Skip to content

Commit e90210b

Browse files
pqCommit Queue
authored and
Commit Queue
committed
augmentation support for overridden_fields
Fixes: https://github.com/dart-lang/linter/issues/4930 Change-Id: Iee270a59ab3ba76f414a7d743aad92559808a948 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363640 Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 2a265c1 commit e90210b

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:analyzer/dart/element/type.dart';
99
import 'package:collection/collection.dart' show IterableExtension;
1010

1111
import '../analyzer.dart';
12+
import '../extensions.dart';
1213

1314
const _desc = r"Don't override fields.";
1415

@@ -128,9 +129,8 @@ class _Visitor extends SimpleAstVisitor<void> {
128129

129130
@override
130131
void visitFieldDeclaration(FieldDeclaration node) {
131-
if (node.isStatic) {
132-
return;
133-
}
132+
if (node.isAugmentation) return;
133+
if (node.isStatic) return;
134134

135135
for (var variable in node.fields.variables) {
136136
var declaredField = variable.declaredElement;

pkg/linter/test/rules/overridden_fields_test.dart

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

20+
test_augmentationClass() async {
21+
var a = newFile('$testPackageLibPath/a.dart', r'''
22+
import augment 'b.dart';
23+
24+
class O {
25+
final a = '';
26+
}
27+
28+
class A extends O { }
29+
''');
30+
31+
var b = newFile('$testPackageLibPath/b.dart', r'''
32+
augment library 'a.dart';
33+
34+
augment class A {
35+
final a = '';
36+
}
37+
''');
38+
39+
result = await resolveFile(a.path);
40+
await assertNoDiagnosticsIn(errors);
41+
42+
result = await resolveFile(b.path);
43+
await assertDiagnosticsIn(errors, [
44+
lint(54, 1),
45+
]);
46+
}
47+
48+
test_augmentedField() async {
49+
var a = newFile('$testPackageLibPath/a.dart', r'''
50+
import augment 'b.dart';
51+
52+
class O {
53+
final a = '';
54+
}
55+
56+
class A extends O {
57+
@override
58+
final a = '';
59+
}
60+
''');
61+
62+
var b = newFile('$testPackageLibPath/b.dart', r'''
63+
augment library 'a.dart';
64+
65+
augment class A {
66+
augment final a = '';
67+
}
68+
''');
69+
70+
result = await resolveFile(a.path);
71+
await assertDiagnosticsIn(errors, [
72+
lint(96, 1),
73+
]);
74+
75+
result = await resolveFile(b.path);
76+
await assertNoDiagnosticsIn(errors);
77+
}
78+
2079
/// https://github.com/dart-lang/linter/issues/2874
2180
test_conflictingStaticAndInstance() async {
2281
await assertNoDiagnostics(r'''

0 commit comments

Comments
 (0)