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 <brianwilkerson@google.com>
> Reviewed-by: Phil Quitslund <pquitslund@google.com>
> Commit-Queue: Samuel Rawlins <srawlins@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
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 <kustermann@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
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 22f7454..f98306f 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 @@
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 14d8d9e..2cf6a12 100644
--- a/pkg/analyzer/lib/src/error/codes.g.dart
+++ b/pkg/analyzer/lib/src/error/codes.g.dart
@@ -7585,9 +7585,11 @@
/// 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 335f41e..5b2c560 100644
--- a/pkg/analyzer/messages.yaml
+++ b/pkg/analyzer/messages.yaml
@@ -27308,6 +27308,8 @@
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 @@
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 @@
```
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 4e46b3d..3d45df2 100644
--- a/pkg/analyzer/tool/diagnostics/diagnostics.md
+++ b/pkg/analyzer/tool/diagnostics/diagnostics.md
@@ -23183,6 +23183,8 @@
### unused_element
+_A value for optional parameter '{0}' isn't ever given._
+
_The declaration '{0}' isn't referenced._
#### Description
@@ -23192,6 +23194,8 @@
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 @@
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 1a60dcc..05e84d7 100644
--- a/runtime/observatory/lib/src/elements/debugger.dart
+++ b/runtime/observatory/lib/src/elements/debugger.dart
@@ -2942,7 +2942,7 @@
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;