Skip to content

Commit 6719bc6

Browse files
authored
Use dart_flutter_team_lints for matcher (#2426)
Change the dependency and analysis options include to the stricter team configuration. Fix newly surfaced diagnostics. Most code changes are related to the strict modes that are enabled by the team config. Fix most implicit casts with explicit casts, but fix some arguments in `typedMatches` implementation so they don't unnecessarily widen the type back to `dynamic` before using the value. Bump to Dart 3.5 The min SDK for the test runner is already at 3.5.0 and matcher is only usable with the latest version of the test runner.
1 parent dc0f8ea commit 6719bc6

35 files changed

+188
-237
lines changed

.github/workflows/dart.yml

Lines changed: 86 additions & 148 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkgs/matcher/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## 0.12.18-wip
22

33
* Remove some dynamic invocations.
4+
* Add explicit casts from `dynamic` values.
5+
* Require Dart 3.5
46

57
## 0.12.17
68

pkgs/matcher/analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include: package:lints/recommended.yaml
1+
include: package:dart_flutter_team_lints/analysis_options.yaml
22

33
linter:
44
rules:

pkgs/matcher/lib/expect.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ export 'src/expect/prints_matcher.dart' show prints;
3838
export 'src/expect/stream_matcher.dart' show StreamMatcher;
3939
export 'src/expect/stream_matchers.dart'
4040
show
41-
emitsDone,
4241
emits,
43-
emitsError,
44-
mayEmit,
4542
emitsAnyOf,
46-
emitsInOrder,
43+
emitsDone,
44+
emitsError,
4745
emitsInAnyOrder,
46+
emitsInOrder,
4847
emitsThrough,
48+
mayEmit,
4949
mayEmitMultiple,
5050
neverEmits;
5151
export 'src/expect/throws_matcher.dart' show Throws, throws, throwsA;

pkgs/matcher/lib/mirror_matchers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class _HasProperty extends Matcher {
7373
.add('has property "$_name" with value ')
7474
.addDescriptionOf(matchState['value']);
7575
var innerDescription = StringDescription();
76-
matchState['state'] ??= {};
76+
matchState['state'] ??= <Object?, Object?>{};
7777
_matcher?.describeMismatch(matchState['value'], innerDescription,
7878
matchState['state'] as Map, verbose);
7979
if (innerDescription.length > 0) {

pkgs/matcher/lib/src/core_matchers.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class _Empty extends Matcher {
1414
const _Empty();
1515

1616
@override
17-
bool matches(Object? item, Map matchState) => (item as dynamic).isEmpty;
17+
bool matches(Object? item, Map matchState) =>
18+
(item as dynamic).isEmpty as bool;
1819

1920
@override
2021
Description describe(Description description) => description.add('empty');
@@ -27,7 +28,8 @@ class _NotEmpty extends Matcher {
2728
const _NotEmpty();
2829

2930
@override
30-
bool matches(Object? item, Map matchState) => (item as dynamic).isNotEmpty;
31+
bool matches(Object? item, Map matchState) =>
32+
(item as dynamic).isNotEmpty as bool;
3133

3234
@override
3335
Description describe(Description description) => description.add('non-empty');

pkgs/matcher/lib/src/equals_matcher.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class _DeepMatcher extends Matcher {
167167
Object? expected, Object? actual, String location, int depth) {
168168
// If the expected value is a matcher, try to match it.
169169
if (expected is Matcher) {
170-
var matchState = {};
170+
var matchState = <Object?, Object?>{};
171171
if (expected.matches(actual, matchState)) return null;
172172
return _Mismatch(location, actual, (description, verbose) {
173173
var oldLength = description.length;

pkgs/matcher/lib/src/expect/expect.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ Future expectLater(dynamic actual, dynamic matcher,
7474

7575
/// The implementation of [expect] and [expectLater].
7676
Future _expect(Object? actual, Object? matcher,
77-
{String? reason, skip, bool verbose = false, ErrorFormatter? formatter}) {
77+
{String? reason,
78+
Object? skip,
79+
bool verbose = false,
80+
ErrorFormatter? formatter}) {
7881
final test = TestHandle.current;
7982
formatter ??= (actual, matcher, reason, matchState, verbose) {
8083
var mismatchDescription = StringDescription();
@@ -133,7 +136,7 @@ Future _expect(Object? actual, Object? matcher,
133136
return Future.sync(() {});
134137
}
135138

136-
var matchState = {};
139+
var matchState = <Object?, Object?>{};
137140
try {
138141
if ((matcher as Matcher).matches(actual, matchState)) {
139142
return Future.sync(() {});

pkgs/matcher/lib/src/expect/expect_async.dart

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,17 @@ class _ExpectedFunction<T> {
124124
/// Returns a function that has the same number of positional arguments as the
125125
/// wrapped function (up to a total of 6).
126126
Function get func {
127-
if (_callback is Function(Never, Never, Never, Never, Never, Never)) {
127+
if (_callback is void Function(Never, Never, Never, Never, Never, Never)) {
128128
return max6;
129129
}
130-
if (_callback is Function(Never, Never, Never, Never, Never)) return max5;
131-
if (_callback is Function(Never, Never, Never, Never)) return max4;
132-
if (_callback is Function(Never, Never, Never)) return max3;
133-
if (_callback is Function(Never, Never)) return max2;
134-
if (_callback is Function(Never)) return max1;
135-
if (_callback is Function()) return max0;
130+
if (_callback is void Function(Never, Never, Never, Never, Never)) {
131+
return max5;
132+
}
133+
if (_callback is void Function(Never, Never, Never, Never)) return max4;
134+
if (_callback is void Function(Never, Never, Never)) return max3;
135+
if (_callback is void Function(Never, Never)) return max2;
136+
if (_callback is void Function(Never)) return max1;
137+
if (_callback is void Function()) return max0;
136138

137139
_outstandingWork?.complete();
138140
throw ArgumentError(
@@ -219,7 +221,8 @@ class _ExpectedFunction<T> {
219221
@Deprecated('Will be removed in 0.13.0')
220222
Function expectAsync(Function callback,
221223
{int count = 1, int max = 0, String? id, String? reason}) =>
222-
_ExpectedFunction(callback, count, max, id: id, reason: reason).func;
224+
_ExpectedFunction<Object?>(callback, count, max, id: id, reason: reason)
225+
.func;
223226

224227
/// Informs the framework that the given [callback] of arity 0 is expected to be
225228
/// called [count] number of times (by default 1).
@@ -415,7 +418,8 @@ Func6<T, A, B, C, D, E, F> expectAsync6<T, A, B, C, D, E, F>(
415418
@Deprecated('Will be removed in 0.13.0')
416419
Function expectAsyncUntil(Function callback, bool Function() isDone,
417420
{String? id, String? reason}) =>
418-
_ExpectedFunction(callback, 0, -1, id: id, reason: reason, isDone: isDone)
421+
_ExpectedFunction<Object?>(callback, 0, -1,
422+
id: id, reason: reason, isDone: isDone)
419423
.func;
420424

421425
/// Informs the framework that the given [callback] of arity 0 is expected to be

pkgs/matcher/lib/src/expect/future_matchers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class _Completes extends AsyncMatcher {
5858
result = await _matcher.matchAsync(value) as String?;
5959
if (result == null) return null;
6060
} else {
61-
var matchState = {};
61+
var matchState = <Object?, Object?>{};
6262
if (_matcher.matches(value, matchState)) return null;
6363
result = _matcher
6464
.describeMismatch(value, StringDescription(), matchState, false)

0 commit comments

Comments
 (0)