Skip to content

Commit

Permalink
augmentation support for avoid_unused_constructor_parameters
Browse files Browse the repository at this point in the history
Fixes: dart-lang/linter#4934


Change-Id: Iafd6ed199bf69214b6520dd56c5bd0012e029341
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363104
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
  • Loading branch information
pq authored and Commit Queue committed Apr 16, 2024
1 parent f807792 commit 4e3ff1d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';

import '../analyzer.dart';
import '../extensions.dart';
import '../util/ascii_utils.dart';

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

@override
void visitConstructorDeclaration(ConstructorDeclaration node) {
if (node.isAugmentation) return;
if (node.redirectedConstructor != null) return;
if (node.externalKeyword != null) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,42 @@ class AvoidUnusedConstructorParametersTest extends LintRuleTest {
@override
String get lintRule => 'avoid_unused_constructor_parameters';

test_augmentationClass() async {
newFile('$testPackageLibPath/a.dart', r'''
import augment 'test.dart';
class A { }
''');

await assertDiagnostics(r'''
augment library 'a.dart';
augment class A {
A(int a);
}
''', [
lint(49, 5),
]);
}

test_augmentedConstructor() async {
newFile('$testPackageLibPath/a.dart', r'''
import augment 'test.dart';
class A {
A(int a);
}
''');

await assertNoDiagnostics(r'''
augment library 'a.dart';
augment class A {
augment A.new(int a);
}
''');
}

test_super() async {
await assertNoDiagnostics(r'''
class A {
Expand Down

0 comments on commit 4e3ff1d

Please sign in to comment.