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

Commit

Permalink
Migrate package to use lints package instead of pedantic package. (
Browse files Browse the repository at this point in the history
…#197)

Address all new warnings.
  • Loading branch information
lrhn authored Jun 25, 2021
1 parent ae0725c commit 04eb292
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 54 deletions.
10 changes: 1 addition & 9 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:pedantic/analysis_options.1.9.0.yaml
include: package:lints/recommended.yaml
analyzer:
errors:
unused_element: error
Expand All @@ -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
4 changes: 1 addition & 3 deletions lib/src/algorithms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ void mergeSort<E>(List<E> elements,
var secondLength = end - middle;
// secondLength is always the same as firstLength, or one greater.
var scratchSpace = List<E>.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);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/canonicalized_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CanonicalizedMap<C, K, V> implements Map<K, V> {
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
Expand Down Expand Up @@ -129,7 +129,7 @@ class CanonicalizedMap<C, K, V> implements Map<K, V> {
void removeWhere(bool Function(K key, V value) test) =>
_base.removeWhere((_, pair) => test(pair.key, pair.value));

@deprecated
@Deprecated("Use cast instead")
Map<K2, V2> retype<K2, V2>() => cast<K2, V2>();

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/empty_unmodifiable_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EmptyUnmodifiableSet<E> extends IterableBase<E>
Iterable<E> followedBy(Iterable<E> other) => DelegatingIterable(other);
@override
E? lookup(Object? element) => null;
@deprecated
@Deprecated("Use cast instead")
@override
EmptyUnmodifiableSet<T> retype<T>() => EmptyUnmodifiableSet<T>();
@override
Expand Down
36 changes: 18 additions & 18 deletions lib/src/equality.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<E> {
Expand Down Expand Up @@ -136,13 +136,13 @@ class IterableEquality<E> implements Equality<Iterable<E>> {
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;
}

Expand Down Expand Up @@ -188,13 +188,13 @@ class ListEquality<E> implements Equality<List<E>> {
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;
}

Expand Down Expand Up @@ -237,11 +237,11 @@ abstract class _UnorderedEquality<E, T extends Iterable<E>?>
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;
}
}
Expand Down Expand Up @@ -287,15 +287,15 @@ class SetEquality<E> extends _UnorderedEquality<E, Set<E>?> {
/// 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) =>
Expand Down Expand Up @@ -349,11 +349,11 @@ class MapEquality<K, V> implements Equality<Map<K, V>> {
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;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/iterable_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ extension IterableExtension<T> on Iterable<T> {
Map<K, Set<T>> groupSetsBy<K>(K Function(T element) keyOf) {
var result = <K, Set<T>>{};
for (var element in this) {
(result[keyOf(element)] ??= <T>{})..add(element);
(result[keyOf(element)] ??= <T>{}).add(element);
}
return result;
}
Expand All @@ -429,7 +429,7 @@ extension IterableExtension<T> on Iterable<T> {
Map<K, List<T>> groupListsBy<K>(K Function(T element) keyOf) {
var result = <K, List<T>>{};
for (var element in this) {
(result[keyOf(element)] ??= [])..add(element);
(result[keyOf(element)] ??= []).add(element);
}
return result;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/priority_queue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ class HeapPriorityQueue<E> implements PriorityQueue<E> {
///
/// 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<E> comparison;

/// List implementation of a heap.
List<E?> _queue = List<E?>.filled(_INITIAL_CAPACITY, null);
List<E?> _queue = List<E?>.filled(_initialCapacity, null);

/// Number of elements in queue.
///
Expand Down Expand Up @@ -451,7 +451,7 @@ class HeapPriorityQueue<E> implements PriorityQueue<E> {
/// 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<E?>.filled(newCapacity, null);
newQueue.setRange(0, _length, _queue);
_queue = newQueue;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/queue_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class QueueList<E> extends Object with ListMixin<E> implements Queue<E> {

QueueList<T> cast<T>() => QueueList._castFrom<E, T>(this);

@deprecated
@Deprecated("Use cast instead")
QueueList<T> retype<T>() => cast<T>();

@override
Expand Down
14 changes: 7 additions & 7 deletions lib/src/wrappers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ abstract class _DelegatingIterableBase<E> implements Iterable<E> {
@override
E reduce(E Function(E value, E element) combine) => _base.reduce(combine);

@deprecated
@Deprecated("Use cast instead")
Iterable<T> retype<T>() => cast<T>();

@override
Expand Down Expand Up @@ -278,7 +278,7 @@ class DelegatingList<E> extends _DelegatingIterableBase<E> implements List<E> {
_base.retainWhere(test);
}

@deprecated
@Deprecated("Use cast instead")
@override
List<T> retype<T>() => cast<T>();

Expand Down Expand Up @@ -379,7 +379,7 @@ class DelegatingSet<E> extends _DelegatingIterableBase<E> implements Set<E> {
_base.retainAll(elements);
}

@deprecated
@Deprecated("Use cast instead")
@override
Set<T> retype<T>() => cast<T>();

Expand Down Expand Up @@ -462,7 +462,7 @@ class DelegatingQueue<E> extends _DelegatingIterableBase<E>
_base.retainWhere(test);
}

@deprecated
@Deprecated("Use cast instead")
@override
Queue<T> retype<T>() => cast<T>();

Expand Down Expand Up @@ -563,7 +563,7 @@ class DelegatingMap<K, V> implements Map<K, V> {
@override
void removeWhere(bool Function(K, V) test) => _base.removeWhere(test);

@deprecated
@Deprecated("Use cast instead")
Map<K2, V2> retype<K2, V2>() => cast<K2, V2>();

@override
Expand Down Expand Up @@ -651,7 +651,7 @@ class MapKeySet<E> extends _DelegatingIterableBase<E>
E lookup(Object? element) =>
throw UnsupportedError("MapKeySet doesn't support lookup().");

@deprecated
@Deprecated("Use cast instead")
@override
Set<T> retype<T>() => Set.castFrom<E, T>(this);

Expand Down Expand Up @@ -822,7 +822,7 @@ class MapValueSet<K, V> extends _DelegatingIterableBase<V> implements Set<V> {
void retainWhere(bool Function(V) test) =>
removeWhere((element) => !test(element));

@deprecated
@Deprecated("Use cast instead")
@override
Set<T> retype<T>() => Set.castFrom<V, T>(this);

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/canonicalized_map_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void main() {
});

group('CanonicalizedMap builds an informative string representation', () {
var map;
dynamic map;
setUp(() {
map = CanonicalizedMap<int, String, dynamic>(int.parse,
isValidKey: RegExp(r'^\d+$').hasMatch);
Expand Down
2 changes: 1 addition & 1 deletion test/queue_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void main() {
});

group('throws a modification error for', () {
var queue;
dynamic queue;
setUp(() {
queue = QueueList.from([1, 2, 3]);
});
Expand Down
10 changes: 5 additions & 5 deletions test/union_set_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:test/test.dart';

void main() {
group('with an empty outer set', () {
var set;
dynamic set;
setUp(() {
set = UnionSet<int>({});
});
Expand Down Expand Up @@ -39,7 +39,7 @@ void main() {
});

group('with multiple disjoint sets', () {
var set;
dynamic set;
setUp(() {
set = UnionSet.from([
{1, 2},
Expand Down Expand Up @@ -78,7 +78,7 @@ void main() {
});

group('with multiple overlapping sets', () {
var set;
dynamic set;
setUp(() {
set = UnionSet.from([
{1, 2, 3},
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -175,7 +175,7 @@ void main() {
});

group('after the outer set was modified', () {
var set;
dynamic set;
setUp(() {
var innerSet = {6};
var outerSet = {
Expand Down
2 changes: 2 additions & 0 deletions test/unmodifiable_collection_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ void testIterable(Iterable<int> original, Iterable<int> 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;
});
Expand Down
1 change: 1 addition & 0 deletions test/wrapper_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class MapExpector<K, V> extends Expector implements Map<K, V> {
}

// 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;
Expand Down

0 comments on commit 04eb292

Please sign in to comment.