Skip to main content

avoid-unused-assignment

added in: 1.22.0
Pro+
preset: recommended

Warns when an assignment is not used in the subsequent statements.

Example

❌ Bad:

void fn1() {
var v = 'used';
doSomething(v);
v = 'unused'; // LINT: This assigned value is not used in subsequent statements. Try removing this assignment.
}

void fn2(bool condition) {
var v = 'used';
if (condition) {
v = 'unused'; // LINT: This assigned value is not used in subsequent statements. Try removing this assignment.
return;
}
doSomething(v);
}

✅ Good:

void fn1() {
var v = 'used';
doSomething(v);
}

void fn2(bool condition) {
var v = 'used';
if (condition) {
return;
}
doSomething(v);
}

Additional Resources