Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit 050035e

Browse files
committed
fix: update tear-off detection for unused-parameters rule
1 parent c752d23 commit 050035e

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_unused_parameters/visitor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class _InvocationsVisitor extends RecursiveAstVisitor<void> {
113113
void visitSimpleIdentifier(SimpleIdentifier node) {
114114
if (node.name == methodName &&
115115
node.staticElement is MethodElement &&
116-
node.parent! is MethodInvocation) {
116+
node.parent is ArgumentList) {
117117
hasTearOffInvocations = true;
118118
}
119119

test/src/analyzers/lint_analyzer/rules/rules_list/avoid_unused_parameters/avoid_unused_parameters_rule_test.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,21 @@ void main() {
7070

7171
RuleTestHelper.verifyIssues(
7272
issues: issues,
73-
startLines: [8, 13, 13],
74-
startColumns: [36, 23, 43],
73+
startLines: [13, 13, 21, 25, 26],
74+
startColumns: [23, 43, 25, 5, 5],
7575
locationTexts: [
76-
'int value',
7776
'String firstString',
7877
'String secondString',
78+
'String value',
79+
'int value',
80+
'String name',
7981
],
8082
messages: [
8183
'Parameter is unused.',
8284
'Parameter is unused.',
8385
'Parameter is unused.',
86+
'Parameter is unused.',
87+
'Parameter is unused.',
8488
],
8589
);
8690
});

test/src/analyzers/lint_analyzer/rules/rules_list/avoid_unused_parameters/examples/tear_off_example.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,18 @@ class TestClass {
1313
void _anotherMethod(String firstString, String secondString) {
1414
someMethod(_otherMethod);
1515
_someOtherMethod(value);
16+
17+
final replacement = value.isNotEmpty ? _someAnotherMethod(1, '1') : null;
1618
}
1719

1820
// LINT
19-
_someOtherMethod(String value) {}
21+
void _someOtherMethod(String value) {}
22+
23+
// LINT
24+
String _someAnotherMethod(
25+
int value,
26+
String name,
27+
) {
28+
return '';
29+
}
2030
}

0 commit comments

Comments
 (0)