-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Dart fix for unused_element
removes parameters when it shouldn't
#54190
Comments
cc @goderbauer |
I would go one step farther. I don't think that |
I believe the fix for an unused field-formal parameter (
I don't think that's a reason to pollute the parameter list of a constructor. The situation should still be reported, and the fix can be to move the initialization to the constructor initializer list. The goal is to indicate unnecessary complexity, perhaps unnecessary fields (such as the final field which is only ever initialized with a value of |
I assume this is what the end result above would be:
So, in that case, would there also now be a lint warning for the final field that is always null? Presumably there's no dart fix for that because of the possible complexity involved in removing the member and all of its uses. |
We actually don't produce any warnings on that last code. We also don't produce a warning if you have a final field with an initializer like |
Oh, sure, I guess it could easily be the case that someone wants a base class to have a final field that is always null that they then override the getter for in a subclass. |
When applying
dart fix --apply
to the following code:The
bar
parameter is never given a value, so theunused_element
lint shows up for that line:Running
dart fix --apply
to the code yields:Which yields the following error:
The Dart Fix for
unused_element
shouldn't remove parameters that are nullable, since they have implicit default values. Alternatively, it could also remove the uninitialized variable, but I suspect that has tons of corner cases.The text was updated successfully, but these errors were encountered: