-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
unused_element reports on unused parameters whose presence is idiomatic #49025
Comments
More or less a duplicate of #48401 |
No I don't think so. If you want to keep an unused parameter on your private widget, you will keep getting an |
How does this relate to |
@srawlins It's related to the super parameters because this breaks class _MyWidget extends StatelessWidget {
const _MyWidget({super.key});
@override
Widget build(BuildContext context) {
return Container();
}
} But this does not: class _MyWidget extends StatelessWidget {
const _MyWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container();
}
} This doesn't really have much to do with the lint rule |
Oops, that second example should also have an |
It's super common in Flutter to have this |
I can update the title of this issue to make that the ask. |
@srawlins That would be great, thanks! |
@srawlins @maxlapides this issue looks perfectly legit to me, why would you want to shut a warning about an unused element ? Implementing super with To go further, I don't think that the new super parameters syntax has an issue, on the contrary I think that the old syntax should also trigger this |
I agree with the previous comment. There's no reason to have the For a public widget (that may get exported from a library you don't have control over) you want to make sure it can always take a key. If the key parameter is omitted, you'd have to ask the library author to release a new version with the key parameter added. |
I'm not strongly opposed to removing the |
I agree with Max. It's common for widgets to have key parameter whether they are public or private. const _MyWidget({Key? key}) : super(key: key); looks legit for it. Also it's more likely to forget to add the key whenever I want to make my private widget a public. |
If there is not a report for unused_element for |
I understand your point of view although I disagree :
|
Generally speaking, the If a dev or a team firmly believes some code should remain, however unused, they can disable the rules or suppress them by various means. If disabling "unused_element" across a codebase is too big a hammer, we may split a diagnostic out, as per #48401, for unused parameters, as this argument has come up a few times, "but I might need it later." |
Linter false positive: dart-lang/sdk#49025
* feat: customize app theme * feat: implement basic launch page * feat: add launch state handling * feat: implement launch card * feat: add floating search bar to LaunchPage * feat: add filtering chips * feat: replace SliverList with SliverGrid To support different screen sizes better. * feat: add last launch page handling * feat: add loading indicators to launch grid * feat: add searching to LaunchPage * fix: make search bar clear button work properly * feat: add no items found indicator to grid of launch cards * fix: ensure the binding is initialized before getting storage directory * feat: add first page error indicator to launch grid * feat: add new page error indicator to launch grid * refactor: break up the launch page into different widgets * feat: add filtering chip dialogs * fix: make buttons in dialogs white * feat: implement launch page sorting * feat: add time filtering to launch page * refactor: change launch state handling * refactor: shorten launch bloc code * feat: add launch successfulness filtering * feat: add launch flight number filtering * feat: add launch year filtering * refactor: split up the launches feature into two features * feat: add launch rocket filtering * feat: add checkbox theme * refactor: remove excessive event addition to launch bloc * feat: create spacex_ui package with common widgets * refactor: split up filtering chips file into multiple files * refactor: use spacex_ui widgets in the rest of the app * feat: add string localization * docs: add missing project documentation * refactor: remove key parameter from private widgets Linter false positive: dart-lang/sdk#49025 * fix: fix FilteringChip layout * refactor: obtain widget colors from Theme * feat: change dialog text button color * test: add basic app test
Clearly, this behavior is controversial. The reactions speak for themselves I think. There's a decent amount of upvotes on both sides of the argument. That's the issue. This ends up negatively impacting a large number of people with no real solution. Extracting this behavior into a new lint rule would lead to a happy ending for everyone. Those who like this can keep it. Those who don't can disable it. |
In flutter/tests#172, I believe this is the cause of |
Any updates? The IntelliJ IDEA plugin generates a widget with I'd love to have either a separate lint that ignores this specific case, as mentioned above, or at the very least have an option for the IDEA plugin to generate |
No updates.
That's probably the direction we'll go. |
Oops, I think we implemented that. You can now @dnfield the |
@srawlins Great, |
No worries, I always forget it too :) Here's the syntax: https://dart.dev/guides/language/analysis-options#ignoring-rules |
@srawlins Strangely, I am getting this warning analyzer:
errors:
unused_element_parameter: ignore |
Ah ok if that doesn't work then there is remaining work. I have an idea. |
Any news? |
No news. |
This reverts commit a458bab. Reason for revert: broke flutter snippet tests, and maybe customer tests Work towards flutter/flutter#131096 Original change's description: > Separate out UNUSED_ELEMENT_PARAMETER from UNUSED_ELEMENT > > Fixes #49025 > > Change-Id: I401093e5b76bcf707060ce022c346e26c6807aa0 > Tested: try-bots > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303261 > Commit-Queue: Samuel Rawlins <srawlins@google.com> > Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> > Reviewed-by: Ben Konyi <bkonyi@google.com> > Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Change-Id: Ib0c9afc4911efd620013896fb895ab7825c50aa4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315940 Commit-Queue: Siva Annamalai <asiva@google.com> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Siva Annamalai <asiva@google.com>
Had to revert the fix; broke various flutter things. See flutter/flutter#131096 |
Works to me with:
|
Don't worry, I'm just a reminder: we still need a solution to this problem |
This worked for me on flutter version 3.19.4 |
Any news? |
Assumptions:
user_super_parameters
lint rule is enabledunused_element
analyzer rule is enabledThis code chunk produces an analyzer issue:
"A value for optional parameter 'key' isn't ever given. Try removing the unused parameter."
But, when the same widget is not private, there is no issue:
I would like to keep the
super.key
on the private widgets, but I also want to keep theunused_element
rule enabled. Is there any way to achieve this?The text was updated successfully, but these errors were encountered: