Skip to main content

avoid-referencing-discarded-variables

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';

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

✅ Good:

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

print(value);
}

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

// no other code that references _
}