Skip to content

Commit 9d2df84

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer_testing: add more default-ignored codes
UNUSED_ELEMENT and UNUSED_FIELD were added to the "ignore list" for the tests of a dozen lint rules. I think it is pretty harmless to ignore them by default, and save plugin authors some `// ignore:` comments, or hand-wringing about how to get rid of an "unused" field in a test which is needed in order to test an analysis rule. Change-Id: Ic35fead8a44d8d3341f9e32e92b53610b517edf5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430121 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Keerti Parthasarathy <[email protected]>
1 parent 7397c1e commit 9d2df84

23 files changed

+66
-323
lines changed

pkg/analyzer_testing/lib/src/analysis_rule/pub_package_resolution.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ class PubPackageResolutionTest with MockPackagesMixin, ResourceProviderMixin {
153153

154154
/// Error codes that by default should be ignored in test expectations.
155155
List<DiagnosticCode> get ignoredErrorCodes => [
156+
WarningCode.UNUSED_ELEMENT,
157+
WarningCode.UNUSED_FIELD,
156158
WarningCode.UNUSED_LOCAL_VARIABLE,
157159
];
158160

pkg/linter/test/rules/avoid_catches_without_on_clauses_test.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/error/error.dart';
65
import 'package:test_reflective_loader/test_reflective_loader.dart';
76

87
import '../rule_test_support.dart';
@@ -18,12 +17,6 @@ class AvoidCatchesWithoutOnClausesTest extends LintRuleTest {
1817
@override
1918
bool get addFlutterPackageDep => true;
2019

21-
@override
22-
List<DiagnosticCode> get ignoredErrorCodes => [
23-
WarningCode.UNUSED_ELEMENT,
24-
WarningCode.UNUSED_LOCAL_VARIABLE,
25-
];
26-
2720
@override
2821
String get lintRule => LintNames.avoid_catches_without_on_clauses;
2922

pkg/linter/test/rules/avoid_private_typedef_functions_test.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/error/error.dart';
65
import 'package:test_reflective_loader/test_reflective_loader.dart';
76

87
import '../rule_test_support.dart';
@@ -15,13 +14,6 @@ void main() {
1514

1615
@reflectiveTest
1716
class AvoidPrivateTypedefFunctionsTest extends LintRuleTest {
18-
@override
19-
List<DiagnosticCode> get ignoredErrorCodes => [
20-
WarningCode.UNUSED_ELEMENT,
21-
WarningCode.UNUSED_FIELD,
22-
WarningCode.UNUSED_LOCAL_VARIABLE,
23-
];
24-
2517
@override
2618
String get lintRule => LintNames.avoid_private_typedef_functions;
2719

pkg/linter/test/rules/avoid_returning_null_for_void_test.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/error/error.dart';
65
import 'package:test_reflective_loader/test_reflective_loader.dart';
76

87
import '../rule_test_support.dart';
@@ -15,12 +14,6 @@ void main() {
1514

1615
@reflectiveTest
1716
class AvoidReturningNullForVoidTest extends LintRuleTest {
18-
@override
19-
List<DiagnosticCode> get ignoredErrorCodes => [
20-
WarningCode.UNUSED_ELEMENT,
21-
WarningCode.UNUSED_LOCAL_VARIABLE,
22-
];
23-
2417
@override
2518
String get lintRule => 'avoid_returning_null_for_void';
2619

pkg/linter/test/rules/avoid_shadowing_type_parameters_test.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/error/error.dart';
65
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
76
import 'package:test_reflective_loader/test_reflective_loader.dart';
87

@@ -16,12 +15,6 @@ void main() {
1615

1716
@reflectiveTest
1817
class AvoidShadowingTypeParametersTest extends LintRuleTest {
19-
@override
20-
List<DiagnosticCode> get ignoredErrorCodes => [
21-
WarningCode.UNUSED_ELEMENT,
22-
WarningCode.UNUSED_LOCAL_VARIABLE,
23-
];
24-
2518
@override
2619
String get lintRule => LintNames.avoid_shadowing_type_parameters;
2720

pkg/linter/test/rules/avoid_types_as_parameter_names_test.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,11 @@ class C {}
249249
}
250250

251251
test_typeParameter_wildcard() async {
252-
await assertDiagnostics(
253-
r'''
252+
await assertNoDiagnostics(r'''
254253
class C<_> {
255254
var _;
256255
C.c(this._, _);
257256
}
258-
''',
259-
[error(WarningCode.UNUSED_FIELD, 19, 1)],
260-
);
257+
''');
261258
}
262259
}

pkg/linter/test/rules/avoid_void_async_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void f() {
110110
void g() async => null;
111111
}
112112
''',
113-
[error(WarningCode.UNUSED_ELEMENT, 18, 1), lint(18, 1)],
113+
[lint(18, 1)],
114114
);
115115
}
116116

@@ -121,7 +121,7 @@ void f() {
121121
void main() async => null;
122122
}
123123
''',
124-
[error(WarningCode.UNUSED_ELEMENT, 18, 4), lint(18, 4)],
124+
[lint(18, 4)],
125125
);
126126
}
127127

@@ -156,7 +156,7 @@ Future<void> f() async {
156156
void g() async {}
157157
}
158158
''',
159-
[error(WarningCode.UNUSED_ELEMENT, 32, 1), lint(32, 1)],
159+
[lint(32, 1)],
160160
);
161161
}
162162

pkg/linter/test/rules/cancel_subscriptions_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class A {
123123
}
124124
}
125125
''',
126-
[error(WarningCode.UNUSED_FIELD, 57, 13), lint(57, 13)],
126+
[lint(57, 13)],
127127
);
128128
}
129129
}

pkg/linter/test/rules/library_private_types_in_public_api_test.dart

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/error/error.dart';
65
import 'package:test_reflective_loader/test_reflective_loader.dart';
76

87
import '../rule_test_support.dart';
@@ -18,13 +17,6 @@ void main() {
1817

1918
@reflectiveTest
2019
class LibraryPrivateTypesInPublicApiEnumTest extends LintRuleTest {
21-
@override
22-
List<DiagnosticCode> get ignoredErrorCodes => [
23-
WarningCode.UNUSED_LOCAL_VARIABLE,
24-
WarningCode.UNUSED_ELEMENT,
25-
WarningCode.UNUSED_FIELD,
26-
];
27-
2820
@override
2921
String get lintRule => LintNames.library_private_types_in_public_api;
3022

@@ -95,13 +87,6 @@ sealed class E {
9587

9688
@reflectiveTest
9789
class LibraryPrivateTypesInPublicApiExtensionTypeTest extends LintRuleTest {
98-
@override
99-
List<DiagnosticCode> get ignoredErrorCodes => [
100-
WarningCode.UNUSED_LOCAL_VARIABLE,
101-
WarningCode.UNUSED_ELEMENT,
102-
WarningCode.UNUSED_FIELD,
103-
];
104-
10590
@override
10691
String get lintRule => LintNames.library_private_types_in_public_api;
10792

@@ -244,13 +229,6 @@ extension type E(Object o) {
244229

245230
@reflectiveTest
246231
class LibraryPrivateTypesInPublicApiSuperParamTest extends LintRuleTest {
247-
@override
248-
List<DiagnosticCode> get ignoredErrorCodes => [
249-
WarningCode.UNUSED_LOCAL_VARIABLE,
250-
WarningCode.UNUSED_ELEMENT,
251-
WarningCode.UNUSED_FIELD,
252-
];
253-
254232
@override
255233
String get lintRule => LintNames.library_private_types_in_public_api;
256234

@@ -305,13 +283,6 @@ class B extends A {
305283

306284
@reflectiveTest
307285
class LibraryPrivateTypesInPublicApiTest extends LintRuleTest {
308-
@override
309-
List<DiagnosticCode> get ignoredErrorCodes => [
310-
WarningCode.UNUSED_LOCAL_VARIABLE,
311-
WarningCode.UNUSED_ELEMENT,
312-
WarningCode.UNUSED_FIELD,
313-
];
314-
315286
@override
316287
String get lintRule => LintNames.library_private_types_in_public_api;
317288

pkg/linter/test/rules/no_leading_underscores_for_local_identifiers_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ class NoLeadingUnderscoresForLocalIdentifiersTest extends LintRuleTest {
1818
@override
1919
List<DiagnosticCode> get ignoredErrorCodes => [
2020
WarningCode.UNUSED_CATCH_STACK,
21-
WarningCode.UNUSED_ELEMENT,
22-
WarningCode.UNUSED_FIELD,
23-
WarningCode.UNUSED_LOCAL_VARIABLE,
21+
...super.ignoredErrorCodes,
2422
];
2523

2624
@override

0 commit comments

Comments
 (0)