Skip to main content

avoid-unnecessary-local-variable

effort: 2m
teams+

Warns when a local variable is only used as an initializer of another local variable.

Such variables introduce unnecessary complexity and does not affect the meaning of the code.

Example

❌ Bad:

void fn() {
var a = 1; // LINT: Avoid unnecessary local variables. Try using the value directly.
var b = a;
print(b);

var c = 2;
var d = c; // LINT: Avoid unnecessary local variables. Try using the value directly.
print(c);
}

✅ Good:

void fn() {
var b = 1;
print(b);

var c = 2;
print(c);
}