From b3f31a04402384861edda207c7ff328bf6d4d37e Mon Sep 17 00:00:00 2001 From: Samuel Rawlins Date: Tue, 27 Aug 2024 17:44:28 +0000 Subject: [PATCH] Revert "Reapply "analyzer: separate unused_element_parameter from unused_element"" This reverts commit b551690c56b3722e15ac1fb4fc9a7f73f1a40cd8. 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 b888da751ed8f2174d2ef5bd50eacabb24979745. > > Change-Id: I8ea52fcdcb491c140c1283602d6911c939e78d50 > Tested: trybots > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381882 > Reviewed-by: Ben Konyi > Commit-Queue: Samuel Rawlins > Reviewed-by: Brian Wilkerson Change-Id: Ie0df2f4be45e5db2fa255dcf8c30ddf8408c155b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382420 Bot-Commit: Rubber Stamper Reviewed-by: Matan Lurey Commit-Queue: Samuel Rawlins Reviewed-by: Brian Wilkerson Reviewed-by: Ryan Macnak --- .../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 11879b2b6f3..9fe34ca2b2d 100644 --- a/pkg/analyzer/lib/src/error/codes.g.dart +++ b/pkg/analyzer/lib/src/error/codes.g.dart @@ -7612,9 +7612,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 21fbe64be7c..24460a80be0 100644 --- a/pkg/analyzer/messages.yaml +++ b/pkg/analyzer/messages.yaml @@ -27316,6 +27316,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 `=` @@ -27335,26 +27337,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: @@ -27379,6 +27361,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 f503e312aec..3eb37202778 100644 --- a/pkg/analyzer/tool/diagnostics/diagnostics.md +++ b/pkg/analyzer/tool/diagnostics/diagnostics.md @@ -23187,6 +23187,8 @@ void f() { ### unused_element +_A value for optional parameter '{0}' isn't ever given._ + _The declaration '{0}' isn't referenced._ #### Description @@ -23196,6 +23198,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 `=` @@ -23215,23 +23219,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;