Skip to content

Commit 5408090

Browse files
authored
fix use_super_parameters false positive w/ field formal params (dart-archive/linter#3293)
* fix `use_super_parameters` false positive w/ field formal params * + super formals
1 parent 15a4b39 commit 5408090

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

lib/src/rules/use_super_parameters.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ class _Visitor extends SimpleAstVisitor {
172172
bool match = false;
173173
for (var i = 0; i < constructorParams.length && !match; ++i) {
174174
var constructorParam = constructorParams[i];
175+
if (constructorParam is FieldFormalParameter) continue;
176+
if (constructorParam is SuperFormalParameter) continue;
175177
var constructorElement = constructorParam.declaredElement;
176178
if (constructorElement == null) continue;
177179
if (referencedParameters.contains(constructorElement)) continue;

test/rules/use_super_parameters_test.dart

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ class UseSuperParametersTest extends LintRuleTest {
2222
@override
2323
String get lintRule => 'use_super_parameters';
2424

25+
test_functionTypedFormalParameter() async {
26+
await assertDiagnostics(r'''
27+
class A {
28+
A(int f(int i));
29+
}
30+
class B extends A {
31+
B(int f(int i)) : super(f);
32+
}
33+
''', [
34+
lint('use_super_parameters', 53, 1),
35+
]);
36+
}
37+
2538
test_named() async {
2639
await assertDiagnostics(r'''
2740
class A {
@@ -48,6 +61,19 @@ class C extends B {
4861
''');
4962
}
5063

64+
test_no_lint_invalid_fieldFormalParameter() async {
65+
await assertNoDiagnostics(r'''
66+
class A {
67+
A(int x);
68+
}
69+
class B extends A {
70+
B(int x) : super(x) {
71+
print(x);
72+
}
73+
}
74+
''');
75+
}
76+
5177
test_no_lint_named_noSuperInvocation() async {
5278
await assertNoDiagnostics(r'''
5379
class A {
@@ -133,12 +159,12 @@ class B extends A {
133159
test_no_lint_referencedInBody_positional() async {
134160
await assertNoDiagnostics(r'''
135161
class A {
136-
A(int x);
162+
int x;
163+
A(this.x);
137164
}
138165
class B extends A {
139-
B(int x) : super(x) {
140-
print(x);
141-
}
166+
int y;
167+
B(this.y) : super(y);
142168
}
143169
''');
144170
}

0 commit comments

Comments
 (0)