Skip to content

Commit 4e3ff1d

Browse files
pqCommit Queue
authored and
Commit Queue
committed
augmentation support for avoid_unused_constructor_parameters
Fixes: https://github.com/dart-lang/linter/issues/4934 Change-Id: Iafd6ed199bf69214b6520dd56c5bd0012e029341 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363104 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent f807792 commit 4e3ff1d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

pkg/linter/lib/src/rules/avoid_unused_constructor_parameters.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:analyzer/dart/ast/visitor.dart';
77
import 'package:analyzer/dart/element/element.dart';
88

99
import '../analyzer.dart';
10+
import '../extensions.dart';
1011
import '../util/ascii_utils.dart';
1112

1213
const _desc = r'Avoid defining unused parameters in constructors.';
@@ -82,6 +83,7 @@ class _Visitor extends SimpleAstVisitor<void> {
8283

8384
@override
8485
void visitConstructorDeclaration(ConstructorDeclaration node) {
86+
if (node.isAugmentation) return;
8587
if (node.redirectedConstructor != null) return;
8688
if (node.externalKeyword != null) return;
8789

pkg/linter/test/rules/avoid_unused_constructor_parameters_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,42 @@ class AvoidUnusedConstructorParametersTest extends LintRuleTest {
1717
@override
1818
String get lintRule => 'avoid_unused_constructor_parameters';
1919

20+
test_augmentationClass() async {
21+
newFile('$testPackageLibPath/a.dart', r'''
22+
import augment 'test.dart';
23+
24+
class A { }
25+
''');
26+
27+
await assertDiagnostics(r'''
28+
augment library 'a.dart';
29+
30+
augment class A {
31+
A(int a);
32+
}
33+
''', [
34+
lint(49, 5),
35+
]);
36+
}
37+
38+
test_augmentedConstructor() async {
39+
newFile('$testPackageLibPath/a.dart', r'''
40+
import augment 'test.dart';
41+
42+
class A {
43+
A(int a);
44+
}
45+
''');
46+
47+
await assertNoDiagnostics(r'''
48+
augment library 'a.dart';
49+
50+
augment class A {
51+
augment A.new(int a);
52+
}
53+
''');
54+
}
55+
2056
test_super() async {
2157
await assertNoDiagnostics(r'''
2258
class A {

0 commit comments

Comments
 (0)