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

Commit 477b950

Browse files
committed
cleanup: enable and fix a number of lints
1 parent b3292e2 commit 477b950

17 files changed

+161
-76
lines changed

analysis_options.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,78 @@
11
analyzer:
22
strong-mode: true
3+
errors:
4+
dead_code: error
5+
override_on_non_overriding_method: error
6+
unused_element: error
7+
unused_import: error
8+
unused_local_variable: error
9+
linter:
10+
rules:
11+
- always_declare_return_types
12+
#- annotate_overrides
13+
- avoid_empty_else
14+
- avoid_function_literals_in_foreach_calls
15+
- avoid_init_to_null
16+
- avoid_null_checks_in_equality_operators
17+
- avoid_renaming_method_parameters
18+
- avoid_return_types_on_setters
19+
- avoid_returning_null
20+
- avoid_types_as_parameter_names
21+
- avoid_unused_constructor_parameters
22+
- await_only_futures
23+
- camel_case_types
24+
- cancel_subscriptions
25+
#- cascade_invocations
26+
- comment_references
27+
- constant_identifier_names
28+
- control_flow_in_finally
29+
- directives_ordering
30+
- empty_catches
31+
- empty_constructor_bodies
32+
- empty_statements
33+
- hash_and_equals
34+
- implementation_imports
35+
- invariant_booleans
36+
- iterable_contains_unrelated_type
37+
- library_names
38+
- library_prefixes
39+
- list_remove_unrelated_type
40+
- literal_only_boolean_expressions
41+
- no_adjacent_strings_in_list
42+
- no_duplicate_case_values
43+
- non_constant_identifier_names
44+
- omit_local_variable_types
45+
- only_throw_errors
46+
- overridden_fields
47+
#- package_api_docs
48+
- package_names
49+
- package_prefixed_library_names
50+
- prefer_adjacent_string_concatenation
51+
- prefer_collection_literals
52+
- prefer_conditional_assignment
53+
- prefer_const_constructors
54+
- prefer_contains
55+
- prefer_equal_for_default_values
56+
- prefer_final_fields
57+
- prefer_initializing_formals
58+
#- prefer_interpolation_to_compose_strings
59+
- prefer_is_empty
60+
- prefer_is_not_empty
61+
#- prefer_single_quotes
62+
- prefer_typing_uninitialized_variables
63+
- recursive_getters
64+
- slash_for_doc_comments
65+
- super_goes_last
66+
- test_types_in_equals
67+
- throw_in_finally
68+
- type_init_formals
69+
- unawaited_futures
70+
- unnecessary_brace_in_string_interps
71+
- unnecessary_getters_setters
72+
- unnecessary_lambdas
73+
- unnecessary_null_aware_assignments
74+
- unnecessary_statements
75+
- unnecessary_this
76+
- unrelated_type_equality_checks
77+
- use_rethrow_when_possible
78+
- valid_regexps

lib/mirror_matchers.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class _HasProperty extends Matcher {
2929
addStateInfo(matchState, {'reason': 'has no property named "$_name"'});
3030
return false;
3131
}
32-
bool isInstanceField = candidate is VariableMirror && !candidate.isStatic;
33-
bool isInstanceGetter =
32+
var isInstanceField = candidate is VariableMirror && !candidate.isStatic;
33+
var isInstanceGetter =
3434
candidate is MethodMirror && candidate.isGetter && !candidate.isStatic;
3535
if (!(isInstanceField || isInstanceGetter)) {
3636
addStateInfo(matchState, {
@@ -60,14 +60,14 @@ class _HasProperty extends Matcher {
6060
item, Description mismatchDescription, Map matchState, bool verbose) {
6161
var reason = matchState == null ? null : matchState['reason'];
6262
if (reason != null) {
63-
mismatchDescription.add(reason);
63+
mismatchDescription.add(reason as String);
6464
} else {
6565
mismatchDescription
6666
.add('has property "$_name" with value ')
6767
.addDescriptionOf(matchState['value']);
6868
var innerDescription = new StringDescription();
69-
_matcher.describeMismatch(
70-
matchState['value'], innerDescription, matchState['state'], verbose);
69+
_matcher.describeMismatch(matchState['value'], innerDescription,
70+
matchState['state'] as Map, verbose);
7171
if (innerDescription.length > 0) {
7272
mismatchDescription.add(' which ').add(innerDescription.toString());
7373
}

lib/src/core_matchers.dart

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class _IsNotNaN extends Matcher {
8686
Matcher same(expected) => new _IsSameAs(expected);
8787

8888
class _IsSameAs extends Matcher {
89-
final _expected;
89+
final Object _expected;
9090
const _IsSameAs(this._expected);
9191
bool matches(item, Map matchState) => identical(item, _expected);
9292
// If all types were hashable we could show a hash here.
@@ -113,10 +113,11 @@ class _IsAnything extends Matcher {
113113
/// 'Foo', we would write:
114114
///
115115
/// expect(bar, new isInstanceOf<Foo>());
116+
// ignore: camel_case_types
116117
class isInstanceOf<T> extends Matcher {
117118
const isInstanceOf();
118119

119-
bool matches(obj, Map matchState) => obj is T;
120+
bool matches(item, Map matchState) => item is T;
120121

121122
Description describe(Description description) =>
122123
description.add('an instance of $T');
@@ -195,7 +196,7 @@ class _IsMap extends TypeMatcher {
195196
const Matcher isList = const _IsList();
196197

197198
class _IsList extends TypeMatcher {
198-
const _IsList() : super("List");
199+
const _IsList() : super('List');
199200
bool matches(item, Map matchState) => item is List;
200201
}
201202

@@ -205,7 +206,7 @@ Matcher hasLength(matcher) => new _HasLength(wrapMatcher(matcher));
205206

206207
class _HasLength extends Matcher {
207208
final Matcher _matcher;
208-
const _HasLength([Matcher matcher = null]) : this._matcher = matcher;
209+
const _HasLength([Matcher matcher]) : this._matcher = matcher;
209210

210211
bool matches(item, Map matchState) {
211212
try {
@@ -214,8 +215,10 @@ class _HasLength extends Matcher {
214215
if (item.length * item.length >= 0) {
215216
return _matcher.matches(item.length, matchState);
216217
}
217-
} catch (e) {}
218-
return false;
218+
} catch (e) {
219+
return false;
220+
}
221+
throw new UnsupportedError('Should never get here');
219222
}
220223

221224
Description describe(Description description) =>
@@ -231,8 +234,10 @@ class _HasLength extends Matcher {
231234
.add('has length of ')
232235
.addDescriptionOf(item.length);
233236
}
234-
} catch (e) {}
235-
return mismatchDescription.add('has no length property');
237+
} catch (e) {
238+
return mismatchDescription.add('has no length property');
239+
}
240+
throw new UnsupportedError('Should never get here');
236241
}
237242
}
238243

@@ -246,16 +251,16 @@ class _HasLength extends Matcher {
246251
Matcher contains(expected) => new _Contains(expected);
247252

248253
class _Contains extends Matcher {
249-
final _expected;
254+
final Object _expected;
250255

251256
const _Contains(this._expected);
252257

253258
bool matches(item, Map matchState) {
254259
if (item is String) {
255-
return item.indexOf(_expected) >= 0;
260+
return item.contains((_expected as Pattern));
256261
} else if (item is Iterable) {
257262
if (_expected is Matcher) {
258-
return item.any((e) => _expected.matches(e, matchState));
263+
return item.any((e) => (_expected as Matcher).matches(e, matchState));
259264
} else {
260265
return item.contains(_expected);
261266
}
@@ -284,17 +289,18 @@ class _Contains extends Matcher {
284289
Matcher isIn(expected) => new _In(expected);
285290

286291
class _In extends Matcher {
287-
final _expected;
292+
final Object _expected;
288293

289294
const _In(this._expected);
290295

291296
bool matches(item, Map matchState) {
292-
if (_expected is String) {
293-
return _expected.indexOf(item) >= 0;
294-
} else if (_expected is Iterable) {
295-
return _expected.any((e) => e == item);
296-
} else if (_expected is Map) {
297-
return _expected.containsKey(item);
297+
var expected = _expected;
298+
if (expected is String) {
299+
return expected.contains(item as Pattern);
300+
} else if (expected is Iterable) {
301+
return expected.contains(item);
302+
} else if (expected is Map) {
303+
return expected.containsKey(item);
298304
}
299305
return false;
300306
}

lib/src/custom_matcher.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CustomMatcher extends Matcher {
3939
: this._matcher = wrapMatcher(matcher);
4040

4141
/// Override this to extract the interesting feature.
42-
featureValueOf(actual) => actual;
42+
Object featureValueOf(actual) => actual;
4343

4444
bool matches(item, Map matchState) {
4545
try {
@@ -84,7 +84,7 @@ class CustomMatcher extends Matcher {
8484
var innerDescription = new StringDescription();
8585

8686
_matcher.describeMismatch(matchState['custom.feature'], innerDescription,
87-
matchState['state'], verbose);
87+
matchState['state'] as Map, verbose);
8888

8989
if (innerDescription.length > 0) {
9090
mismatchDescription.add(' which ').add(innerDescription.toString());

lib/src/equals_matcher.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'util.dart';
1616
/// handle cyclic structures a recursion depth [limit] can be provided. The
1717
/// default limit is 100. [Set]s will be compared order-independently.
1818
Matcher equals(expected, [int limit = 100]) => expected is String
19-
? new _StringEqualsMatcher(expected)
19+
? new _StringEqualsMatcher(expected) as Matcher
2020
: new _DeepMatcher(expected, limit);
2121

2222
typedef _RecursiveMatcher = List<String> Function(
@@ -44,7 +44,7 @@ class _StringEqualsMatcher extends Matcher {
4444
buff.write('is different.');
4545
var escapedItem = escape(item);
4646
var escapedValue = escape(_value);
47-
int minLength = escapedItem.length < escapedValue.length
47+
var minLength = escapedItem.length < escapedValue.length
4848
? escapedItem.length
4949
: escapedValue.length;
5050
var start = 0;
@@ -71,7 +71,7 @@ class _StringEqualsMatcher extends Matcher {
7171
_writeLeading(buff, escapedItem, start);
7272
_writeTrailing(buff, escapedItem, start);
7373
buff.write('\n ');
74-
for (int i = (start > 10 ? 14 : start); i > 0; i--) buff.write(' ');
74+
for (var i = (start > 10 ? 14 : start); i > 0; i--) buff.write(' ');
7575
buff.write('^\n Differ at offset $start');
7676
}
7777

@@ -99,7 +99,7 @@ class _StringEqualsMatcher extends Matcher {
9999
}
100100

101101
class _DeepMatcher extends Matcher {
102-
final _expected;
102+
final Object _expected;
103103
final int _limit;
104104

105105
_DeepMatcher(this._expected, [int limit = 1000]) : this._limit = limit;
@@ -136,7 +136,7 @@ class _DeepMatcher extends Matcher {
136136
List<String> _compareSets(Set expected, Object actual,
137137
_RecursiveMatcher matcher, int depth, String location) {
138138
if (actual is Iterable) {
139-
Set other = actual.toSet();
139+
var other = actual.toSet();
140140

141141
for (var expectedElement in expected) {
142142
if (other.every((actualElement) =>
@@ -235,8 +235,8 @@ class _DeepMatcher extends Matcher {
235235
var rp = _recursiveMatch(expected, actual, '', 0);
236236
if (rp == null) return null;
237237
String reason;
238-
if (rp[0].length > 0) {
239-
if (rp[1].length > 0) {
238+
if (rp[0].isNotEmpty) {
239+
if (rp[1].isNotEmpty) {
240240
reason = "${rp[0]} at location ${rp[1]}";
241241
} else {
242242
reason = rp[0];
@@ -257,12 +257,12 @@ class _DeepMatcher extends Matcher {
257257

258258
Description describeMismatch(
259259
item, Description mismatchDescription, Map matchState, bool verbose) {
260-
var reason = matchState['reason'] ?? '';
260+
var reason = matchState['reason'] as String ?? '';
261261
// If we didn't get a good reason, that would normally be a
262262
// simple 'is <value>' message. We only add that if the mismatch
263263
// description is non empty (so we are supplementing the mismatch
264264
// description).
265-
if (reason.length == 0 && mismatchDescription.length > 0) {
265+
if (reason.isEmpty && mismatchDescription.length > 0) {
266266
mismatchDescription.add('is ').addDescriptionOf(item);
267267
} else {
268268
mismatchDescription.add(reason);

lib/src/interfaces.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ abstract class Description {
2727
Description addAll(String start, String separator, String end, Iterable list);
2828
}
2929

30-
/// [expect] Matchers must implement/extend the Matcher class.
31-
///
3230
/// The base Matcher class has a generic implementation of [describeMismatch]
3331
/// so this does not need to be provided unless a more clear description is
3432
/// required. The other two methods ([matches] and [describe])

lib/src/iterable_matchers.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
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 'equals_matcher.dart';
65
import 'description.dart';
6+
import 'equals_matcher.dart';
77
import 'interfaces.dart';
88
import 'util.dart';
99

@@ -45,7 +45,7 @@ class _EveryElement extends _IterableMatcher {
4545
.add(' which ');
4646
var subDescription = new StringDescription();
4747
_matcher.describeMismatch(
48-
element, subDescription, matchState['state'], verbose);
48+
element, subDescription, matchState['state'] as Map, verbose);
4949
if (subDescription.length > 0) {
5050
mismatchDescription.add(subDescription.toString());
5151
} else {
@@ -159,10 +159,13 @@ class _UnorderedMatches extends Matcher {
159159
_allowUnmatchedValues = allowUnmatchedValues ?? false;
160160

161161
String _test(item) {
162-
if (item is! Iterable) return 'not iterable';
163-
164-
var values = item.toList();
162+
if (item is Iterable) {
163+
return _testCore(item.toList());
164+
}
165+
return 'not iterable';
166+
}
165167

168+
String _testCore(List values) {
166169
// Check the lengths are the same.
167170
if (_expected.length > values.length) {
168171
return 'has too few elements (${values.length} < ${_expected.length})';
@@ -172,8 +175,8 @@ class _UnorderedMatches extends Matcher {
172175

173176
var edges =
174177
new List.generate(values.length, (_) => <int>[], growable: false);
175-
for (int v = 0; v < values.length; v++) {
176-
for (int m = 0; m < _expected.length; m++) {
178+
for (var v = 0; v < values.length; v++) {
179+
for (var m = 0; m < _expected.length; m++) {
177180
if (_expected[m].matches(values[v], {})) {
178181
edges[v].add(m);
179182
}
@@ -182,10 +185,10 @@ class _UnorderedMatches extends Matcher {
182185
// The index into `values` matched with each matcher or `null` if no value
183186
// has been matched yet.
184187
var matched = new List<int>(_expected.length);
185-
for (int valueIndex = 0; valueIndex < values.length; valueIndex++) {
188+
for (var valueIndex = 0; valueIndex < values.length; valueIndex++) {
186189
_findPairing(edges, valueIndex, matched);
187190
}
188-
for (int matcherIndex = 0;
191+
for (var matcherIndex = 0;
189192
matcherIndex < _expected.length;
190193
matcherIndex++) {
191194
if (matched[matcherIndex] == null) {
@@ -216,10 +219,10 @@ class _UnorderedMatches extends Matcher {
216219
Map matchState, bool verbose) =>
217220
mismatchDescription.add(_test(item));
218221

219-
/// Returns [true] if the value at [valueIndex] can be paired with some
222+
/// Returns `true` if the value at [valueIndex] can be paired with some
220223
/// unmatched matcher and updates the state of [matched].
221224
///
222-
/// If there is a conflic where multiple values may match the same matcher
225+
/// If there is a conflict where multiple values may match the same matcher
223226
/// recursively looks for a new place to match the old value. [reserved]
224227
/// tracks the matchers that have been used _during_ this search.
225228
bool _findPairing(List<List<int>> edges, int valueIndex, List<int> matched,

0 commit comments

Comments
 (0)