go/dart-cbuild result: SUCCESS
Details: https://goto.google.com/dart-cbuild/find/4cbf7d587fff8c87c824ac3db5126d70a4c693a8
To view, visit change 329140. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Phil Quitslund.
Samuel Rawlins would like Phil Quitslund to review this change.
linter: Move avoid_multiple_declarations_per_line tests
Change-Id: I92271ad7999c521ea343c3199dc09f32a897b0c7
---
M pkg/linter/test/rules/all.dart
A pkg/linter/test/rules/avoid_multiple_declarations_per_line_test.dart
D pkg/linter/test_data/rules/avoid_multiple_declarations_per_line.dart
3 files changed, 99 insertions(+), 59 deletions(-)
diff --git a/pkg/linter/test/rules/all.dart b/pkg/linter/test/rules/all.dart
index adc8b30..3fe18c4 100644
--- a/pkg/linter/test/rules/all.dart
+++ b/pkg/linter/test/rules/all.dart
@@ -16,6 +16,8 @@
import 'avoid_function_literals_in_foreach_calls_test.dart'
as avoid_function_literals_in_foreach_calls;
import 'avoid_init_to_null_test.dart' as avoid_init_to_null;
+import 'avoid_multiple_declarations_per_line_test.dart'
+ as avoid_multiple_declarations_per_line;
import 'avoid_positional_boolean_parameters_test.dart'
as avoid_positional_boolean_parameters;
import 'avoid_print_test.dart' as avoid_print;
@@ -259,6 +261,7 @@
avoid_final_parameters.main();
avoid_function_literals_in_foreach_calls.main();
avoid_init_to_null.main();
+ avoid_multiple_declarations_per_line.main();
avoid_positional_boolean_parameters.main();
avoid_print.main();
avoid_private_typedef_functions.main();
diff --git a/pkg/linter/test/rules/avoid_multiple_declarations_per_line_test.dart b/pkg/linter/test/rules/avoid_multiple_declarations_per_line_test.dart
new file mode 100644
index 0000000..251bd64
--- /dev/null
+++ b/pkg/linter/test/rules/avoid_multiple_declarations_per_line_test.dart
@@ -0,0 +1,96 @@
+// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import '../rule_test_support.dart';
+
+main() {
+ defineReflectiveSuite(() {
+ defineReflectiveTests(AvoidMultipleDeclarationsPerLineTest);
+ });
+}
+
+@reflectiveTest
+class AvoidMultipleDeclarationsPerLineTest extends LintRuleTest {
+ @override
+ String get lintRule => 'avoid_multiple_declarations_per_line';
+
+ test_extensionField_multiple() async {
+ await assertDiagnostics(r'''
+extension E on Object {
+ static String? a, b, c;
+}
+''', [
+ lint(44, 1),
+ ]);
+ }
+
+ test_extensionField_single() async {
+ await assertNoDiagnostics(r'''
+extension E on Object {
+ static String? a;
+}
+''');
+ }
+
+ test_field_multiple() async {
+ await assertDiagnostics(r'''
+class C {
+ String? a, b, c;
+}
+''', [
+ lint(23, 1),
+ ]);
+ }
+
+ test_field_single() async {
+ await assertNoDiagnostics(r'''
+class C {
+ String? a;
+}
+''');
+ }
+
+ test_forLoop_multiple() async {
+ await assertNoDiagnostics(r'''
+// See https://github.com/dart-lang/linter/issues/2543.
+void f() {
+ for (var i = 0, j = 0; i < 2 && j < 2; ++i, ++j) {}
+}
+''');
+ }
+
+ test_functionVariable_multiple() async {
+ await assertDiagnostics(r'''
+void f() {
+ String? a, b, c;
+}
+''', [
+ lint(24, 1),
+ ]);
+ }
+
+ test_functionVariable_single() async {
+ await assertNoDiagnostics(r'''
+void f() {
+ String? a;
+}
+''');
+ }
+
+ test_topLevel_multiple() async {
+ await assertDiagnostics(r'''
+String? a, b, c;
+''', [
+ lint(11, 1),
+ ]);
+ }
+
+ test_topLevel_single() async {
+ await assertNoDiagnostics(r'''
+String? a;
+''');
+ }
+}
diff --git a/pkg/linter/test_data/rules/avoid_multiple_declarations_per_line.dart b/pkg/linter/test_data/rules/avoid_multiple_declarations_per_line.dart
deleted file mode 100644
index 3c23858..0000000
--- a/pkg/linter/test_data/rules/avoid_multiple_declarations_per_line.dart
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-// ignore_for_file: unused_local_variable
-
-String? badFoo, badBar, badBaz; // LINT
-
-String? goodFoo;
-String? goodBar;
-String? goodBaz;
-
-methodContainingBadDeclaration() {
- String? badFoo, badBar, badBaz; // LINT
-}
-
-methodContainingGoodDeclaration() {
- String? goodFoo;
- String? goodBar;
- String? goodBaz;
-}
-
-class BadClass {
- String? foo, bar, baz; // LINT
-
- methodContainingBadDeclaration() {
- String? badFoo, badBar, badBaz; // LINT
- }
-}
-
-class GoodClass {
- String? foo;
- String? bar;
- String? baz;
-
- methodContainingGoodDeclaration() {
- String? goodFoo;
- String? goodBar;
- String? goodBaz;
- }
-}
-
-extension BadExtension on Object {
- static String? badFoo, badBar, badBaz; // LINT
-}
-
-extension GoodExtension on Object {
- static String? foo;
- static String? bar;
- static String? baz;
-}
-
-// https://github.com/dart-lang/linter/issues/2543
-okInForLoop() {
- for (var i = 0, j = 0; i < 2 && j < 2; ++i, ++j) // OK
- {
- //
- }
-}
To view, visit change 329140. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Phil Quitslund.
Patch set 1:Auto-Submit +1
Attention is currently required from: Samuel Rawlins.
Patch set 1:Code-Review +1Commit-Queue +2
Commit Queue submitted this change.
linter: Move avoid_multiple_declarations_per_line tests
Change-Id: I92271ad7999c521ea343c3199dc09f32a897b0c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329140
Auto-Submit: Samuel Rawlins <sraw...@google.com>
Reviewed-by: Phil Quitslund <pquit...@google.com>
Commit-Queue: Phil Quitslund <pquit...@google.com>
---
M pkg/linter/test/rules/all.dart
A pkg/linter/test/rules/avoid_multiple_declarations_per_line_test.dart
D pkg/linter/test_data/rules/avoid_multiple_declarations_per_line.dart
3 files changed, 99 insertions(+), 59 deletions(-)
diff --git a/pkg/linter/test/rules/all.dart b/pkg/linter/test/rules/all.dart
index 4ec5355..65d4c69 100644
--- a/pkg/linter/test/rules/all.dart
+++ b/pkg/linter/test/rules/all.dart
@@ -16,6 +16,8 @@
import 'avoid_function_literals_in_foreach_calls_test.dart'
as avoid_function_literals_in_foreach_calls;
import 'avoid_init_to_null_test.dart' as avoid_init_to_null;
+import 'avoid_multiple_declarations_per_line_test.dart'
+ as avoid_multiple_declarations_per_line;
import 'avoid_positional_boolean_parameters_test.dart'
as avoid_positional_boolean_parameters;
import 'avoid_print_test.dart' as avoid_print;
@@ -260,6 +262,7 @@To view, visit change 329140. To unsubscribe, or for help writing mail filters, visit settings.
go/dart-cbuild result: SUCCESS
Details: https://goto.google.com/dart-cbuild/find/8d80d978addf38ba6e3b40f8284d3c1a949c329c