-
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
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
This worked for me on flutter version 3.19.4 |
Any news? |
The splitting CL is reverted; re-opening. |
This reverts commit c1976b0. Reason for revert: It seems this change caused failures on Flutter HHH bot. Example log can be found at [0]: ``` | lib/src/super_reader/super_reader.dart:615:14: Error: Final field 'showDebugLeaderBounds' is not initialized. | Try to initialize the field in the declaration or in every constructor. | final bool showDebugLeaderBounds; | ^^^^^^^^^^^^^^^^^^^^^ ``` Looking at the sources it seems that may be related to the `// ignore: unused_element` analyzer directive: ``` 602 /// A [SuperReaderDocumentLayerBuilder] that builds a [SelectionLeadersDocumentLayer], which positions 603 /// leader widgets at the base and extent of the user's selection, so that other widgets 604 /// can position themselves relative to the user's selection. 605 class _SelectionLeadersDocumentLayerBuilder implements SuperReaderDocumentLayerBuilder { 606 const _SelectionLeadersDocumentLayerBuilder({ 607 required this.links, 608 // ignore: unused_element 609 this.showDebugLeaderBounds = false, 610 }); 611 612 /// Collections of [LayerLink]s, which are given to leader widgets that are 613 /// positioned at the selection bounds, and around the full selection. 614 final SelectionLayerLinks links; 615 616 /// Whether to paint colorful bounds around the leader widgets, for debugging purposes. 617 final bool showDebugLeaderBounds; ``` So tentatively reverting this CL. [0] https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket/8739650477551803313/+/u/Run_customer_testing_tests/stdout Original change's description: > analyzer: separate unused_element_parameter from unused_element > > Fixes #49025 > > This allows users to blanket ignore unused_element_parameter without > ignoring unused_element. They are reported in distinct situations so it > is valid to separate them. > > Change-Id: I4844a6a0e0a67cd5e37ed8735b1526e174deb950 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378500 > Reviewed-by: Brian Wilkerson <[email protected]> > Reviewed-by: Phil Quitslund <[email protected]> > Commit-Queue: Samuel Rawlins <[email protected]> > Reviewed-by: Ryan Macnak <[email protected]> Change-Id: Ibbba75fe56601c7c4b5535c9142cf94c2dd80b91 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380460 Reviewed-by: Christopher Fujino <[email protected]> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380689 Commit-Queue: Kevin Chisholm <[email protected]>
…d_element" This reverts commit c1976b0. Note: this is the second attempt at reverting this CL. The previous commit claimed to do the revert but did not actually revert the code. Reason for revert: It seems this change caused failures on Flutter HHH bot. Example log can be found at [0]: ``` | lib/src/super_reader/super_reader.dart:615:14: Error: Final field 'showDebugLeaderBounds' is not initialized. | Try to initialize the field in the declaration or in every constructor. | final bool showDebugLeaderBounds; | ^^^^^^^^^^^^^^^^^^^^^ ``` Looking at the sources it seems that may be related to the `// ignore: unused_element` analyzer directive: ``` 602 /// A [SuperReaderDocumentLayerBuilder] that builds a [SelectionLeadersDocumentLayer], which positions 603 /// leader widgets at the base and extent of the user's selection, so that other widgets 604 /// can position themselves relative to the user's selection. 605 class _SelectionLeadersDocumentLayerBuilder implements SuperReaderDocumentLayerBuilder { 606 const _SelectionLeadersDocumentLayerBuilder({ 607 required this.links, 608 // ignore: unused_element 609 this.showDebugLeaderBounds = false, 610 }); 611 612 /// Collections of [LayerLink]s, which are given to leader widgets that are 613 /// positioned at the selection bounds, and around the full selection. 614 final SelectionLayerLinks links; 615 616 /// Whether to paint colorful bounds around the leader widgets, for debugging purposes. 617 final bool showDebugLeaderBounds; ``` So tentatively reverting this CL. [0] https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket/8739650477551803313/+/u/Run_customer_testing_tests/stdout Original change's description: > analyzer: separate unused_element_parameter from unused_element > > Fixes #49025 > > This allows users to blanket ignore unused_element_parameter without > ignoring unused_element. They are reported in distinct situations so it > is valid to separate them. > > Tested: Presubmit CI > Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try > Change-Id: I4844a6a0e0a67cd5e37ed8735b1526e174deb950 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378500 > Reviewed-by: Brian Wilkerson <[email protected]> > Reviewed-by: Phil Quitslund <[email protected]> > Commit-Queue: Samuel Rawlins <[email protected]> > Reviewed-by: Ryan Macnak <[email protected]> Change-Id: I85c98a2d8b24d38d438015e7a10bd99ab914fc7a Cq-Include-Trybots: luci.dart.try:analyzer-win-release-try,pkg-win-release-try Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/380460 Cherry-pick-request: #56486 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380703 Reviewed-by: Slava Egorov <[email protected]> Commit-Queue: Alexander Thomas <[email protected]>
3.6.0-149.0.dev includes the fix, in case someone wants to try it. However, it's still reverted on |
The latter was separated from the former to avoid conflation (see dart-lang/sdk#49025). Makes CI green again.
@iinozemtsev this is still reverted on main, right? re-open? |
oh, I didn't expect that pushing into a fork can close the issue, sorry! |
Oh, I see, haha! Thanks much! |
…sed_element"" This reverts commit b551690. Reason for revert: flutter customer tests failing: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8738601049545714785/+/u/run_test.dart_for_customer_testing_shard_and_subshard_None/stdout Original change's description: > Reapply "analyzer: separate unused_element_parameter from unused_element" > > Fixes #49025. Fixes #48401 > > This allows users to blanket ignore unused_element_parameter without > ignoring unused_element. They are reported in distinct situations so it > is valid to separate them. > > This reverts commit b888da7. > > Change-Id: I8ea52fcdcb491c140c1283602d6911c939e78d50 > Tested: trybots > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381882 > Reviewed-by: Ben Konyi <[email protected]> > Commit-Queue: Samuel Rawlins <[email protected]> > Reviewed-by: Brian Wilkerson <[email protected]> Change-Id: Ie0df2f4be45e5db2fa255dcf8c30ddf8408c155b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382420 Bot-Commit: Rubber Stamper <[email protected]> Reviewed-by: Matan Lurey <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
In dart-lang/sdk#49025, we are splitting the `unused_element` code, so that the warning reported is `unused_element_parameter`. In this change, I change each ignored case to ignore each warning name, to make the code forwards-compatible.
super_editor needs to be updated to handle an upcoming Dart change, dart-lang/sdk#49025, where unused parameters must be ignored with `// ignore: unused_element_parameter` instead of `// ignore: unused_element`. A PR making this change has been unaddressed for 3 weeks. superlistapp/super_editor#2308 super_editor tests can be re-enabled when that PR is accepted, and the SHA here is bumped.
…2308) In dart-lang/sdk#49025, we are splitting the `unused_element` code, so that the warning reported is `unused_element_parameter`. In this change, I change each ignored case to ignore each warning name, to make the code forwards-compatible.
super_editor needs to be updated to handle an upcoming Dart change, dart-lang/sdk#49025, where unused parameters must be ignored with `// ignore: unused_element_parameter` instead of `// ignore: unused_element`. A PR making this change has been unaddressed for 3 weeks. superlistapp/super_editor#2308 super_editor tests can be re-enabled when that PR is accepted, and the SHA here is bumped.
…sed_element"" This reverts commit b3f31a0. Reason for revert: Customer tests are now disabled. Original change's description: > Revert "Reapply "analyzer: separate unused_element_parameter from unused_element"" > > This reverts commit b551690. > > Reason for revert: flutter customer tests failing: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8738601049545714785/+/u/run_test.dart_for_customer_testing_shard_and_subshard_None/stdout > > Original change's description: > > Reapply "analyzer: separate unused_element_parameter from unused_element" > > > > Fixes #49025. Fixes #48401 > > > > This allows users to blanket ignore unused_element_parameter without > > ignoring unused_element. They are reported in distinct situations so it > > is valid to separate them. > > > > This reverts commit b888da7. > > > > Change-Id: I8ea52fcdcb491c140c1283602d6911c939e78d50 > > Tested: trybots > > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381882 > > Reviewed-by: Ben Konyi <[email protected]> > > Commit-Queue: Samuel Rawlins <[email protected]> > > Reviewed-by: Brian Wilkerson <[email protected]> > > Change-Id: Ie0df2f4be45e5db2fa255dcf8c30ddf8408c155b > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382420 > Bot-Commit: Rubber Stamper <[email protected]> > Reviewed-by: Matan Lurey <[email protected]> > Commit-Queue: Samuel Rawlins <[email protected]> > Reviewed-by: Brian Wilkerson <[email protected]> > Reviewed-by: Ryan Macnak <[email protected]> Change-Id: Icbe69690e83daecc5a0649d2f632ffc33ba6394c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386722 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Matan Lurey <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Ben Konyi <[email protected]>
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: