Skip to main content

avoid-unused-assignment

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

Example

❌ Bad:

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

void fn2(bool condition) {
var v = 'used';
if (condition) {
// LINT: This assigned value is not used in subsequent statements.
// Try removing this assignment.
v = 'unused';
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