Skip to content

Commit 347817c

Browse files
authored
Latest lints, require Dart 3.1, use mixin (dart-archive/collection#322)
1 parent c4c2563 commit 347817c

26 files changed

+143
-180
lines changed

pkgs/collection/.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
matrix:
4747
# Add macos-latest and/or windows-latest if relevant for this package.
4848
os: [ubuntu-latest]
49-
sdk: [2.18.0, dev]
49+
sdk: [3.1.0, dev]
5050
steps:
5151
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
5252
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d

pkgs/collection/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
- Adds `shuffled` to `IterableExtension`.
44
- Shuffle `IterableExtension.sample` results.
5+
- Require Dart `^3.1.0`
6+
- Mark "mixin" classes as `mixin`.
57

68
## 1.18.0
79

pkgs/collection/analysis_options.yaml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
1-
include: package:lints/recommended.yaml
1+
include: package:dart_flutter_team_lints/analysis_options.yaml
22

33
analyzer:
44
language:
55
strict-casts: true
66

77
linter:
88
rules:
9-
- always_declare_return_types
10-
- avoid_dynamic_calls
119
- avoid_unused_constructor_parameters
1210
- cancel_subscriptions
13-
- directives_ordering
14-
- lines_longer_than_80_chars
1511
- literal_only_boolean_expressions
1612
- missing_whitespace_between_adjacent_strings
1713
- no_adjacent_strings_in_list
1814
- no_runtimeType_toString
19-
- omit_local_variable_types
2015
- package_api_docs
21-
- prefer_relative_imports
22-
- prefer_single_quotes
23-
- test_types_in_equals
24-
- throw_in_finally
25-
- type_annotate_public_apis
26-
- unawaited_futures
2716
- unnecessary_await_in_return
28-
- unnecessary_lambdas
29-
- use_super_parameters

pkgs/collection/lib/algorithms.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
library dart.pkg.collection.algorithms;
88

99
export 'src/algorithms.dart'
10-
show binarySearch, insertionSort, lowerBound, mergeSort, shuffle, reverse;
10+
show binarySearch, insertionSort, lowerBound, mergeSort, reverse, shuffle;

pkgs/collection/lib/collection.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
export 'src/algorithms.dart'
6-
show binarySearch, insertionSort, lowerBound, mergeSort, shuffle, reverse;
6+
show binarySearch, insertionSort, lowerBound, mergeSort, reverse, shuffle;
77
export 'src/boollist.dart';
88
export 'src/canonicalized_map.dart';
99
export 'src/combined_wrappers/combined_iterable.dart';

pkgs/collection/lib/src/comparators.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int compareAsciiUpperCase(String a, String b) {
9999
bUpperCase -= _asciiCaseBit;
100100
}
101101
if (aUpperCase != bUpperCase) return (aUpperCase - bUpperCase).sign;
102-
if (defaultResult == 0) defaultResult = (aChar - bChar);
102+
if (defaultResult == 0) defaultResult = aChar - bChar;
103103
}
104104
if (b.length > a.length) return -1;
105105
return defaultResult.sign;

pkgs/collection/lib/src/empty_unmodifiable_set.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class EmptyUnmodifiableSet<E> extends IterableBase<E>
3434
E singleWhere(bool Function(E) test, {E Function()? orElse}) =>
3535
orElse != null ? orElse() : throw StateError('No element');
3636
@override
37-
Iterable<T> whereType<T>() => Iterable.empty();
37+
Iterable<T> whereType<T>() => Iterable<T>.empty();
3838
@override
3939
Set<E> toSet() => {};
4040
@override

pkgs/collection/lib/src/equality.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ class IterableEquality<E> implements Equality<Iterable<E>> {
138138
var c = _elementEquality.hash(element);
139139
hash = (hash + c) & _hashMask;
140140
hash = (hash + (hash << 10)) & _hashMask;
141-
hash ^= (hash >> 6);
141+
hash ^= hash >> 6;
142142
}
143143
hash = (hash + (hash << 3)) & _hashMask;
144-
hash ^= (hash >> 11);
144+
hash ^= hash >> 11;
145145
hash = (hash + (hash << 15)) & _hashMask;
146146
return hash;
147147
}
@@ -190,10 +190,10 @@ class ListEquality<E> implements Equality<List<E>> {
190190
var c = _elementEquality.hash(list[i]);
191191
hash = (hash + c) & _hashMask;
192192
hash = (hash + (hash << 10)) & _hashMask;
193-
hash ^= (hash >> 6);
193+
hash ^= hash >> 6;
194194
}
195195
hash = (hash + (hash << 3)) & _hashMask;
196-
hash ^= (hash >> 11);
196+
hash ^= hash >> 11;
197197
hash = (hash + (hash << 15)) & _hashMask;
198198
return hash;
199199
}
@@ -240,7 +240,7 @@ abstract class _UnorderedEquality<E, T extends Iterable<E>>
240240
hash = (hash + c) & _hashMask;
241241
}
242242
hash = (hash + (hash << 3)) & _hashMask;
243-
hash ^= (hash >> 11);
243+
hash ^= hash >> 11;
244244
hash = (hash + (hash << 15)) & _hashMask;
245245
return hash;
246246
}
@@ -349,7 +349,7 @@ class MapEquality<K, V> implements Equality<Map<K, V>> {
349349
hash = (hash + 3 * keyHash + 7 * valueHash) & _hashMask;
350350
}
351351
hash = (hash + (hash << 3)) & _hashMask;
352-
hash ^= (hash >> 11);
352+
hash ^= hash >> 11;
353353
hash = (hash + (hash << 15)) & _hashMask;
354354
return hash;
355355
}

pkgs/collection/lib/src/unmodifiable_wrappers.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class NonGrowableListView<E> extends DelegatingList<E>
2525

2626
/// Mixin class that implements a throwing version of all list operations that
2727
/// change the List's length.
28-
abstract class NonGrowableListMixin<E> implements List<E> {
28+
abstract mixin class NonGrowableListMixin<E> implements List<E> {
2929
static Never _throw() {
3030
throw UnsupportedError('Cannot change the length of a fixed-length list');
3131
}
@@ -116,7 +116,7 @@ class UnmodifiableSetView<E> extends DelegatingSet<E>
116116

117117
/// Mixin class that implements a throwing version of all set operations that
118118
/// change the Set.
119-
abstract /*mixin*/ class UnmodifiableSetMixin<E> implements Set<E> {
119+
abstract mixin class UnmodifiableSetMixin<E> implements Set<E> {
120120
static Never _throw() {
121121
throw UnsupportedError('Cannot modify an unmodifiable Set');
122122
}
@@ -164,7 +164,7 @@ abstract /*mixin*/ class UnmodifiableSetMixin<E> implements Set<E> {
164164

165165
/// Mixin class that implements a throwing version of all map operations that
166166
/// change the Map.
167-
abstract /*mixin*/ class UnmodifiableMapMixin<K, V> implements Map<K, V> {
167+
abstract mixin class UnmodifiableMapMixin<K, V> implements Map<K, V> {
168168
static Never _throw() {
169169
throw UnsupportedError('Cannot modify an unmodifiable Map');
170170
}

pkgs/collection/lib/src/wrappers.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ class MapValueSet<K, V> extends _DelegatingIterableBase<V> implements Set<V> {
793793

794794
@override
795795
void removeWhere(bool Function(V) test) {
796-
var toRemove = [];
796+
var toRemove = <K>[];
797797
_baseMap.forEach((key, value) {
798798
if (test(value)) toRemove.add(key);
799799
});
@@ -811,7 +811,7 @@ class MapValueSet<K, V> extends _DelegatingIterableBase<V> implements Set<V> {
811811
valuesToRetain.add(_baseMap[key] ?? null as V);
812812
}
813813

814-
var keysToRemove = [];
814+
var keysToRemove = <K>[];
815815
_baseMap.forEach((k, v) {
816816
if (!valuesToRetain.contains(v)) keysToRemove.add(k);
817817
});

pkgs/collection/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ topics:
99
- collections
1010

1111
environment:
12-
sdk: ">=2.18.0 <4.0.0"
12+
sdk: ^3.1.0
1313

1414
dev_dependencies:
15-
lints: ^2.0.1
15+
dart_flutter_team_lints: ^2.0.0
1616
test: ^1.16.0

pkgs/collection/test/algorithms_test.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
/// Tests algorithm utilities.
6+
library;
7+
68
import 'dart:math';
79

810
import 'package:collection/collection.dart';
@@ -13,7 +15,7 @@ void main() {
1315
void testShuffle(List list) {
1416
var copy = list.toList();
1517
shuffle(list);
16-
expect(UnorderedIterableEquality().equals(list, copy), isTrue);
18+
expect(const UnorderedIterableEquality().equals(list, copy), isTrue);
1719
}
1820

1921
test('Shuffle 0', () {
@@ -270,34 +272,34 @@ void main() {
270272
test('$name2: Same #$n', () {
271273
var list = List<OC>.generate(n, (i) => OC(i, 0));
272274
// Should succeed. Bad implementations of, e.g., quicksort can diverge.
273-
sort(list, ocOrder, compareInt);
275+
sort(list, _ocOrder, _compareInt);
274276
});
275277
test('$name: Pre-sorted #$n', () {
276278
var list = List<OC>.generate(n, (i) => OC(-i, i));
277279
var expected = list.toList();
278-
sort(list, ocOrder, compareInt);
280+
sort(list, _ocOrder, _compareInt);
279281
// Elements have not moved.
280282
expect(list, expected);
281283
});
282284
test('$name: Reverse-sorted #$n', () {
283285
var list = List<OC>.generate(n, (i) => OC(i, -i));
284-
sort(list, ocOrder, compareInt);
285-
expectSorted(list, ocOrder, compareInt);
286+
sort(list, _ocOrder, _compareInt);
287+
expectSorted(list, _ocOrder, _compareInt);
286288
});
287289
test('$name: Random #$n', () {
288290
var random = Random();
289291
var list = List<OC>.generate(n, (i) => OC(i, random.nextInt(n)));
290-
sort(list, ocOrder, compareInt);
291-
expectSorted(list, ocOrder, compareInt);
292+
sort(list, _ocOrder, _compareInt);
293+
expectSorted(list, _ocOrder, _compareInt);
292294
});
293295
test('$name: Sublist #$n', () {
294296
var random = Random();
295297
var list = List<OC>.generate(n, (i) => OC(i, random.nextInt(n)));
296298
var original = list.toList();
297299
var start = n ~/ 4;
298300
var end = start * 3;
299-
sort(list, ocOrder, compareInt, start, end);
300-
expectSorted(list, ocOrder, compareInt, start, end);
301+
sort(list, _ocOrder, _compareInt, start, end);
302+
expectSorted(list, _ocOrder, _compareInt, start, end);
301303
expect(list.sublist(0, start), original.sublist(0, start));
302304
expect(list.sublist(end), original.sublist(end));
303305
});
@@ -374,7 +376,6 @@ class C {
374376
}
375377

376378
int compareC(C one, C other) => one.id - other.id;
377-
int cId(C c) => c.id;
378379

379380
/// Class naturally ordered by its first constructor argument.
380381
class OC implements Comparable<OC> {
@@ -389,10 +390,9 @@ class OC implements Comparable<OC> {
389390
String toString() => 'OC[$id,$order]';
390391
}
391392

392-
int ocId(OC oc) => oc.id;
393-
int ocOrder(OC oc) => oc.order;
393+
int _ocOrder(OC oc) => oc.order;
394394

395-
int compareInt(int a, int b) => a - b;
395+
int _compareInt(int a, int b) => a - b;
396396

397397
/// Check that a list is sorted according to [compare] of [keyOf] of elements.
398398
void expectSorted<T, K>(

pkgs/collection/test/analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ include: ../analysis_options.yaml
44
analyzer:
55
errors:
66
avoid_dynamic_calls: ignore
7+
inference_failure_on_collection_literal: ignore
8+
inference_failure_on_instance_creation: ignore

pkgs/collection/test/boollist_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ void main() {
4444
var b = BoolList(1024, fill: false);
4545

4646
expect(() {
47+
// ignore: unnecessary_statements
4748
b[-1];
4849
}, throwsRangeError);
4950

5051
expect(() {
52+
// ignore: unnecessary_statements
5153
b[1024];
5254
}, throwsRangeError);
5355
});

pkgs/collection/test/canonicalized_map_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ void main() {
147147

148148
test('addEntries adds key-value pairs to the map', () {
149149
map.addEntries([
150-
MapEntry('1', 'value 1'),
151-
MapEntry('01', 'value 01'),
152-
MapEntry('2', 'value 2'),
150+
const MapEntry('1', 'value 1'),
151+
const MapEntry('01', 'value 01'),
152+
const MapEntry('2', 'value 2'),
153153
]);
154154
expect(map, {'01': 'value 01', '2': 'value 2'});
155155
});

pkgs/collection/test/combined_wrapper/iterable_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ void main() {
2222
});
2323

2424
test('should function as an empty iterable when no iterables are passed', () {
25-
var empty = CombinedIterableView([]);
25+
var empty = const CombinedIterableView([]);
2626
expect(empty, isEmpty);
2727
});
2828

2929
test('should function as an empty iterable with all empty iterables', () {
30-
var empty = CombinedIterableView([[], [], []]);
30+
var empty = const CombinedIterableView([[], [], []]);
3131
expect(empty, isEmpty);
3232
});
3333

pkgs/collection/test/combined_wrapper/map_test.dart

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import 'dart:collection';
77
import 'package:collection/collection.dart';
88
import 'package:test/test.dart';
99

10-
import '../unmodifiable_collection_test.dart' as common;
11-
1210
void main() {
1311
var map1 = const {1: 1, 2: 2, 3: 3};
1412
var map2 = const {4: 4, 5: 5, 6: 6};
@@ -24,10 +22,10 @@ void main() {
2422
..addAll(map3);
2523

2624
// In every way possible this should test the same as an UnmodifiableMapView.
27-
common.testReadMap(
25+
_testReadMap(
2826
concat, CombinedMapView([map1, map2, map3, map4]), 'CombinedMapView');
2927

30-
common.testReadMap(
28+
_testReadMap(
3129
concat,
3230
CombinedMapView([map1, {}, map2, {}, map3, {}, map4, {}]),
3331
'CombinedMapView (some empty)');
@@ -69,3 +67,52 @@ void main() {
6967
expect(keys.toList(), keys.toList());
7068
});
7169
}
70+
71+
void _testReadMap(Map<int, int> original, Map<int, int> wrapped, String name) {
72+
test('$name length', () {
73+
expect(wrapped.length, equals(original.length));
74+
});
75+
76+
test('$name isEmpty', () {
77+
expect(wrapped.isEmpty, equals(original.isEmpty));
78+
});
79+
80+
test('$name isNotEmpty', () {
81+
expect(wrapped.isNotEmpty, equals(original.isNotEmpty));
82+
});
83+
84+
test('$name operator[]', () {
85+
expect(wrapped[0], equals(original[0]));
86+
expect(wrapped[999], equals(original[999]));
87+
});
88+
89+
test('$name containsKey', () {
90+
expect(wrapped.containsKey(0), equals(original.containsKey(0)));
91+
expect(wrapped.containsKey(999), equals(original.containsKey(999)));
92+
});
93+
94+
test('$name containsValue', () {
95+
expect(wrapped.containsValue(0), equals(original.containsValue(0)));
96+
expect(wrapped.containsValue(999), equals(original.containsValue(999)));
97+
});
98+
99+
test('$name forEach', () {
100+
var origCnt = 0;
101+
var wrapCnt = 0;
102+
wrapped.forEach((k, v) {
103+
wrapCnt += 1 << k + 3 * v;
104+
});
105+
original.forEach((k, v) {
106+
origCnt += 1 << k + 3 * v;
107+
});
108+
expect(wrapCnt, equals(origCnt));
109+
});
110+
111+
test('$name keys', () {
112+
expect(wrapped.keys, orderedEquals(original.keys));
113+
});
114+
115+
test('$name values', () {
116+
expect(wrapped.values, orderedEquals(original.values));
117+
});
118+
}

0 commit comments

Comments
 (0)