diff --git a/analysis_options.yaml b/analysis_options.yaml index 483d38f..72e4a38 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,4 +1,4 @@ -include: package:pedantic/analysis_options.1.9.0.yaml +include: package:lints/recommended.yaml analyzer: errors: unused_element: error @@ -8,18 +8,10 @@ analyzer: linter: rules: # Errors - - control_flow_in_finally - - empty_statements - - hash_and_equals - - implementation_imports - test_types_in_equals - throw_in_finally # Style - avoid_private_typedef_functions - - avoid_renaming_method_parameters - - await_only_futures - - camel_case_types - directives_ordering - - non_constant_identifier_names - only_throw_errors diff --git a/lib/src/algorithms.dart b/lib/src/algorithms.dart index d589e1e..820d32b 100644 --- a/lib/src/algorithms.dart +++ b/lib/src/algorithms.dart @@ -227,9 +227,7 @@ void mergeSort(List elements, var secondLength = end - middle; // secondLength is always the same as firstLength, or one greater. var scratchSpace = List.filled(secondLength, elements[start]); - // TODO(linter/2097): Remove ignore when no longer required by linter. - // See: https://github.com/dart-lang/linter/issues/2097 - E Function(E) id = identity; // ignore: omit_local_variable_types + E Function(E) id = identity; _mergeSort(elements, id, compare, middle, end, scratchSpace, 0); var firstTarget = end - firstLength; _mergeSort(elements, id, compare, start, middle, elements, firstTarget); diff --git a/lib/src/canonicalized_map.dart b/lib/src/canonicalized_map.dart index 5f97b25..de63908 100644 --- a/lib/src/canonicalized_map.dart +++ b/lib/src/canonicalized_map.dart @@ -50,7 +50,7 @@ class CanonicalizedMap implements Map { V? operator [](Object? key) { if (!_isValidKey(key)) return null; var pair = _base[_canonicalize(key as K)]; - return pair == null ? null : pair.value; + return pair?.value; } @override @@ -129,7 +129,7 @@ class CanonicalizedMap implements Map { void removeWhere(bool Function(K key, V value) test) => _base.removeWhere((_, pair) => test(pair.key, pair.value)); - @deprecated + @Deprecated("Use cast instead") Map retype() => cast(); @override diff --git a/lib/src/empty_unmodifiable_set.dart b/lib/src/empty_unmodifiable_set.dart index 725dfc0..76f9f22 100644 --- a/lib/src/empty_unmodifiable_set.dart +++ b/lib/src/empty_unmodifiable_set.dart @@ -27,7 +27,7 @@ class EmptyUnmodifiableSet extends IterableBase Iterable followedBy(Iterable other) => DelegatingIterable(other); @override E? lookup(Object? element) => null; - @deprecated + @Deprecated("Use cast instead") @override EmptyUnmodifiableSet retype() => EmptyUnmodifiableSet(); @override diff --git a/lib/src/equality.dart b/lib/src/equality.dart index eba3841..a6b464f 100644 --- a/lib/src/equality.dart +++ b/lib/src/equality.dart @@ -6,7 +6,7 @@ import 'dart:collection'; import 'comparators.dart'; -const int _HASH_MASK = 0x7fffffff; +const int _hashMask = 0x7fffffff; /// A generic equality relation on objects. abstract class Equality { @@ -136,13 +136,13 @@ class IterableEquality implements Equality> { var hash = 0; for (var element in elements) { var c = _elementEquality.hash(element); - hash = (hash + c) & _HASH_MASK; - hash = (hash + (hash << 10)) & _HASH_MASK; + hash = (hash + c) & _hashMask; + hash = (hash + (hash << 10)) & _hashMask; hash ^= (hash >> 6); } - hash = (hash + (hash << 3)) & _HASH_MASK; + hash = (hash + (hash << 3)) & _hashMask; hash ^= (hash >> 11); - hash = (hash + (hash << 15)) & _HASH_MASK; + hash = (hash + (hash << 15)) & _hashMask; return hash; } @@ -188,13 +188,13 @@ class ListEquality implements Equality> { var hash = 0; for (var i = 0; i < list.length; i++) { var c = _elementEquality.hash(list[i]); - hash = (hash + c) & _HASH_MASK; - hash = (hash + (hash << 10)) & _HASH_MASK; + hash = (hash + c) & _hashMask; + hash = (hash + (hash << 10)) & _hashMask; hash ^= (hash >> 6); } - hash = (hash + (hash << 3)) & _HASH_MASK; + hash = (hash + (hash << 3)) & _hashMask; hash ^= (hash >> 11); - hash = (hash + (hash << 15)) & _HASH_MASK; + hash = (hash + (hash << 15)) & _hashMask; return hash; } @@ -237,11 +237,11 @@ abstract class _UnorderedEquality?> var hash = 0; for (E element in elements) { var c = _elementEquality.hash(element); - hash = (hash + c) & _HASH_MASK; + hash = (hash + c) & _hashMask; } - hash = (hash + (hash << 3)) & _HASH_MASK; + hash = (hash + (hash << 3)) & _hashMask; hash ^= (hash >> 11); - hash = (hash + (hash << 15)) & _HASH_MASK; + hash = (hash + (hash << 15)) & _hashMask; return hash; } } @@ -287,15 +287,15 @@ class SetEquality extends _UnorderedEquality?> { /// using a combined hashCode and equality of the key and value. class _MapEntry { final MapEquality equality; - final key; - final value; + final Object? key; + final Object? value; _MapEntry(this.equality, this.key, this.value); @override int get hashCode => (3 * equality._keyEquality.hash(key) + 7 * equality._valueEquality.hash(value)) & - _HASH_MASK; + _hashMask; @override bool operator ==(Object other) => @@ -349,11 +349,11 @@ class MapEquality implements Equality> { for (var key in map.keys) { var keyHash = _keyEquality.hash(key); var valueHash = _valueEquality.hash(map[key] as V); - hash = (hash + 3 * keyHash + 7 * valueHash) & _HASH_MASK; + hash = (hash + 3 * keyHash + 7 * valueHash) & _hashMask; } - hash = (hash + (hash << 3)) & _HASH_MASK; + hash = (hash + (hash << 3)) & _hashMask; hash ^= (hash >> 11); - hash = (hash + (hash << 15)) & _HASH_MASK; + hash = (hash + (hash << 15)) & _hashMask; return hash; } diff --git a/lib/src/iterable_extensions.dart b/lib/src/iterable_extensions.dart index 1c82bc4..7bb4e22 100644 --- a/lib/src/iterable_extensions.dart +++ b/lib/src/iterable_extensions.dart @@ -420,7 +420,7 @@ extension IterableExtension on Iterable { Map> groupSetsBy(K Function(T element) keyOf) { var result = >{}; for (var element in this) { - (result[keyOf(element)] ??= {})..add(element); + (result[keyOf(element)] ??= {}).add(element); } return result; } @@ -429,7 +429,7 @@ extension IterableExtension on Iterable { Map> groupListsBy(K Function(T element) keyOf) { var result = >{}; for (var element in this) { - (result[keyOf(element)] ??= [])..add(element); + (result[keyOf(element)] ??= []).add(element); } return result; } diff --git a/lib/src/priority_queue.dart b/lib/src/priority_queue.dart index 345d6f7..ae4ee9a 100644 --- a/lib/src/priority_queue.dart +++ b/lib/src/priority_queue.dart @@ -174,13 +174,13 @@ class HeapPriorityQueue implements PriorityQueue { /// /// Number can be any positive value. Picking a size that gives a whole /// number of "tree levels" in the heap is only done for aesthetic reasons. - static const int _INITIAL_CAPACITY = 7; + static const int _initialCapacity = 7; /// The comparison being used to compare the priority of elements. final Comparator comparison; /// List implementation of a heap. - List _queue = List.filled(_INITIAL_CAPACITY, null); + List _queue = List.filled(_initialCapacity, null); /// Number of elements in queue. /// @@ -451,7 +451,7 @@ class HeapPriorityQueue implements PriorityQueue { /// Called when the list is full. void _grow() { var newCapacity = _queue.length * 2 + 1; - if (newCapacity < _INITIAL_CAPACITY) newCapacity = _INITIAL_CAPACITY; + if (newCapacity < _initialCapacity) newCapacity = _initialCapacity; var newQueue = List.filled(newCapacity, null); newQueue.setRange(0, _length, _queue); _queue = newQueue; diff --git a/lib/src/queue_list.dart b/lib/src/queue_list.dart index 3bf13f2..f013723 100644 --- a/lib/src/queue_list.dart +++ b/lib/src/queue_list.dart @@ -115,7 +115,7 @@ class QueueList extends Object with ListMixin implements Queue { QueueList cast() => QueueList._castFrom(this); - @deprecated + @Deprecated("Use cast instead") QueueList retype() => cast(); @override diff --git a/lib/src/wrappers.dart b/lib/src/wrappers.dart index b5b61e3..e380350 100644 --- a/lib/src/wrappers.dart +++ b/lib/src/wrappers.dart @@ -79,7 +79,7 @@ abstract class _DelegatingIterableBase implements Iterable { @override E reduce(E Function(E value, E element) combine) => _base.reduce(combine); - @deprecated + @Deprecated("Use cast instead") Iterable retype() => cast(); @override @@ -278,7 +278,7 @@ class DelegatingList extends _DelegatingIterableBase implements List { _base.retainWhere(test); } - @deprecated + @Deprecated("Use cast instead") @override List retype() => cast(); @@ -379,7 +379,7 @@ class DelegatingSet extends _DelegatingIterableBase implements Set { _base.retainAll(elements); } - @deprecated + @Deprecated("Use cast instead") @override Set retype() => cast(); @@ -462,7 +462,7 @@ class DelegatingQueue extends _DelegatingIterableBase _base.retainWhere(test); } - @deprecated + @Deprecated("Use cast instead") @override Queue retype() => cast(); @@ -563,7 +563,7 @@ class DelegatingMap implements Map { @override void removeWhere(bool Function(K, V) test) => _base.removeWhere(test); - @deprecated + @Deprecated("Use cast instead") Map retype() => cast(); @override @@ -651,7 +651,7 @@ class MapKeySet extends _DelegatingIterableBase E lookup(Object? element) => throw UnsupportedError("MapKeySet doesn't support lookup()."); - @deprecated + @Deprecated("Use cast instead") @override Set retype() => Set.castFrom(this); @@ -822,7 +822,7 @@ class MapValueSet extends _DelegatingIterableBase implements Set { void retainWhere(bool Function(V) test) => removeWhere((element) => !test(element)); - @deprecated + @Deprecated("Use cast instead") @override Set retype() => Set.castFrom(this); diff --git a/pubspec.yaml b/pubspec.yaml index c8a468e..74f5bc3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,5 +8,5 @@ environment: sdk: ">=2.12.0 <3.0.0" dev_dependencies: - pedantic: ^1.10.0-nullsafety + lints: ^1.0.0 test: ^1.16.0-nullsafety diff --git a/test/canonicalized_map_test.dart b/test/canonicalized_map_test.dart index e5bd34e..dad9c87 100644 --- a/test/canonicalized_map_test.dart +++ b/test/canonicalized_map_test.dart @@ -160,7 +160,7 @@ void main() { }); group('CanonicalizedMap builds an informative string representation', () { - var map; + dynamic map; setUp(() { map = CanonicalizedMap(int.parse, isValidKey: RegExp(r'^\d+$').hasMatch); diff --git a/test/queue_list_test.dart b/test/queue_list_test.dart index 21b6056..57644da 100644 --- a/test/queue_list_test.dart +++ b/test/queue_list_test.dart @@ -219,7 +219,7 @@ void main() { }); group('throws a modification error for', () { - var queue; + dynamic queue; setUp(() { queue = QueueList.from([1, 2, 3]); }); diff --git a/test/union_set_test.dart b/test/union_set_test.dart index fe9e204..d8897a4 100644 --- a/test/union_set_test.dart +++ b/test/union_set_test.dart @@ -7,7 +7,7 @@ import 'package:test/test.dart'; void main() { group('with an empty outer set', () { - var set; + dynamic set; setUp(() { set = UnionSet({}); }); @@ -39,7 +39,7 @@ void main() { }); group('with multiple disjoint sets', () { - var set; + dynamic set; setUp(() { set = UnionSet.from([ {1, 2}, @@ -78,7 +78,7 @@ void main() { }); group('with multiple overlapping sets', () { - var set; + dynamic set; setUp(() { set = UnionSet.from([ {1, 2, 3}, @@ -131,7 +131,7 @@ void main() { }); group('after an inner set was modified', () { - var set; + dynamic set; setUp(() { var innerSet = {3, 7}; set = UnionSet.from([ @@ -175,7 +175,7 @@ void main() { }); group('after the outer set was modified', () { - var set; + dynamic set; setUp(() { var innerSet = {6}; var outerSet = { diff --git a/test/unmodifiable_collection_test.dart b/test/unmodifiable_collection_test.dart index 1eaed3f..a0cb89c 100644 --- a/test/unmodifiable_collection_test.dart +++ b/test/unmodifiable_collection_test.dart @@ -123,9 +123,11 @@ void testIterable(Iterable original, Iterable wrapped, String name) { test('$name - forEach', () { var wrapCtr = 0; var origCtr = 0; + // ignore: avoid_function_literals_in_foreach_calls wrapped.forEach((x) { wrapCtr += x; }); + // ignore: avoid_function_literals_in_foreach_calls original.forEach((x) { origCtr += x; }); diff --git a/test/wrapper_test.dart b/test/wrapper_test.dart index f31499b..00a2ccb 100644 --- a/test/wrapper_test.dart +++ b/test/wrapper_test.dart @@ -161,6 +161,7 @@ class MapExpector extends Expector implements Map { } // Utility values to use as arguments in calls. +// ignore: prefer_void_to_null Null func0() => null; dynamic func1(dynamic x) => null; dynamic func2(dynamic x, dynamic y) => null;