Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/src/rules/use_super_parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ class _Visitor extends SimpleAstVisitor {
bool match = false;
for (var i = 0; i < constructorParams.length && !match; ++i) {
var constructorParam = constructorParams[i];
if (constructorParam is FieldFormalParameter) continue;
if (constructorParam is SuperFormalParameter) continue;
var constructorElement = constructorParam.declaredElement;
if (constructorElement == null) continue;
if (referencedParameters.contains(constructorElement)) continue;
Expand Down
34 changes: 30 additions & 4 deletions test/rules/use_super_parameters_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ class UseSuperParametersTest extends LintRuleTest {
@override
String get lintRule => 'use_super_parameters';

test_functionTypedFormalParameter() async {
await assertDiagnostics(r'''
class A {
A(int f(int i));
}
class B extends A {
B(int f(int i)) : super(f);
}
''', [
lint('use_super_parameters', 53, 1),
]);
}

test_named() async {
await assertDiagnostics(r'''
class A {
Expand All @@ -48,6 +61,19 @@ class C extends B {
''');
}

test_no_lint_invalid_fieldFormalParameter() async {
await assertNoDiagnostics(r'''
class A {
A(int x);
}
class B extends A {
B(int x) : super(x) {
print(x);
}
}
''');
}

test_no_lint_named_noSuperInvocation() async {
await assertNoDiagnostics(r'''
class A {
Expand Down Expand Up @@ -133,12 +159,12 @@ class B extends A {
test_no_lint_referencedInBody_positional() async {
await assertNoDiagnostics(r'''
class A {
A(int x);
int x;
A(this.x);
}
class B extends A {
B(int x) : super(x) {
print(x);
}
int y;
B(this.y) : super(y);
}
''');
}
Expand Down