Linting rules
E005: write-only-variable
Checks for variables that are written to but never read.
Metadata
Code:E005Rule:write-only-variableStatus: Stable sincev0.0.1Quick fix: not available
What it does
Checks for variables that are written to but never read.
Why is this bad?
A variable that is only written to but never read is likely a bug or redundant code.
Example
fun main() {
var x = 1; x = 2;
println("hello");
}Use instead:
fun main() {
println("hello");
}Behavior notes
- Locals prefixed with
_are ignored. - Mutable parameters (
mutate) are ignored. - Variables with zero usages are handled by
unused-variable. - This rule only reports variables with writes and no reads.
Operations that imply reads (for example
+=) do not match this rule.
Last updated on