Skip to content

Commit 3a94bc7

Browse files
FMorschelCommit Queue
authored andcommitted
[linter] Fixes false-negative avoid_redundant_argument_values at annotations
Fixes: #61456 Change-Id: I491c1c9e64ccce47555d04e7eab5587ce5a8a540 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448604 Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Felipe Morschel <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 78d280a commit 3a94bc7

File tree

2 files changed

+59
-26
lines changed

2 files changed

+59
-26
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class AvoidRedundantArgumentValues extends LintRule {
3535
registry.addInstanceCreationExpression(this, visitor);
3636
registry.addFunctionExpressionInvocation(this, visitor);
3737
registry.addMethodInvocation(this, visitor);
38+
registry.addAnnotation(this, visitor);
3839
}
3940
}
4041

@@ -86,6 +87,13 @@ class _Visitor extends SimpleAstVisitor<void> {
8687
}
8788
}
8889

90+
@override
91+
void visitAnnotation(Annotation node) {
92+
if (node.arguments case var arguments?) {
93+
check(arguments);
94+
}
95+
}
96+
8997
@override
9098
void visitEnumConstantArguments(EnumConstantArguments node) {
9199
check(node.argumentList);

pkg/linter/test/rules/avoid_redundant_argument_values_test.dart

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AvoidRedundantArgumentValuesNamedArgsAnywhereTest extends LintRuleTest {
1818
@override
1919
String get lintRule => LintNames.avoid_redundant_argument_values;
2020

21-
test_namedArgumentBeforePositional() async {
21+
Future<void> test_namedArgumentBeforePositional() async {
2222
await assertDiagnostics(
2323
r'''
2424
void foo(int a, int b, {bool c = true}) {}
@@ -37,7 +37,30 @@ class AvoidRedundantArgumentValuesTest extends LintRuleTest {
3737
@override
3838
String get lintRule => LintNames.avoid_redundant_argument_values;
3939

40-
test_constructor_redundant() async {
40+
Future<void> test_annotation() async {
41+
await assertNoDiagnostics(r'''
42+
@A(p: false)
43+
class A {
44+
final bool p;
45+
const A({this.p = true});
46+
}
47+
''');
48+
}
49+
50+
Future<void> test_annotation_redundant() async {
51+
await assertDiagnostics(
52+
r'''
53+
@A(p: true)
54+
class A {
55+
final bool p;
56+
const A({this.p = true});
57+
}
58+
''',
59+
[lint(6, 4)],
60+
);
61+
}
62+
63+
Future<void> test_constructor_redundant() async {
4164
await assertDiagnostics(
4265
r'''
4366
void f() {
@@ -51,7 +74,7 @@ class A {
5174
);
5275
}
5376

54-
test_constructor_tearoff_redundant() async {
77+
Future<void> test_constructor_tearoff_redundant() async {
5578
await assertDiagnostics(
5679
r'''
5780
void f() {
@@ -67,7 +90,7 @@ class A {
6790
}
6891

6992
/// https://github.com/dart-lang/linter/issues/3617
70-
test_enumDeclaration() async {
93+
Future<void> test_enumDeclaration() async {
7194
await assertDiagnostics(
7295
r'''
7396
enum TestEnum {
@@ -83,7 +106,7 @@ enum TestEnum {
83106
}
84107

85108
@FailingTest(issue: 'https://github.com/dart-lang/linter/issues/3447')
86-
test_fromEnvironment() async {
109+
Future<void> test_fromEnvironment() async {
87110
await assertNoDiagnostics(r'''
88111
const bool someDefine = bool.fromEnvironment('someDefine');
89112
@@ -97,7 +120,7 @@ void g() {
97120
''');
98121
}
99122

100-
test_function_optionalPositional_followedByPositional() async {
123+
Future<void> test_function_optionalPositional_followedByPositional() async {
101124
await assertNoDiagnostics(r'''
102125
void f() {
103126
g(0, 1);
@@ -106,7 +129,7 @@ void g([int a = 0, int? b]) {}
106129
''');
107130
}
108131

109-
test_function_optionalPositional_subsequent_different() async {
132+
Future<void> test_function_optionalPositional_subsequent_different() async {
110133
await assertNoDiagnostics(r'''
111134
void f() {
112135
g(0, 2);
@@ -115,7 +138,7 @@ void g([int? a, int? b = 1]) {}
115138
''');
116139
}
117140

118-
test_function_optionalPositional_subsequent_redundant() async {
141+
Future<void> test_function_optionalPositional_subsequent_redundant() async {
119142
await assertDiagnostics(
120143
r'''
121144
void f() {
@@ -127,7 +150,7 @@ void g([int? a, int? b = 1]) {}
127150
);
128151
}
129152

130-
test_localFunction_optionalNamed_different() async {
153+
Future<void> test_localFunction_optionalNamed_different() async {
131154
await assertNoDiagnostics(r'''
132155
void f() {
133156
void g({bool p = true}) {}
@@ -136,7 +159,7 @@ void f() {
136159
''');
137160
}
138161

139-
test_localFunction_optionalNamed_redundant() async {
162+
Future<void> test_localFunction_optionalNamed_redundant() async {
140163
await assertDiagnostics(
141164
r'''
142165
void f() {
@@ -148,7 +171,7 @@ void f() {
148171
);
149172
}
150173

151-
test_method_noDefault() async {
174+
Future<void> test_method_noDefault() async {
152175
await assertNoDiagnostics(r'''
153176
void f(A a) {
154177
a.g(p: false);
@@ -159,7 +182,7 @@ class A {
159182
''');
160183
}
161184

162-
test_method_optionalNamed_variable() async {
185+
Future<void> test_method_optionalNamed_variable() async {
163186
await assertNoDiagnostics(r'''
164187
void f(A a, bool v) {
165188
a.g(p: v);
@@ -170,7 +193,7 @@ class A {
170193
''');
171194
}
172195

173-
test_method_redundant() async {
196+
Future<void> test_method_redundant() async {
174197
await assertDiagnostics(
175198
r'''
176199
void f(A a) {
@@ -184,7 +207,7 @@ class A {
184207
);
185208
}
186209

187-
test_redirectingFactoryConstructor() async {
210+
Future<void> test_redirectingFactoryConstructor() async {
188211
await assertNoDiagnostics(r'''
189212
class A {
190213
factory A([int? value]) = B;
@@ -201,7 +224,7 @@ void f() {
201224
''');
202225
}
203226

204-
test_redirectingFactoryConstructor_cyclic() async {
227+
Future<void> test_redirectingFactoryConstructor_cyclic() async {
205228
await assertDiagnostics(
206229
r'''
207230
class A {
@@ -220,7 +243,7 @@ void f() {
220243
);
221244
}
222245

223-
test_redirectingFactoryConstructor_multipleOptional() async {
246+
Future<void> test_redirectingFactoryConstructor_multipleOptional() async {
224247
await assertNoDiagnostics(r'''
225248
class A {
226249
factory A([int? one, int? two]) = B;
@@ -239,7 +262,7 @@ void f() {
239262
''');
240263
}
241264

242-
test_redirectingFactoryConstructor_named() async {
265+
Future<void> test_redirectingFactoryConstructor_named() async {
243266
await assertNoDiagnostics(r'''
244267
class A {
245268
factory A({int? value}) = B;
@@ -256,7 +279,7 @@ void f() {
256279
''');
257280
}
258281

259-
test_redirectingFactoryConstructor_named_redundant() async {
282+
Future<void> test_redirectingFactoryConstructor_named_redundant() async {
260283
await assertDiagnostics(
261284
r'''
262285
class A {
@@ -274,6 +297,7 @@ void f() {
274297
);
275298
}
276299

300+
Future<void>
277301
test_redirectingFactoryConstructor_namedArgumentsAnywhere() async {
278302
await assertNoDiagnostics(r'''
279303
class A {
@@ -293,6 +317,7 @@ void f() {
293317
''');
294318
}
295319

320+
Future<void>
296321
test_redirectingFactoryConstructor_namedArgumentsAnywhere_redundant() async {
297322
await assertDiagnostics(
298323
r'''
@@ -311,7 +336,7 @@ void f() {
311336
);
312337
}
313338

314-
test_redirectingFactoryConstructor_nested() async {
339+
Future<void> test_redirectingFactoryConstructor_nested() async {
315340
await assertNoDiagnostics(r'''
316341
class A {
317342
factory A([num? value]) = B;
@@ -336,7 +361,7 @@ void f() {
336361
''');
337362
}
338363

339-
test_redirectingFactoryConstructor_redundant() async {
364+
Future<void> test_redirectingFactoryConstructor_redundant() async {
340365
await assertDiagnostics(
341366
r'''
342367
class A {
@@ -354,7 +379,7 @@ void f() {
354379
);
355380
}
356381

357-
test_redirectingGenerativeConstructor() async {
382+
Future<void> test_redirectingGenerativeConstructor() async {
358383
await assertNoDiagnostics(r'''
359384
class A {
360385
A([int? value]) : this._(value);
@@ -366,7 +391,7 @@ void f() {
366391
''');
367392
}
368393

369-
test_redirectingGenerativeConstructor_named() async {
394+
Future<void> test_redirectingGenerativeConstructor_named() async {
370395
await assertNoDiagnostics(r'''
371396
class A {
372397
A({int? value}) : this._(value: value);
@@ -378,7 +403,7 @@ void f() {
378403
''');
379404
}
380405

381-
test_redirectingGenerativeConstructor_named_redundant() async {
406+
Future<void> test_redirectingGenerativeConstructor_named_redundant() async {
382407
await assertDiagnostics(
383408
r'''
384409
class A {
@@ -393,7 +418,7 @@ void f() {
393418
);
394419
}
395420

396-
test_redirectingGenerativeConstructor_redundant() async {
421+
Future<void> test_redirectingGenerativeConstructor_redundant() async {
397422
await assertDiagnostics(
398423
r'''
399424
class A {
@@ -408,7 +433,7 @@ void f() {
408433
);
409434
}
410435

411-
test_requiredNullable() async {
436+
Future<void> test_requiredNullable() async {
412437
await assertNoDiagnostics(r'''
413438
void f({required int? x}) { }
414439
@@ -419,7 +444,7 @@ void main() {
419444
}
420445

421446
@FailingTest(issue: 'https://github.com/dart-lang/linter/issues/4967')
422-
test_toListOptionalGrowable() async {
447+
Future<void> test_toListOptionalGrowable() async {
423448
await assertDiagnostics(
424449
r'''
425450
void main() {

0 commit comments

Comments
 (0)