From 5753c4d10888d62d5e83215ce4863b2bee6e86f7 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Sun, 3 Nov 2019 14:54:49 -0800 Subject: [PATCH] Eliminate use of 'as' casts (#524) Also enables the avoid_as lint. --- analysis_options.yaml | 2 +- lib/src/async/stream_buffer.dart | 4 ++-- lib/src/collection/multimap.dart | 2 +- lib/src/collection/treeset.dart | 6 +++--- lib/testing/src/equality/equality.dart | 2 +- test/testing/equality/equality_test.dart | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 69e7dcdc..dfc5686d 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -25,7 +25,7 @@ linter: # ENABLE - always_specify_types # ENABLE - annotate_overrides # - avoid_annotating_with_dynamic # conflicts with always_specify_types - # ENABLE - avoid_as + - avoid_as # ENABLE - avoid_bool_literals_in_conditional_expressions # - avoid_catches_without_on_clauses # we do this commonly # - avoid_catching_errors # we do this commonly diff --git a/lib/src/async/stream_buffer.dart b/lib/src/async/stream_buffer.dart index 7d03b874..81a07455 100644 --- a/lib/src/async/stream_buffer.dart +++ b/lib/src/async/stream_buffer.dart @@ -91,7 +91,7 @@ class StreamBuffer implements StreamConsumer> { var subsize = leftToRead > listCap ? listCap : leftToRead; if (chunk is List) { ret.setRange(follower, follower + subsize, - (chunk as List).getRange(_offset, _offset + subsize)); + chunk.getRange(_offset, _offset + subsize)); } else { ret[follower] = chunk; } @@ -99,7 +99,7 @@ class StreamBuffer implements StreamConsumer> { _offset += subsize; _counter -= subsize; leftToRead -= subsize; - if (chunk is! List || _offset >= (chunk as List).length) { + if (!(chunk is List && _offset < chunk.length)) { _offset = 0; _chunks.removeAt(0); } diff --git a/lib/src/collection/multimap.dart b/lib/src/collection/multimap.dart index fe0e7434..d355278a 100644 --- a/lib/src/collection/multimap.dart +++ b/lib/src/collection/multimap.dart @@ -173,7 +173,7 @@ abstract class _BaseMultimap> retValues.addAll(values); values.clear(); } - return retValues as Iterable; + return retValues; } void clear() { diff --git a/lib/src/collection/treeset.dart b/lib/src/collection/treeset.dart index 42efccef..9e05cf8b 100644 --- a/lib/src/collection/treeset.dart +++ b/lib/src/collection/treeset.dart @@ -407,7 +407,7 @@ class AvlTreeSet extends TreeSet { bool remove(Object item) { if (item is! V) return false; - AvlNode x = _getNode(item as V); + AvlNode x = _getNode(item); if (x != null) { _removeNode(x); return true; @@ -652,7 +652,7 @@ class AvlTreeSet extends TreeSet { AvlNode x = _root; int compare = 0; while (x != null) { - compare = comparator(element as V, x.object); + compare = comparator(element, x.object); if (compare == 0) { return x.object; } else if (compare < 0) { @@ -730,7 +730,7 @@ class AvlTreeSet extends TreeSet { /// See [IterableBase.contains] bool contains(Object object) { - AvlNode x = _getNode(object as V); + AvlNode x = _getNode(object); return x != null; } diff --git a/lib/testing/src/equality/equality.dart b/lib/testing/src/equality/equality.dart index e67222ab..e88c9eca 100644 --- a/lib/testing/src/equality/equality.dart +++ b/lib/testing/src/equality/equality.dart @@ -63,7 +63,7 @@ class _EqualityGroupMatcher extends Matcher { @override bool matches(item, Map matchState) { try { - _verifyEqualityGroups(item as Map, matchState); + _verifyEqualityGroups(item, matchState); return true; } on MatchError catch (e) { matchState[failureReason] = e.toString(); diff --git a/test/testing/equality/equality_test.dart b/test/testing/equality/equality_test.dart index 84eb40d6..a1d30d54 100644 --- a/test/testing/equality/equality_test.dart +++ b/test/testing/equality/equality_test.dart @@ -294,7 +294,7 @@ class _ValidTestObject { if (!(o is _ValidTestObject)) { return false; } - _ValidTestObject other = o as _ValidTestObject; + final _ValidTestObject other = o; if (aspect1 != other.aspect1) { return false; } @@ -340,7 +340,7 @@ class _InconsistentHashCodeObject { if (!(o is _InconsistentHashCodeObject)) { return false; } - _InconsistentHashCodeObject other = o as _InconsistentHashCodeObject; + final _InconsistentHashCodeObject other = o; if (_aspect1 != other._aspect1) return false; if (_aspect2 != other._aspect2) return false; return true; @@ -364,7 +364,7 @@ class _InvalidHashCodeObject { if (!(o is _InvalidHashCodeObject)) { return false; } - _InvalidHashCodeObject other = o as _InvalidHashCodeObject; + final _InvalidHashCodeObject other = o; if (_aspect1 != other._aspect1) return false; if (_aspect2 != other._aspect2) return false; return true;