dart-lang / linter

Linter for Dart.
https://dart.dev/tools/linter-rules
BSD 3-Clause "New" or "Revised" License
629 stars 170 forks source link

[Wildcard Variables] support for `no_leading_underscores_for_local_identifiers` #5040

Open pq opened 1 month ago

pq commented 1 month ago

The current implementation special-cases all underscore variations:

**EXCEPTION:**: An unused parameter can be named `_`, `__`, `___`, etc.  This is
common practice in callbacks where you are passed a value but you don't need
to use it. Giving it a name that consists solely of underscores is the idiomatic
way to indicate that the value isn't used.

With the wild card variables feature we might start reporting on __, ___, etc.

Note that making this change may result in newly reported diagnostics. The impact could have some reach since this is a recommended lint.

/fyi @kallentu @bwilkerson

lrhn commented 1 month ago

Agree on warning on __ etc. The reason they are exempt no longer applies, you should just use _ everywhere.

kallentu commented 1 month ago

+1 on warning on _.

I don't know how much we care, but I wonder if it would be a useful step to have a fix that turns __ into the wildcard _ because I'm sure that's what users are trying to do in most cases.

bwilkerson commented 1 month ago

Yes, we should definitely have a fix. And we should care a lot because such a fix will help users migrate seamlessly to whatever version this language feature ships in.

pq commented 2 weeks ago

See also https://github.com/dart-lang/linter/issues/5048.

We'll want to pick how and where to nudge to use wildcards (and not do over do it!)