Skip to main content

avoid-referencing-discarded-variables

added in: 1.9.0
Pro+
preset: recommended

Warns when a variable with the name that has only underscores (ex. _, __, etc.) is referenced.

Example

❌ Bad:

void main() {
final _ = 'some value';

print(_); // LINT
}

✅ Good:

void main() {
final value = 'some value';

print(value);
}

void main() {
final _ = 'some value';

// no other code that references _
}