Skip to main content

avoid-unused-local-variable

effort: 4m
teams+

Warns when a local variable is not referenced and can be removed or renamed to _.

Example

❌ Bad:

void fn() {
var a = 1;
// LINT: This local variable is not used. Try removing the variable or using it.
var b = a;

print(a);
}

void withRecord() {
// LINT: This local variable is not used. Try removing the variable or using it.
final (a, b) = (1, 2);

print(a);
}

✅ Good:

void fn() {
var a = 1;

print(a);
}

void withRecord() {
final (a, _) = (1, 2);

print(a);
}