Skip to content

Commit

Permalink
Reapply "analyzer: separate unused_element_parameter from unused_elem…
Browse files Browse the repository at this point in the history
…ent"

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]>
  • Loading branch information
srawlins authored and Commit Queue committed Aug 23, 2024
1 parent f6fd63d commit b551690
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ base class E {
class _E {
static const _E c = _E();
// ignore: unused_element, recursive_constant_constructor
// ignore: unused_element_parameter, recursive_constant_constructor
const _E({_E e = const _E()});
}
''');
Expand Down
4 changes: 1 addition & 3 deletions pkg/analyzer/lib/src/error/codes.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7612,11 +7612,9 @@ 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',
'UNUSED_ELEMENT_PARAMETER',
"A value for optional parameter '{0}' isn't ever given.",
correctionMessage: "Try removing the unused parameter.",
hasPublishedDocs: true,
uniqueName: 'UNUSED_ELEMENT_PARAMETER',
);

/// Parameters:
Expand Down
30 changes: 20 additions & 10 deletions pkg/analyzer/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27316,8 +27316,6 @@ 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 `=`
Expand All @@ -27337,6 +27335,26 @@ 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:

Expand All @@ -27361,14 +27379,6 @@ 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.
Expand Down
21 changes: 17 additions & 4 deletions pkg/analyzer/tool/diagnostics/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -23187,8 +23187,6 @@ void f() {

### unused_element

_A value for optional parameter '{0}' isn't ever given._

_The declaration '{0}' isn't referenced._

#### Description
Expand All @@ -23198,8 +23196,6 @@ 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 `=`
Expand All @@ -23219,6 +23215,23 @@ 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:

Expand Down
2 changes: 1 addition & 1 deletion runtime/observatory/lib/src/elements/debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ignore: unused_element_parameter
static bool _isScrolledToBottom(DivElement? container, [int threshold = 2]) {
if (container == null) {
return false;
Expand Down

0 comments on commit b551690

Please sign in to comment.