-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Wildcard Variables][lint] proposal: use_wildcard_rather_than_underscores
#59473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
use_wildcard_rather_than_underscores
use_wildcard_rather_than_underscores
cc. @pq |
I'm confused about when |
Is this confusing for users? |
I'm not sure I'd say that it's confusing, but it definitely isn't helpful. There should really be a single diagnostic for a single problem. It isn't clear to me that we need two lints that do the same thing. Is there a motivation here that I'm missing? |
I think it depends on what type of fix the user is looking for and what they intend on doing with In the case where a user actually wants a non-binding In the case where a user using |
If a multi-underscore identifier is actually being used then we won't report either diagnostic. But in the case where the variable is not being used, and we report an unused variable, we could offer to convert it to a wildcard (when the experiment is enabled). And if there were a different fix for the problem we could offer both without needing a second diagnostic. I still don't see the value to the user of having two lints for the same problem. If there's enough support for it in the community we could add a lint to flag multi-underscore identifiers that are being used with a recommendation that they be renamed, but I suspect that might not be a common enough problem to justify a lint. |
Fair enough. I wasn't sure if we could have more than one fix on an error. If we can do that, let's just add an additional fix for Does that sound reasonable? |
Okay decided.
Closing issue. |
use_wildcard_rather_than_underscores
Description
Use
_
instead of underscores such as__
(etc.).Details
DO use
_
instead of multiple underscores such as__
(etc.) when declaring a local wildcard.Kind
This lint enforces the usage of the new wildcard feature where
_
is non-binding, over__
and etc which are binding.Bad Examples
Good Examples
Discussion
Related issue and discussion:
no_wildcard_variable_uses
and the new wildcard variables feature. #59470This should complement the
UNUSED_VARIABLE
warning and theno_wildcard_variable_uses
lint once they're updated to take the wildcard feature into account.We should also have a quickfix that can easily change these bad instances to
_
.Discussion checklist
The text was updated successfully, but these errors were encountered: