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

Commit 6247ab5

Browse files
authored
test diagnostic cleanup and fastFail bit-flip (#3003)
* test diagnostic cleanup and fastFail bit-flip * API fixes
1 parent f67eada commit 6247ab5

15 files changed

+70
-79
lines changed

lib/src/rules/always_declare_return_types.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ class _Visitor extends SimpleAstVisitor<void> {
6767
static const LintCode functionCode = LintCode(
6868
"always_declare_return_types", // ignore: prefer_single_quotes
6969
"The function '{0}' should have a return type but doesn't.",
70-
correction:
70+
correctionMessage:
7171
"Try adding a return type to the function."); // ignore: prefer_single_quotes
7272

7373
static const LintCode methodCode = LintCode(
7474
"always_declare_return_types", // ignore: prefer_single_quotes
7575
"The method '{0}' should have a return type but doesn't.",
76-
correction:
76+
correctionMessage:
7777
"Try adding a return type to the method."); // ignore: prefer_single_quotes
7878

7979
final LintRule rule;

lib/src/rules/avoid_renaming_method_parameters.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class _Visitor extends SimpleAstVisitor<void> {
6868
static const LintCode parameterCode = LintCode(
6969
"avoid_renaming_method_parameters", // ignore: prefer_single_quotes
7070
"The parameter '{0}' should have the name '{1}' to match the name used in the overridden method.",
71-
correction:
71+
correctionMessage:
7272
"Try renaming the parameter."); // ignore: prefer_single_quotes
7373

7474
final LintRule rule;

lib/src/rules/exhaustive_cases.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class _Visitor extends SimpleAstVisitor {
9494
static const LintCode lintCode = LintCode(
9595
'exhaustive_cases',
9696
"Missing case clause for '{0}'.",
97-
correction: 'Try adding a case clause for the missing constant.',
97+
correctionMessage: 'Try adding a case clause for the missing constant.',
9898
);
9999

100100
final LintRule rule;

lib/src/rules/hash_and_equals.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ class HashAndEquals extends LintRule {
6969
class _Visitor extends SimpleAstVisitor<void> {
7070
static const LintCode hashMemberCode = LintCode(
7171
'hash_and_equals', 'Override `==` if overriding `hashCode`.',
72-
correction: 'Implement `==`.');
72+
correctionMessage: 'Implement `==`.');
7373
static const LintCode equalsMemberCode = LintCode(
7474
'hash_and_equals', 'Override `hashCode` if overriding `==`.',
75-
correction: 'Implement `hashCode`.');
75+
correctionMessage: 'Implement `hashCode`.');
7676

7777
final LintRule rule;
7878

lib/src/rules/use_named_constants.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ class _Visitor extends SimpleAstVisitor<void> {
7676
arguments: ['${element.name}.${field.name}'],
7777
errorCode: const LintCode(lintName,
7878
"The constant '{0}' should be referenced instead of duplicating its value.",
79-
correction: "Try using the predefined constant '{0}'."));
79+
correctionMessage:
80+
"Try using the predefined constant '{0}'."));
8081
return;
8182
}
8283
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ environment:
1212
sdk: '>=2.12.0 <3.0.0'
1313

1414
dependencies:
15-
analyzer: '>=2.4.0 <3.0.0'
15+
analyzer: '>=2.5.0 <3.0.0'
1616
args: ^2.0.0
1717
collection: ^1.15.0
1818
glob: ^2.0.0

test/mocks.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class TestErrorCode extends ErrorCode {
130130

131131
TestErrorCode(String name, String message)
132132
: super(
133-
message: message,
133+
problemMessage: message,
134134
name: name,
135135
uniqueName: 'TestErrorCode.$name',
136136
);

test/rule_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void defineSoloRuleTest(String ruleToTest) {
202202
}
203203

204204
void testRule(String ruleName, File file,
205-
{bool debug = true, bool failOnErrors = false, String? analysisOptions}) {
205+
{bool debug = true, bool failOnErrors = true, String? analysisOptions}) {
206206
test(ruleName, () async {
207207
if (!file.existsSync()) {
208208
throw Exception('No rule found defined at: ${file.path}');

test/rules/null_closures.dart

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,59 @@ import '../rule_test_support.dart';
88

99
main() {
1010
defineReflectiveSuite(() {
11+
defineReflectiveTests(NullClosuresPreNNBDTest);
1112
defineReflectiveTests(NullClosuresTest);
1213
});
1314
}
1415

16+
@reflectiveTest
17+
class NullClosuresPreNNBDTest extends LintRuleTest {
18+
@override
19+
String get lintRule => 'null_closures';
20+
21+
test_list_firstWhere() async {
22+
await assertNoDiagnostics(r'''
23+
// @dart=2.9
24+
25+
f() => <int>[2, 4, 6].firstWhere((e) => e.isEven, orElse: () => null);
26+
''');
27+
}
28+
29+
test_list_generate() async {
30+
await assertDiagnostics(r'''
31+
// @dart=2.9
32+
33+
f() => List.generate(3, null);
34+
''', [
35+
lint('null_closures', 38, 4),
36+
]);
37+
}
38+
39+
test_list_where() async {
40+
await assertDiagnostics(r'''
41+
// @dart=2.9
42+
43+
f() => <int>[2, 4, 6].where(null);
44+
''', [
45+
lint('null_closures', 42, 4),
46+
]);
47+
}
48+
49+
test_map_putIfAbsent() async {
50+
await assertDiagnostics(r'''
51+
// @dart=2.9
52+
53+
f() {
54+
var map = <int, int>{};
55+
map.putIfAbsent(7, null);
56+
return map;
57+
}
58+
''', [
59+
lint('null_closures', 67, 4),
60+
]);
61+
}
62+
}
63+
1564
@reflectiveTest
1665
class NullClosuresTest extends LintRuleTest {
1766
@override

test_data/rules/avoid_void_async.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ void d() async => null; // LINT
1919
void e() => null; // OK
2020
Future<void> f() async => null; // OK
2121

22-
void g() async* {} // LINT
23-
void h() sync* {} // LINT
2422
Stream<void> i() async* {} // OK
2523
Iterable<void> j() sync* {} // OK
2624

@@ -46,8 +44,6 @@ class Foo {
4644
void e() => null; // OK
4745
Future<void> f() async => null; // OK
4846

49-
void g() async* {} // LINT
50-
void h() sync* {} // LINT
5147
Stream<void> i() async* {} // OK
5248
Iterable<void> j() sync* {} // OK
5349

0 commit comments

Comments
 (0)