Skip to content

Commit 27430e8

Browse files
committed
Switch topackage:dart_flutter_team_lints
1 parent eb4d1da commit 27430e8

20 files changed

+115
-127
lines changed

analysis_options.yaml

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

33
analyzer:
4+
errors:
5+
lines_longer_than_80_chars: ignore
46
language:
57
strict-casts: true
68

example/build_extensions/example.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// ignore_for_file: unreachable_from_main
16+
1517
import 'package:mockito/annotations.dart';
1618
import 'package:mockito/mockito.dart';
1719
import 'package:test_api/scaffolding.dart';
@@ -30,7 +32,7 @@ class Dog {
3032
@GenerateNiceMocks([MockSpec<Dog>()])
3133
void main() {
3234
test('Verify some dog behaviour', () async {
33-
MockDog mockDog = MockDog();
35+
var mockDog = MockDog();
3436
when(mockDog.eatFood(any));
3537

3638
mockDog.eatFood('biscuits');

example/example.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: unreachable_from_main
2+
13
import 'dart:async';
24

35
import 'package:mockito/annotations.dart';
@@ -229,7 +231,7 @@ void main() {
229231
final cat = FakeCat();
230232

231233
cat.eatFood('Milk'); // Prints 'Fake eat Milk'.
232-
expect(() => cat.sleep(), throwsUnimplementedError);
234+
expect(cat.sleep, throwsUnimplementedError);
233235
});
234236

235237
test('Relaxed mock class', () {

example/iss/iss.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ class IssLocator {
4141
// at this moment.
4242
final uri = Uri.parse('http://api.open-notify.org/iss-now.json');
4343
final rs = await client.get(uri);
44-
final data = jsonDecode(rs.body);
45-
final latitude = double.parse(data['iss_position']['latitude'] as String);
46-
final longitude = double.parse(data['iss_position']['longitude'] as String);
44+
final data = jsonDecode(rs.body) as Map;
45+
final position = data['iss_position'] as Map;
46+
final latitude = double.parse(position['latitude'] as String);
47+
final longitude = double.parse(position['longitude'] as String);
4748
_position = Point<double>(latitude, longitude);
4849
}
4950
}

example/iss/iss_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ void main() {
2727
// verify the calculated distance between them.
2828
group('Spherical distance', () {
2929
test('London - Paris', () {
30-
final london = Point(51.5073, -0.1277);
31-
final paris = Point(48.8566, 2.3522);
30+
final london = const Point(51.5073, -0.1277);
31+
final paris = const Point(48.8566, 2.3522);
3232
final d = sphericalDistanceKm(london, paris);
3333
// London should be approximately 343.5km
3434
// (+/- 0.1km) from Paris.
3535
expect(d, closeTo(343.5, 0.1));
3636
});
3737

3838
test('San Francisco - Mountain View', () {
39-
final sf = Point(37.783333, -122.416667);
40-
final mtv = Point(37.389444, -122.081944);
39+
final sf = const Point(37.783333, -122.416667);
40+
final mtv = const Point(37.389444, -122.081944);
4141
final d = sphericalDistanceKm(sf, mtv);
4242
// San Francisco should be approximately 52.8km
4343
// (+/- 0.1km) from Mountain View.
@@ -52,8 +52,8 @@ void main() {
5252
// second predefined location. This test runs asynchronously.
5353
group('ISS spotter', () {
5454
test('ISS visible', () async {
55-
final sf = Point(37.783333, -122.416667);
56-
final mtv = Point(37.389444, -122.081944);
55+
final sf = const Point(37.783333, -122.416667);
56+
final mtv = const Point(37.389444, -122.081944);
5757
final IssLocator locator = MockIssLocator();
5858
// Mountain View should be visible from San Francisco.
5959
when(locator.currentPosition).thenReturn(sf);
@@ -63,8 +63,8 @@ void main() {
6363
});
6464

6565
test('ISS not visible', () async {
66-
final london = Point(51.5073, -0.1277);
67-
final mtv = Point(37.389444, -122.081944);
66+
final london = const Point(51.5073, -0.1277);
67+
final mtv = const Point(37.389444, -122.081944);
6868
final IssLocator locator = MockIssLocator();
6969
// London should not be visible from Mountain View.
7070
when(locator.currentPosition).thenReturn(london);

lib/src/builder.dart

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ import 'package:build/build.dart';
4242
import 'package:code_builder/code_builder.dart' hide refer;
4343
import 'package:collection/collection.dart';
4444
import 'package:dart_style/dart_style.dart';
45-
import 'package:mockito/annotations.dart';
46-
import 'package:mockito/src/version.dart';
4745
import 'package:path/path.dart' as p;
4846
import 'package:source_gen/source_gen.dart';
4947

48+
import '../annotations.dart';
49+
import 'version.dart';
50+
5051
/// For a source Dart library, generate the mocks referenced therein.
5152
///
5253
/// Given an input library, 'foo.dart', this builder will search the top-level
@@ -106,31 +107,33 @@ class MockBuilder implements Builder {
106107
// These comments are added after import directives; leading newlines
107108
// are necessary. Individual rules are still ignored to preserve backwards
108109
// compatibility with older versions of Dart.
109-
b.body.add(Code('\n\n// ignore_for_file: type=lint\n'));
110-
b.body.add(Code('// ignore_for_file: avoid_redundant_argument_values\n'));
110+
b.body.add(const Code('\n\n// ignore_for_file: type=lint\n'));
111+
b.body.add(
112+
const Code('// ignore_for_file: avoid_redundant_argument_values\n'));
111113
// We might generate a setter without a corresponding getter.
112-
b.body.add(Code('// ignore_for_file: avoid_setters_without_getters\n'));
114+
b.body.add(
115+
const Code('// ignore_for_file: avoid_setters_without_getters\n'));
113116
// We don't properly prefix imported class names in doc comments.
114-
b.body.add(Code('// ignore_for_file: comment_references\n'));
117+
b.body.add(const Code('// ignore_for_file: comment_references\n'));
115118
// We might import a deprecated library, or implement a deprecated class.
116-
b.body.add(Code('// ignore_for_file: deprecated_member_use\n'));
117-
b.body.add(Code(
119+
b.body.add(const Code('// ignore_for_file: deprecated_member_use\n'));
120+
b.body.add(const Code(
118121
'// ignore_for_file: deprecated_member_use_from_same_package\n'));
119122
// We might import a package's 'src' directory.
120-
b.body.add(Code('// ignore_for_file: implementation_imports\n'));
123+
b.body.add(const Code('// ignore_for_file: implementation_imports\n'));
121124
// `Mock.noSuchMethod` is `@visibleForTesting`, but the generated code is
122125
// not always in a test directory; the Mockito `example/iss` tests, for
123126
// example.
124-
b.body.add(Code(
127+
b.body.add(const Code(
125128
'// ignore_for_file: invalid_use_of_visible_for_testing_member\n'));
126-
b.body.add(Code('// ignore_for_file: must_be_immutable\n'));
127-
b.body.add(Code('// ignore_for_file: prefer_const_constructors\n'));
129+
b.body.add(const Code('// ignore_for_file: must_be_immutable\n'));
130+
b.body.add(const Code('// ignore_for_file: prefer_const_constructors\n'));
128131
// The code_builder `asA` API unconditionally adds defensive parentheses.
129-
b.body.add(Code('// ignore_for_file: unnecessary_parenthesis\n'));
132+
b.body.add(const Code('// ignore_for_file: unnecessary_parenthesis\n'));
130133
// The generator appends a suffix to fake classes
131-
b.body.add(Code('// ignore_for_file: camel_case_types\n'));
134+
b.body.add(const Code('// ignore_for_file: camel_case_types\n'));
132135
// The generator has to occasionally implement sealed classes
133-
b.body.add(Code('// ignore_for_file: subtype_of_sealed_class\n\n'));
136+
b.body.add(const Code('// ignore_for_file: subtype_of_sealed_class\n\n'));
134137
b.body.addAll(mockLibraryInfo.fakeClasses);
135138
b.body.addAll(mockLibraryInfo.mockClasses);
136139
});
@@ -329,8 +332,8 @@ class _TypeVisitor extends RecursiveElementVisitor<void> {
329332
if (!alreadyVisitedElement) {
330333
type.element.typeParameters.forEach(visitTypeParameterElement);
331334

332-
final toStringMethod =
333-
type.element.lookUpMethod('toString', type.element.library);
335+
final toStringMethod = type.element.augmented
336+
.lookUpMethod(name: 'toString', library: type.element.library);
334337
if (toStringMethod != null && toStringMethod.parameters.isNotEmpty) {
335338
// In a Fake class which implements a class which overrides `toString`
336339
// with additional (optional) parameters, we must also override
@@ -594,9 +597,7 @@ class _MockTargetGatherer {
594597
var type = _determineDartType(typeToMock, entryLib.typeProvider);
595598
final mockTypeArguments = mockType?.typeArguments;
596599
if (mockTypeArguments != null) {
597-
final typeName =
598-
type.alias?.element.getDisplayString(withNullability: false) ??
599-
'type $type';
600+
final typeName = type.alias?.element.getDisplayString() ?? 'type $type';
600601
final typeArguments = type.alias?.typeArguments ?? type.typeArguments;
601602
// Check explicit type arguments for unknown types that were
602603
// turned into `dynamic` by the analyzer.
@@ -1593,7 +1594,7 @@ class _MockClassInfo {
15931594
}
15941595
}
15951596
if (type.returnType is analyzer.VoidType) {
1596-
b.body = Code('');
1597+
b.body = const Code('');
15971598
} else {
15981599
b.body = _dummyValue(type.returnType, invocation).code;
15991600
}
@@ -1688,8 +1689,8 @@ class _MockClassInfo {
16881689
..initializers.add(refer('super')
16891690
.call([refer('parent'), refer('parentInvocation')]).code)));
16901691

1691-
final toStringMethod =
1692-
elementToFake.lookUpMethod('toString', elementToFake.library);
1692+
final toStringMethod = elementToFake.augmented
1693+
.lookUpMethod(name: 'toString', library: elementToFake.library);
16931694
if (toStringMethod != null && toStringMethod.parameters.isNotEmpty) {
16941695
// If [elementToFake] includes an overriding `toString` implementation,
16951696
// we need to include an implementation which matches the signature.
@@ -1849,7 +1850,7 @@ class _MockClassInfo {
18491850
// TODO(srawlins): It seems like this might be revivable, but Angular
18501851
// does not revive Types; we should investigate this if users request it.
18511852
final type = object.toTypeValue()!;
1852-
final typeStr = type.getDisplayString(withNullability: false);
1853+
final typeStr = type.getDisplayString();
18531854
throw _ReviveException('default value is a Type: $typeStr.');
18541855
} else {
18551856
// If [constant] is not null, a literal, or a type, then it must be an
@@ -2177,7 +2178,7 @@ class _MockClassInfo {
21772178
..isNullable = forceNullable || typeSystem.isNullable(type));
21782179
} else {
21792180
return referImported(
2180-
type.getDisplayString(withNullability: false),
2181+
type.getDisplayString(),
21812182
_typeImport(type.element),
21822183
);
21832184
}
@@ -2286,7 +2287,7 @@ class _AvoidConflictsAllocator implements Allocator {
22862287
/// A [MockBuilder] instance for use by `build.yaml`.
22872288
Builder buildMocks(BuilderOptions options) {
22882289
final buildExtensions = options.config['build_extensions'];
2289-
if (buildExtensions == null) return MockBuilder();
2290+
if (buildExtensions == null) return const MockBuilder();
22902291
if (buildExtensions is! Map) {
22912292
throw ArgumentError(
22922293
'build_extensions should be a map from inputs to outputs');

lib/src/dummies.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ List<Object?> _defaultDummies = [
134134
<Never>[],
135135
<Never>{},
136136
<Never, Never>{},
137-
Stream<Never>.empty(),
137+
const Stream<Never>.empty(),
138138
SplayTreeSet<Never>(),
139139
SplayTreeMap<Never, Never>(),
140140
];
@@ -155,6 +155,7 @@ T? dummyValueOrNull<T>(Object parent, Invocation invocation) {
155155
T dummyValue<T>(Object parent, Invocation invocation) {
156156
final value = dummyValueOrNull<T>(parent, invocation);
157157
if (value is T) return value;
158+
// ignore: only_throw_errors
158159
throw MissingDummyValueError(T);
159160
}
160161

lib/src/invocation_matcher.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import 'package:collection/collection.dart';
1616
import 'package:matcher/matcher.dart';
17-
import 'package:mockito/src/mock.dart';
17+
import 'mock.dart';
1818

1919
/// Returns a matcher that expects an invocation that matches arguments given.
2020
///
@@ -130,7 +130,7 @@ class _InvocationMatcher implements Matcher {
130130
// Specifically, if a Matcher is passed as an argument, we'd like to get an
131131
// error like "Expected fly(miles: > 10), Actual: fly(miles: 5)".
132132
@override
133-
Description describeMismatch(item, Description d, _, __) {
133+
Description describeMismatch(dynamic item, Description d, _, __) {
134134
if (item is Invocation) {
135135
d = d.add('Does not match ');
136136
return _describeInvocation(d, item);
@@ -139,7 +139,7 @@ class _InvocationMatcher implements Matcher {
139139
}
140140

141141
@override
142-
bool matches(item, _) =>
142+
bool matches(dynamic item, _) =>
143143
item is Invocation &&
144144
_invocation.memberName == item.memberName &&
145145
_invocation.isSetter == item.isSetter &&
@@ -156,7 +156,7 @@ class _MatcherEquality extends DeepCollectionEquality /* <Matcher | E> */ {
156156
const _MatcherEquality();
157157

158158
@override
159-
bool equals(e1, e2) {
159+
bool equals(Object? e1, Object? e2) {
160160
// All argument matches are wrapped in `ArgMatcher`, so we have to unwrap
161161
// them into the raw `Matcher` type in order to finish our equality checks.
162162
if (e1 is ArgMatcher) {

lib/src/mock.dart

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ import 'dart:collection';
2222

2323
import 'package:matcher/expect.dart';
2424
import 'package:meta/meta.dart';
25-
import 'package:mockito/src/call_pair.dart';
26-
import 'package:mockito/src/dummies.dart' show resetDummyBuilders;
27-
import 'package:mockito/src/invocation_matcher.dart';
2825
// ignore: deprecated_member_use
2926
import 'package:test_api/fake.dart';
3027

28+
import 'call_pair.dart';
29+
import 'dummies.dart' show resetDummyBuilders;
30+
import 'invocation_matcher.dart';
31+
3132
/// Whether a [when] call is "in progress."
3233
///
3334
/// Since [when] is a getter, this is `true` immediately after [when] returns,
@@ -195,7 +196,7 @@ mixin class Mock {
195196
int get hashCode => _givenHashCode ?? 0;
196197

197198
@override
198-
bool operator ==(other) => (_givenHashCode != null && other is Mock)
199+
bool operator ==(Object other) => (_givenHashCode != null && other is Mock)
199200
? _givenHashCode == other._givenHashCode
200201
: identical(this, other);
201202

@@ -392,8 +393,7 @@ class _InvocationForMatchedArguments extends Invocation {
392393
// by a stored value in [_storedNamedArgs].
393394
static Map<Symbol, dynamic> _reconstituteNamedArgs(Invocation invocation) {
394395
final namedArguments = <Symbol, dynamic>{};
395-
final storedNamedArgSymbols =
396-
_storedNamedArgs.keys.map((name) => Symbol(name));
396+
final storedNamedArgSymbols = _storedNamedArgs.keys.map(Symbol.new);
397397

398398
// Iterate through [invocation]'s named args, validate them, and add them
399399
// to the return map.
@@ -509,13 +509,13 @@ T named<T extends Mock>(T mock, {String? name, int? hashCode}) => mock
509509
.._givenHashCode = hashCode;
510510

511511
/// Clear stubs of, and collected interactions with [mock].
512-
void reset(var mock) {
512+
void reset(Mock mock) {
513513
mock._realCalls.clear();
514514
mock._responses.clear();
515515
}
516516

517517
/// Clear the collected interactions with [mock].
518-
void clearInteractions(var mock) {
518+
void clearInteractions(Mock mock) {
519519
mock._realCalls.clear();
520520
}
521521

@@ -557,6 +557,7 @@ class PostExpectation<T> {
557557
/// Store an exception to throw when this method stub is called.
558558
void thenThrow(Object throwable) {
559559
return _completeWhen((Invocation _) {
560+
// ignore: only_throw_errors
560561
throw throwable;
561562
});
562563
}
@@ -668,7 +669,7 @@ class InvocationMatcher {
668669
return true;
669670
}
670671

671-
bool isMatchingArg(roleArg, actArg) {
672+
bool isMatchingArg(dynamic roleArg, dynamic actArg) {
672673
if (roleArg is ArgMatcher) {
673674
return roleArg.matcher.matches(actArg, {});
674675
} else {
@@ -1133,6 +1134,7 @@ List<VerificationResult> Function<T>(List<T> recordedInvocations)
11331134
matchedCalls.add(matched.realCall);
11341135
verificationResults.add(VerificationResult._(1, matched.capturedArgs));
11351136
time = matched.realCall.timeStamp;
1137+
// ignore: avoid_catching_errors
11361138
} on StateError {
11371139
final mocks = tmpVerifyCalls.map((vc) => vc.mock).toSet();
11381140
final allInvocations =
@@ -1154,14 +1156,14 @@ List<VerificationResult> Function<T>(List<T> recordedInvocations)
11541156
};
11551157
}
11561158

1157-
void _throwMockArgumentError(String method, var nonMockInstance) {
1159+
void _throwMockArgumentError(String method, dynamic nonMockInstance) {
11581160
if (nonMockInstance == null) {
11591161
throw ArgumentError('$method was called with a null argument');
11601162
}
11611163
throw ArgumentError('$method must only be given a Mock object');
11621164
}
11631165

1164-
void verifyNoMoreInteractions(var mock) {
1166+
void verifyNoMoreInteractions(dynamic mock) {
11651167
if (mock is Mock) {
11661168
final unverified = mock._realCalls.where((inv) => !inv.verified).toList();
11671169
if (unverified.isNotEmpty) {
@@ -1172,7 +1174,7 @@ void verifyNoMoreInteractions(var mock) {
11721174
}
11731175
}
11741176

1175-
void verifyZeroInteractions(var mock) {
1177+
void verifyZeroInteractions(dynamic mock) {
11761178
if (mock is Mock) {
11771179
if (mock._realCalls.isNotEmpty) {
11781180
fail('No interaction expected, but following found: '

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dev_dependencies:
2424
build_runner: ^2.0.0
2525
build_test: ^2.0.0
2626
build_web_compilers: '>=3.0.0 <5.0.0'
27+
dart_flutter_team_lints: ^2.1.1
2728
http: ^1.0.0
28-
lints: ^3.0.0
2929
package_config: ^2.0.0
3030
test: ^1.16.0

0 commit comments

Comments
 (0)