Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit f1b13f4

Browse files
committed
support named-arguments-anywhere
1 parent af0f8c8 commit f1b13f4

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

lib/src/rules/avoid_redundant_argument_values.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ class _Visitor extends SimpleAstVisitor {
7171
for (var i = arguments.length - 1; i >= 0; --i) {
7272
var arg = arguments[i];
7373
var param = arg.staticParameterElement;
74-
if (param == null || param.hasRequired || param.isRequiredNamed) {
74+
if (param == null ||
75+
param.hasRequired ||
76+
param.isRequiredNamed ||
77+
param.isRequiredPositional) {
7578
continue;
76-
} else if (param.isRequiredPositional) {
77-
break;
7879
}
7980
var value = param.computeConstantValue();
8081
if (value != null) {

test/rules/all.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import 'avoid_function_literals_in_foreach_calls.dart'
66
as avoid_function_literals_in_foreach_calls;
77
import 'avoid_init_to_null.dart' as avoid_init_to_null;
8+
import 'avoid_redundant_argument_values.dart'
9+
as avoid_redundant_argument_values;
810
import 'avoid_shadowing_type_parameters.dart'
911
as avoid_shadowing_type_parameters;
1012
import 'conditional_uri_does_not_exist.dart' as conditional_uri_does_not_exist;
@@ -39,6 +41,7 @@ import 'void_checks.dart' as void_checks;
3941
void main() {
4042
avoid_function_literals_in_foreach_calls.main();
4143
avoid_init_to_null.main();
44+
avoid_redundant_argument_values.main();
4245
avoid_shadowing_type_parameters.main();
4346
conditional_uri_does_not_exist.main();
4447
file_names.main();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/src/dart/analysis/experiments.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../rule_test_support.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(AvoidRedundantArgumentValuesTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class AvoidRedundantArgumentValuesTest extends LintRuleTest {
18+
@override
19+
List<String> get experiments => [EnableString.named_arguments_anywhere];
20+
21+
@override
22+
String get lintRule => 'avoid_redundant_argument_values';
23+
24+
test_namedArgumentBeforePositional() async {
25+
await assertDiagnostics(r'''
26+
void foo(int a, int b, {bool c = true}) {}
27+
28+
void f() {
29+
foo(0, c: true, 1);
30+
}
31+
''', [
32+
lint('avoid_redundant_argument_values', 67, 4),
33+
]);
34+
}
35+
}

0 commit comments

Comments
 (0)