no_ wildcard_ variable_ uses
Learn about the no_wildcard_variable_uses linter rule.
Don't use wildcard parameters or variables.
Details
#DON'T use wildcard parameters or variables.
Wildcard parameters and local variables (e.g. underscore-only
names like _, __, ___,
etc.) will become non-binding in a future version of the Dart
language. Any existing code that uses wildcard parameters or
variables will break. In anticipation of this change, and to
make adoption easier, this lint disallows wildcard and
variable parameter uses.
BAD:
var _ = 1;
print(_); // LINT
void f(int __) {
print(__); // LINT multiple underscores too
}
GOOD:
for (var _ in [1, 2, 3]) count++;
var [a, _, b, _] = [1, 2, 3, 4];
Enable
#
To enable the no_wildcard_variable_uses rule, add
no_wildcard_variable_uses
under
linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- no_wildcard_variable_uses
If you're instead using the YAML map syntax to configure
linter rules, add
no_wildcard_variable_uses: true under
linter > rules:
linter:
rules:
no_wildcard_variable_uses: true
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.