linter
linter copied to clipboard
[Wildcard Variables][lint] `no_wildcard_variable_uses` and the new wildcard variables feature.
Changes to make
(Updated May 14th 2024)
- Change the documentation of the lint to something like:
Wildcard parameters and local variables (whose name is '_' by definition) will become non-binding in a future version of the Dart language.
- This lint should WARN on
_
(not__
etc) if it's being used. -
UNUSED_VARIABLE
will have an additional fix to suggest converting to_
.
As mentioned from https://github.com/dart-lang/language/pull/3785#discussion_r1593537182.
https://dart.dev/tools/linter-rules/no_wildcard_variable_uses
no_wildcard_variable_uses
reports all named underscores, which is more than what we want.
This lint will flag usages of names of the form __, ___ and so on, in addition to _. Does it give rise to unnecessary churn to flag all the names that have more than one underscore, given that they will keep their status as regular (non-wildcard) identifiers? For example, if someone really wants to use local variables with the name _ then they might switch to __ just because it's similar, and not overly long, and they might be unhappy if they still get the lint message.
In the context of implementing the new wildcard variables feature (spec), what changes, if any, do we want to make to the no_wildcard_variable_uses
lint?
1. Migration/Breakage
One purpose of this existing lint is for an easier migration/breakage: which since it's enabled in the core lint set, should make the breakages across projects pretty small.
2. Wildcard variables feature
However, once the wildcard variables feature ships, we will most likely need to make a new lint and remove/deprecate(?)/change this one (because wildcards can be used :) ).
As @eernstg said, add a new lint that "targets the cases where _
resolves to a declaration which would be wildcarded when that feature is enabled."
cc. @pq