From b888da751ed8f2174d2ef5bd50eacabb24979745 Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Wed, 14 Aug 2024 08:05:37 +0000 Subject: [PATCH] Revert "analyzer: separate unused_element_parameter from unused_element" This reverts commit c1976b097d1f85fe2c8fa4cab1d0d51cc7e92b42. 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 https://github.com/dart-lang/sdk/issues/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 > Reviewed-by: Phil Quitslund > Commit-Queue: Samuel Rawlins > Reviewed-by: Ryan Macnak Change-Id: Ibbba75fe56601c7c4b5535c9142cf94c2dd80b91 Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380460 Commit-Queue: Martin Kustermann Bot-Commit: Rubber Stamper Reviewed-by: Slava Egorov --- .../assist/convert_class_to_enum_test.dart | 2 +- pkg/analyzer/lib/src/error/codes.g.dart | 4 ++- pkg/analyzer/messages.yaml | 30 +++++++------------ pkg/analyzer/tool/diagnostics/diagnostics.md | 21 +++---------- .../lib/src/elements/debugger.dart | 2 +- 5 files changed, 19 insertions(+), 40 deletions(-) diff --git a/pkg/analysis_server/test/src/services/correction/assist/convert_class_to_enum_test.dart b/pkg/analysis_server/test/src/services/correction/assist/convert_class_to_enum_test.dart index 22f745419e5..f98306f4b4a 100644 --- a/pkg/analysis_server/test/src/services/correction/assist/convert_class_to_enum_test.dart +++ b/pkg/analysis_server/test/src/services/correction/assist/convert_class_to_enum_test.dart @@ -348,7 +348,7 @@ base class E { class _E { static const _E c = _E(); - // ignore: unused_element_parameter, recursive_constant_constructor + // ignore: unused_element, recursive_constant_constructor const _E({_E e = const _E()}); } '''); diff --git a/pkg/analyzer/lib/src/error/codes.g.dart b/pkg/analyzer/lib/src/error/codes.g.dart index 14d8d9eb42c..2cf6a1202a9 100644 --- a/pkg/analyzer/lib/src/error/codes.g.dart +++ b/pkg/analyzer/lib/src/error/codes.g.dart @@ -7585,9 +7585,11 @@ class WarningCode extends AnalyzerErrorCode { /// Parameters: /// 0: the name of the parameter that is declared but not used static const WarningCode UNUSED_ELEMENT_PARAMETER = WarningCode( - 'UNUSED_ELEMENT_PARAMETER', + 'UNUSED_ELEMENT', "A value for optional parameter '{0}' isn't ever given.", correctionMessage: "Try removing the unused parameter.", + hasPublishedDocs: true, + uniqueName: 'UNUSED_ELEMENT_PARAMETER', ); /// Parameters: diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml index 335f41e5019..5b2c560df8d 100644 --- a/pkg/analyzer/messages.yaml +++ b/pkg/analyzer/messages.yaml @@ -27308,6 +27308,8 @@ WarningCode: kinds of declarations are analyzed: - Private top-level declarations and all of their members - Private members of public declarations + - Optional parameters of private functions for which a value is never + passed Not all references to an element will mark it as "used": - Assigning a value to a top-level variable (with a standard `=` @@ -27327,26 +27329,6 @@ WarningCode: class [!_C!] {} ``` - #### Common fixes - - If the declaration isn't needed, then remove it. - - If the declaration is intended to be used, then add the code to use it. - UNUSED_ELEMENT_PARAMETER: - problemMessage: "A value for optional parameter '{0}' isn't ever given." - correctionMessage: Try removing the unused parameter. - hasPublishedDocs: false - comment: |- - Parameters: - 0: the name of the parameter that is declared but not used - documentation: |- - #### Description - - The analyzer produces this diagnostic when a value is never passed for an - optional parameter declared within a private declaration. - - #### Example - Assuming that no code in the library passes a value for `y` in any invocation of `_m`, the following code produces this diagnostic: @@ -27371,6 +27353,14 @@ WarningCode: ``` If the declaration is intended to be used, then add the code to use it. + UNUSED_ELEMENT_PARAMETER: + sharedName: UNUSED_ELEMENT + problemMessage: "A value for optional parameter '{0}' isn't ever given." + correctionMessage: Try removing the unused parameter. + hasPublishedDocs: true + comment: |- + Parameters: + 0: the name of the parameter that is declared but not used UNUSED_FIELD: problemMessage: "The value of the field '{0}' isn't used." correctionMessage: Try removing the field, or using it. diff --git a/pkg/analyzer/tool/diagnostics/diagnostics.md b/pkg/analyzer/tool/diagnostics/diagnostics.md index 4e46b3da1da..3d45df2e82f 100644 --- a/pkg/analyzer/tool/diagnostics/diagnostics.md +++ b/pkg/analyzer/tool/diagnostics/diagnostics.md @@ -23183,6 +23183,8 @@ void f() { ### unused_element +_A value for optional parameter '{0}' isn't ever given._ + _The declaration '{0}' isn't referenced._ #### Description @@ -23192,6 +23194,8 @@ referenced in the library that contains the declaration. The following kinds of declarations are analyzed: - Private top-level declarations and all of their members - Private members of public declarations +- Optional parameters of private functions for which a value is never + passed Not all references to an element will mark it as "used": - Assigning a value to a top-level variable (with a standard `=` @@ -23211,23 +23215,6 @@ produces this diagnostic: class [!_C!] {} ``` -#### Common fixes - -If the declaration isn't needed, then remove it. - -If the declaration is intended to be used, then add the code to use it. - -### unused_element_parameter - -_A value for optional parameter '{0}' isn't ever given._ - -#### Description - -The analyzer produces this diagnostic when a value is never passed for an -optional parameter declared within a private declaration. - -#### Example - Assuming that no code in the library passes a value for `y` in any invocation of `_m`, the following code produces this diagnostic: diff --git a/runtime/observatory/lib/src/elements/debugger.dart b/runtime/observatory/lib/src/elements/debugger.dart index 1a60dcc55dd..05e84d70e03 100644 --- a/runtime/observatory/lib/src/elements/debugger.dart +++ b/runtime/observatory/lib/src/elements/debugger.dart @@ -2942,7 +2942,7 @@ class DebuggerConsoleElement extends CustomElement implements Renderable { DebuggerConsoleElement.created() : super.created('debugger-console'); /// Is [container] scrolled to the within [threshold] pixels of the bottom? - // ignore: unused_element_parameter + // ignore: unused_element static bool _isScrolledToBottom(DivElement? container, [int threshold = 2]) { if (container == null) { return false;