no-wildcard-variable-uses
Same as no_wildcard_variable_uses in Dart lints
- Group
- Suspicious
- Path
lint/suspicious/no-wildcard-variable-uses- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 298 of 512
Flags references to a wildcard variable or parameter (a name made solely of
underscores, such as _ or __).
An all-underscore name marks a binding as intentionally unused, and under Dart's wildcard-variable semantics such names are non-binding — reading one back does not retrieve the value you expect. Referencing it is therefore either a mistake or a reliance on behavior that is changing. Declaring a wildcard is fine; only uses in expression position are reported. Give the binding a real name if you actually need its value.
Invalid
// Referencing a wildcard variable or parameter is not allowed.
int a(int _) => _;
int b(int _) => _ * 2;
void c() {
var _ = 1;
print(_);
}
void d() {
var __ = 2;
print(__);
}
int e(int _) {
return _ + 1;
}
void f() {
var _ = 0;
_ = 5;
} int a(int _) => _; int b(int _) => _ * 2; var _ = 1; print(_); var __ = 2; print(__);int e(int _) { return _ + 1; var _ = 0; _ = 5;Valid
// Wildcards may be declared but never referenced.
void a() {
var x = 1;
print(x);
}
int b(int value) => value;
void c(int _) {}
void d() {
var _ = 1;
}
void e() {
[1, 2].forEach((_) {});
}
void f() {
for (var _ in <int>[]) {}
}Configure no-wildcard-variable-uses
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"no-wildcard-variable-uses": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/no-wildcard-variable-uses: <reason>More suspicious rules
- overridden-fields
overridden_fieldsrecommendedFlags instance fields that redeclare an inherited field.
- prefer-unique-test-namestest
Reports duplicate test descriptions within a group and constant names in loops.
- recursive-getters
recursive_gettersrecommendedFlags a getter that unconditionally returns itself.
- unnecessary-null-aware-assignments
unnecessary_null_aware_assignmentsrecommendedFlags
x ??= null, which can never have an effect. - unnecessary-null-in-if-null-operators
unnecessary_null_in_if_null_operatorsrecommendedFlags
x ?? nullandnull ?? x, where thenulloperand is redundant. - use-rethrow-when-possible
use_rethrow_when_possiblerecommendedFlags
throw einside acatch (e)by matching the exception parameter's name. - avoid-accessing-other-classes-private-members
Enforces class-level encapsulation even inside one Dart library.
- avoid-assignments-as-conditions
Flags assignments evaluated inside control-flow conditions.