Closed
Description
<no_wildcard_variable_uses>
Description
Do not use wildcard parameters or variables.
Details
There's a proposal to change the language so that (at least) parameters and local variables named _
(e.g., wildcards) become non-binding. When that happens, existing code that uses wildcard parameters or variables will break.
Enabling this lint now will make it less breaking to make _
non-binding in a future Dart release.
Kind
Error
Bad Examples
var _ = 1;
print(_); // LINT
void f(int __) {
print(__); // LINT multiple underscores too
}
Good Examples
for (var _ in [1, 2, 3]) count++;
try {
...
} catch (_) {
...
}
var [a, _, b, _] = [1, 2, 3, 4];
Discussion
cc @dart-lang/language-team
Discussion checklist
- List any existing rules this proposal modifies, complements, overlaps or conflicts with.
- List any relevant issues (reported here, the SDK Tracker, or elsewhere).
- If there's any prior art (e.g., in other linters), please add references here.
- If this proposal corresponds to Effective Dart or Flutter Style Guide advice, please call it out. (If there isn't any corresponding advice, should there be?)
- If this proposal is motivated by real-world examples, please provide as many details as you can. Demonstrating potential impact is especially valuable.