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.

warning

This rule is deprecated and will be removed in the upcoming release. Use this standard rule https://dart.dev/tools/diagnostic-messages?#no_wildcard_variable_uses instead.

Example

❌ Bad:

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

print(_); // LINT: Avoid references to discarded variables. Try renaming it if this variable is intended to be used.
}

✅ Good:

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

print(value);
}

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

// no other code that references _
}