Skip to content

Commit c1976b0

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
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]>
1 parent d916799 commit c1976b0

File tree

5 files changed

+40
-19
lines changed

5 files changed

+40
-19
lines changed

pkg/analysis_server/test/src/services/correction/assist/convert_class_to_enum_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ base class E {
348348
class _E {
349349
static const _E c = _E();
350350
351-
// ignore: unused_element, recursive_constant_constructor
351+
// ignore: unused_element_parameter, recursive_constant_constructor
352352
const _E({_E e = const _E()});
353353
}
354354
''');

pkg/analyzer/lib/src/error/codes.g.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7585,11 +7585,9 @@ class WarningCode extends AnalyzerErrorCode {
75857585
/// Parameters:
75867586
/// 0: the name of the parameter that is declared but not used
75877587
static const WarningCode UNUSED_ELEMENT_PARAMETER = WarningCode(
7588-
'UNUSED_ELEMENT',
7588+
'UNUSED_ELEMENT_PARAMETER',
75897589
"A value for optional parameter '{0}' isn't ever given.",
75907590
correctionMessage: "Try removing the unused parameter.",
7591-
hasPublishedDocs: true,
7592-
uniqueName: 'UNUSED_ELEMENT_PARAMETER',
75937591
);
75947592

75957593
/// Parameters:

pkg/analyzer/messages.yaml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27308,8 +27308,6 @@ WarningCode:
2730827308
kinds of declarations are analyzed:
2730927309
- Private top-level declarations and all of their members
2731027310
- Private members of public declarations
27311-
- Optional parameters of private functions for which a value is never
27312-
passed
2731327311

2731427312
Not all references to an element will mark it as "used":
2731527313
- Assigning a value to a top-level variable (with a standard `=`
@@ -27329,6 +27327,26 @@ WarningCode:
2732927327
class [!_C!] {}
2733027328
```
2733127329

27330+
#### Common fixes
27331+
27332+
If the declaration isn't needed, then remove it.
27333+
27334+
If the declaration is intended to be used, then add the code to use it.
27335+
UNUSED_ELEMENT_PARAMETER:
27336+
problemMessage: "A value for optional parameter '{0}' isn't ever given."
27337+
correctionMessage: Try removing the unused parameter.
27338+
hasPublishedDocs: false
27339+
comment: |-
27340+
Parameters:
27341+
0: the name of the parameter that is declared but not used
27342+
documentation: |-
27343+
#### Description
27344+
27345+
The analyzer produces this diagnostic when a value is never passed for an
27346+
optional parameter declared within a private declaration.
27347+
27348+
#### Example
27349+
2733227350
Assuming that no code in the library passes a value for `y` in any
2733327351
invocation of `_m`, the following code produces this diagnostic:
2733427352

@@ -27353,14 +27371,6 @@ WarningCode:
2735327371
```
2735427372

2735527373
If the declaration is intended to be used, then add the code to use it.
27356-
UNUSED_ELEMENT_PARAMETER:
27357-
sharedName: UNUSED_ELEMENT
27358-
problemMessage: "A value for optional parameter '{0}' isn't ever given."
27359-
correctionMessage: Try removing the unused parameter.
27360-
hasPublishedDocs: true
27361-
comment: |-
27362-
Parameters:
27363-
0: the name of the parameter that is declared but not used
2736427374
UNUSED_FIELD:
2736527375
problemMessage: "The value of the field '{0}' isn't used."
2736627376
correctionMessage: Try removing the field, or using it.

pkg/analyzer/tool/diagnostics/diagnostics.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23183,8 +23183,6 @@ void f() {
2318323183

2318423184
### unused_element
2318523185

23186-
_A value for optional parameter '{0}' isn't ever given._
23187-
2318823186
_The declaration '{0}' isn't referenced._
2318923187

2319023188
#### Description
@@ -23194,8 +23192,6 @@ referenced in the library that contains the declaration. The following
2319423192
kinds of declarations are analyzed:
2319523193
- Private top-level declarations and all of their members
2319623194
- Private members of public declarations
23197-
- Optional parameters of private functions for which a value is never
23198-
passed
2319923195

2320023196
Not all references to an element will mark it as "used":
2320123197
- Assigning a value to a top-level variable (with a standard `=`
@@ -23215,6 +23211,23 @@ produces this diagnostic:
2321523211
class [!_C!] {}
2321623212
```
2321723213

23214+
#### Common fixes
23215+
23216+
If the declaration isn't needed, then remove it.
23217+
23218+
If the declaration is intended to be used, then add the code to use it.
23219+
23220+
### unused_element_parameter
23221+
23222+
_A value for optional parameter '{0}' isn't ever given._
23223+
23224+
#### Description
23225+
23226+
The analyzer produces this diagnostic when a value is never passed for an
23227+
optional parameter declared within a private declaration.
23228+
23229+
#### Example
23230+
2321823231
Assuming that no code in the library passes a value for `y` in any
2321923232
invocation of `_m`, the following code produces this diagnostic:
2322023233

runtime/observatory/lib/src/elements/debugger.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2942,7 +2942,7 @@ class DebuggerConsoleElement extends CustomElement implements Renderable {
29422942
DebuggerConsoleElement.created() : super.created('debugger-console');
29432943

29442944
/// Is [container] scrolled to the within [threshold] pixels of the bottom?
2945-
// ignore: unused_element
2945+
// ignore: unused_element_parameter
29462946
static bool _isScrolledToBottom(DivElement? container, [int threshold = 2]) {
29472947
if (container == null) {
29482948
return false;

0 commit comments

Comments
 (0)