Skip to content

Commit 3f5a96b

Browse files
pqCommit Queue
authored and
Commit Queue
committed
don't overreport prefer_void_to_null in augmentations
See: https://github.com/dart-lang/linter/issues/4890 Change-Id: Ie2f3364e781c5b62cbea252460b28ba48482a552 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353203 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent b0a96bf commit 3f5a96b

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ class _Visitor extends SimpleAstVisitor<void> {
153153
return;
154154
}
155155

156+
if (parent != null) {
157+
AstNode? member = parent.thisOrAncestorOfType<ClassMember>();
158+
member ??= parent.thisOrAncestorOfType<NamedCompilationUnitMember>();
159+
if (member?.isAugmentation ?? false) return;
160+
}
161+
156162
rule.reportLintForToken(node.name2);
157163
}
158164
}

pkg/linter/test/rules/prefer_void_to_null_test.dart

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

20+
@FailingTest(
21+
issue: 'https://github.com/dart-lang/linter/issues/4890',
22+
reason: 'Null check operator used on a null value')
23+
test_augmentedField() async {
24+
newFile('$testPackageLibPath/a.dart', r'''
25+
import augment 'test.dart';
26+
27+
class A {
28+
Future<Null>? f;
29+
}
30+
''');
31+
32+
await assertNoDiagnostics(r'''
33+
library augment 'a.dart';
34+
35+
augment class A {
36+
augment Future<Null>? f;
37+
}
38+
''');
39+
}
40+
41+
test_augmentedFunction() async {
42+
newFile('$testPackageLibPath/a.dart', r'''
43+
import augment 'test.dart';
44+
45+
Future<Null>? f() => null;
46+
''');
47+
48+
await assertNoDiagnostics(r'''
49+
library augment 'a.dart';
50+
51+
augment Future<Null>? f() => null;
52+
''');
53+
}
54+
55+
test_augmentedGetter() async {
56+
newFile('$testPackageLibPath/a.dart', r'''
57+
import augment 'test.dart';
58+
59+
class A {
60+
Future<Null>? get v => null;
61+
}
62+
''');
63+
64+
await assertNoDiagnostics(r'''
65+
library augment 'a.dart';
66+
67+
augment class A {
68+
augment Future<Null>? get v => null;
69+
}
70+
''');
71+
}
72+
73+
test_augmentedMethod() async {
74+
newFile('$testPackageLibPath/a.dart', r'''
75+
import augment 'test.dart';
76+
77+
class A {
78+
Future<Null>? f() => null;
79+
}
80+
''');
81+
82+
await assertNoDiagnostics(r'''
83+
library augment 'a.dart';
84+
85+
augment class A {
86+
augment Future<Null>? f() => null;
87+
}
88+
''');
89+
}
90+
91+
@FailingTest(
92+
issue: 'https://github.com/dart-lang/linter/issues/4890',
93+
reason:
94+
"CompileTimeErrorCode.DUPLICATE_DEFINITION [55, 1, The name 'v' is already defined.]")
95+
test_augmentedTopLevelGetter() async {
96+
newFile('$testPackageLibPath/a.dart', r'''
97+
import augment 'test.dart';
98+
99+
Future<Null>? get v => null;
100+
''');
101+
102+
await assertNoDiagnostics(r'''
103+
library augment 'a.dart';
104+
105+
augment Future<Null>? get v => null;
106+
''');
107+
}
108+
109+
@FailingTest(
110+
issue: 'https://github.com/dart-lang/linter/issues/4890',
111+
reason:
112+
"CompileTimeErrorCode.DUPLICATE_DEFINITION [49, 1, The name 'v' is already defined.]")
113+
test_augmentedTopLevelVariable() async {
114+
newFile('$testPackageLibPath/a.dart', r'''
115+
import augment 'test.dart';
116+
117+
Future<Null>? v;
118+
''');
119+
120+
await assertNoDiagnostics(r'''
121+
library augment 'a.dart';
122+
123+
augment Future<Null>? v;
124+
''');
125+
}
126+
20127
/// https://github.com/dart-lang/linter/issues/4201
21128
test_castAsExpression() async {
22129
await assertNoDiagnostics(r'''

0 commit comments

Comments
 (0)