Skip to content

Commit 0167449

Browse files
committed
Make pana happy
1 parent 8ca82ba commit 0167449

File tree

5 files changed

+54
-44
lines changed

5 files changed

+54
-44
lines changed

analysis_options.yaml

+11-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
include: package:lint/analysis_options.yaml
1+
include: package:lint/analysis_options_package.yaml
2+
3+
analyzer:
4+
strong-mode:
5+
implicit-casts: false
6+
7+
linter:
8+
rules:
9+
# Make pana happy
10+
prefer_single_quotes: true
11+
omit_local_variable_types: true

lib/src/iterable.dart

+27-27
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension IterableX<E> on Iterable<E> {
3535
/// ```
3636
E? elementAtOrNull(int index) {
3737
if (index < 0) return null;
38-
int count = 0;
38+
var count = 0;
3939
for (final element in this) {
4040
if (index == count++) return element;
4141
}
@@ -65,7 +65,7 @@ extension IterableX<E> on Iterable<E> {
6565
/// ```
6666
E elementAtOrElse(int index, E Function(int index) defaultValue) {
6767
if (index < 0) return defaultValue(index);
68-
int count = 0;
68+
var count = 0;
6969
for (final element in this) {
7070
if (index == count++) return element;
7171
}
@@ -148,8 +148,8 @@ extension IterableX<E> on Iterable<E> {
148148
/// If [end] is omitted, it is being set to `lastIndex`.
149149
List<E> slice(int start, [int end = -1]) {
150150
final list = this is List ? this as List<E> : toList();
151-
int _start = start;
152-
int _end = end;
151+
var _start = start;
152+
var _end = end;
153153

154154
if (_start < 0) {
155155
_start = _start + list.length;
@@ -166,7 +166,7 @@ extension IterableX<E> on Iterable<E> {
166166
/// Performs the given [action] on each element, providing sequential index
167167
/// with the element.
168168
void forEachIndexed(void Function(E element, int index) action) {
169-
int index = 0;
169+
var index = 0;
170170
for (final element in this) {
171171
action(element, index++);
172172
}
@@ -284,7 +284,7 @@ extension IterableX<E> on Iterable<E> {
284284
String truncated = '...',
285285
}) {
286286
final buffer = StringBuffer();
287-
int count = 0;
287+
var count = 0;
288288
for (final element in this) {
289289
if (limit != null && count >= limit) {
290290
buffer.write(truncated);
@@ -311,7 +311,7 @@ extension IterableX<E> on Iterable<E> {
311311
/// Returns the sum of all values produced by [selector] function applied to
312312
/// each element in the collection.
313313
double sumBy(num Function(E element) selector) {
314-
double sum = 0.0;
314+
var sum = 0.0;
315315
for (final current in this) {
316316
sum += selector(current);
317317
}
@@ -321,7 +321,7 @@ extension IterableX<E> on Iterable<E> {
321321
/// Returns the average of values returned by [selector] for all elements in
322322
/// the collection.
323323
double averageBy(num Function(E element) selector) {
324-
int count = 0;
324+
var count = 0;
325325
num sum = 0;
326326

327327
for (final current in this) {
@@ -367,7 +367,7 @@ extension IterableX<E> on Iterable<E> {
367367
if (!it.moveNext()) {
368368
return null;
369369
}
370-
E currentMin = it.current;
370+
var currentMin = it.current;
371371

372372
while (it.moveNext()) {
373373
if ((it.current as Comparable).compareTo(currentMin) == order) {
@@ -384,8 +384,8 @@ extension IterableX<E> on Iterable<E> {
384384
return null;
385385
}
386386

387-
E currentMin = it.current;
388-
Comparable currentMinValue = selector(it.current);
387+
var currentMin = it.current;
388+
var currentMinValue = selector(it.current);
389389
while (it.moveNext()) {
390390
final comp = selector(it.current);
391391
if (comp.compareTo(currentMinValue) == order) {
@@ -402,7 +402,7 @@ extension IterableX<E> on Iterable<E> {
402402
if (!it.moveNext()) {
403403
return null;
404404
}
405-
E currentMin = it.current;
405+
var currentMin = it.current;
406406

407407
while (it.moveNext()) {
408408
if (comparator(it.current, currentMin) == order) {
@@ -417,7 +417,7 @@ extension IterableX<E> on Iterable<E> {
417417
///
418418
/// If no [predicate] is given, this equals to [length].
419419
int count([bool Function(E element)? predicate]) {
420-
int count = 0;
420+
var count = 0;
421421
if (predicate == null) {
422422
return length;
423423
} else {
@@ -543,7 +543,7 @@ extension IterableX<E> on Iterable<E> {
543543
/// Returns all elements that satisfy the given [predicate].
544544
Iterable<E> whereIndexed(
545545
bool Function(E element, int index) predicate) sync* {
546-
int index = 0;
546+
var index = 0;
547547
for (final element in this) {
548548
if (predicate(element, index++)) {
549549
yield element;
@@ -565,7 +565,7 @@ extension IterableX<E> on Iterable<E> {
565565
/// [destination].
566566
void whereIndexedTo(
567567
List<E> destination, bool Function(E element, int index) predicate) {
568-
int index = 0;
568+
var index = 0;
569569
for (final element in this) {
570570
if (predicate(element, index++)) {
571571
destination.add(element);
@@ -585,7 +585,7 @@ extension IterableX<E> on Iterable<E> {
585585
/// Returns all elements not matching the given [predicate].
586586
Iterable<E> whereNotIndexed(
587587
bool Function(E element, int index) predicate) sync* {
588-
int index = 0;
588+
var index = 0;
589589
for (final element in this) {
590590
if (!predicate(element, index++)) {
591591
yield element;
@@ -607,7 +607,7 @@ extension IterableX<E> on Iterable<E> {
607607
/// [destination].
608608
void whereNotToIndexed(
609609
List<E> destination, bool Function(E element, int index) predicate) {
610-
int index = 0;
610+
var index = 0;
611611
for (final element in this) {
612612
if (!predicate(element, index++)) {
613613
destination.add(element);
@@ -634,7 +634,7 @@ extension IterableX<E> on Iterable<E> {
634634
/// given [transform] function to each element and its index in the original
635635
/// collection.
636636
Iterable<R> mapIndexed<R>(R Function(int index, E) transform) sync* {
637-
int index = 0;
637+
var index = 0;
638638
for (final element in this) {
639639
yield transform(index++, element);
640640
}
@@ -644,7 +644,7 @@ extension IterableX<E> on Iterable<E> {
644644
/// applying the given [transform] function to each element and its index
645645
/// in the original collection.
646646
Iterable<R> mapIndexedNotNull<R>(R? Function(int index, E) transform) sync* {
647-
int index = 0;
647+
var index = 0;
648648
for (final element in this) {
649649
final result = transform(index++, element);
650650
if (result != null) {
@@ -703,7 +703,7 @@ extension IterableX<E> on Iterable<E> {
703703
throw ArgumentError('Requested chunk size $size is less than one.');
704704
}
705705

706-
List<E> currentChunk = [];
706+
var currentChunk = <E>[];
707707
for (final current in this) {
708708
currentChunk.add(current);
709709
if (currentChunk.length >= size) {
@@ -731,8 +731,8 @@ extension IterableX<E> on Iterable<E> {
731731
/// See also:
732732
/// - [splitWhen], which works similarly but with a reverted [predicate].
733733
Iterable<List<E>> chunkWhile(bool Function(E, E) predicate) sync* {
734-
List<E> currentChunk = [];
735-
bool hasPrevious = false;
734+
var currentChunk = <E>[];
735+
var hasPrevious = false;
736736
late E previous;
737737

738738
for (final element in this) {
@@ -784,8 +784,8 @@ extension IterableX<E> on Iterable<E> {
784784
}) sync* {
785785
final gap = step - size;
786786
if (gap >= 0) {
787-
List<E> buffer = [];
788-
int skip = 0;
787+
var buffer = <E>[];
788+
var skip = 0;
789789
for (final element in this) {
790790
if (skip > 0) {
791791
skip -= 1;
@@ -794,7 +794,7 @@ extension IterableX<E> on Iterable<E> {
794794
buffer.add(element);
795795
if (buffer.length == size) {
796796
yield buffer;
797-
buffer = [];
797+
buffer = <E>[];
798798
skip = gap;
799799
}
800800
}
@@ -842,7 +842,7 @@ extension IterableX<E> on Iterable<E> {
842842
///
843843
/// If [n] is omitted, the Iterable cycles forever.
844844
Iterable<E> cycle([int? n]) sync* {
845-
Iterator<E> it = iterator;
845+
var it = iterator;
846846
if (!it.moveNext()) {
847847
return;
848848
}
@@ -855,7 +855,7 @@ extension IterableX<E> on Iterable<E> {
855855
it = iterator;
856856
}
857857
} else {
858-
int count = 0;
858+
var count = 0;
859859
yield it.current;
860860
while (count++ < n) {
861861
while (it.moveNext()) {

lib/src/list.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extension ListX<E> on List<E> {
2727
int get lastIndex => length - 1;
2828

2929
Iterable<int> get indices sync* {
30-
int index = 0;
30+
var index = 0;
3131
while (index <= lastIndex) {
3232
yield index++;
3333
}
@@ -50,7 +50,7 @@ extension ListX<E> on List<E> {
5050
/// satisfy the given [predicate].
5151
List<E> dropWhile(bool Function(E element) predicate) {
5252
int? startIndex;
53-
for (int i = 0; i < length; i++) {
53+
for (var i = 0; i < length; i++) {
5454
if (!predicate(this[i])) {
5555
startIndex = i;
5656
break;
@@ -77,7 +77,7 @@ extension ListX<E> on List<E> {
7777
/// satisfy the given [predicate].
7878
List<E> dropLastWhile(bool Function(E element) predicate) {
7979
int? endIndex;
80-
for (int i = lastIndex; i >= 0; i--) {
80+
for (var i = lastIndex; i >= 0; i--) {
8181
if (!predicate(this[i])) {
8282
endIndex = i;
8383
break;

lib/src/range.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class _IntRangeIterator extends Iterator<int> {
246246
}
247247

248248
final now = _current ?? first;
249-
int next = now;
249+
var next = now;
250250
if (_current != null) {
251251
assert(first != last);
252252
if (first <= last) {

test/iterable_test.dart

+12-12
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void main() {
145145
});
146146

147147
test('.forEachIndexed()', () {
148-
int index = 0;
148+
var index = 0;
149149
[6, 5, 4, 3, 2, 1, 0].forEachIndexed((it, i) {
150150
expect(it, 6 - index);
151151
expect(i, index);
@@ -352,7 +352,7 @@ void main() {
352352
});
353353

354354
test('.filterIndexed()', () {
355-
int index = 0;
355+
var index = 0;
356356
final result = [6, 5, 4, 3, 2, 1, 0].filterIndexed((it, i) {
357357
expect(it, 6 - index);
358358
expect(i, index);
@@ -369,7 +369,7 @@ void main() {
369369
});
370370

371371
test('.filterToIndexed()', () {
372-
int index = 0;
372+
var index = 0;
373373
final list = <int>[];
374374
[1, 2, 3, 4, 3, 2, 1].filterIndexedTo(list, (e, i) {
375375
expect(index++, i);
@@ -383,7 +383,7 @@ void main() {
383383
});
384384

385385
test('.filterNotIndexed()', () {
386-
int index = 0;
386+
var index = 0;
387387
expect(
388388
[1, 2, 3, 4, 3, 2, 1].filterNotIndexed((e, i) {
389389
expect(index++, i);
@@ -400,7 +400,7 @@ void main() {
400400
});
401401

402402
test('.filterToIndexed()', () {
403-
int index = 0;
403+
var index = 0;
404404
final list = <int>[];
405405
[1, 2, 3, 4, 3, 2, 1].filterNotToIndexed(list, (e, i) {
406406
expect(index++, i);
@@ -414,7 +414,7 @@ void main() {
414414
});
415415

416416
test('.whereIndexed()', () {
417-
int index = 0;
417+
var index = 0;
418418
final result = [6, 5, 4, 3, 2, 1, 0].whereIndexed((it, i) {
419419
expect(it, 6 - index);
420420
expect(i, index);
@@ -431,7 +431,7 @@ void main() {
431431
});
432432

433433
test('.whereToIndexed()', () {
434-
int index = 0;
434+
var index = 0;
435435
final list = <int>[];
436436
[1, 2, 3, 4, 3, 2, 1].whereIndexedTo(list, (e, i) {
437437
expect(index++, i);
@@ -445,7 +445,7 @@ void main() {
445445
});
446446

447447
test('.whereNotIndexed()', () {
448-
int index = 0;
448+
var index = 0;
449449
expect(
450450
[1, 2, 3, 4, 3, 2, 1].whereNotIndexed((e, i) {
451451
expect(index++, i);
@@ -462,7 +462,7 @@ void main() {
462462
});
463463

464464
test('.whereToIndexed()', () {
465-
int index = 0;
465+
var index = 0;
466466
final list = <int>[];
467467
[1, 2, 3, 4, 3, 2, 1].whereNotToIndexed(list, (e, i) {
468468
expect(index++, i);
@@ -908,7 +908,7 @@ void main() {
908908

909909
group('cached', () {
910910
test('does not re-evaluate elements when re-accessed', () {
911-
int accessCount = 0;
911+
var accessCount = 0;
912912
final iterable = [0, 1, 2].map((e) {
913913
accessCount++;
914914
return e;
@@ -921,7 +921,7 @@ void main() {
921921
expect(accessCount, 3);
922922
});
923923
test('concurrent access', () {
924-
int accessCount = 0;
924+
var accessCount = 0;
925925
final iterable = [0, 1, 2].map((e) {
926926
accessCount++;
927927
return e;
@@ -934,7 +934,7 @@ void main() {
934934
expect(accessCount, 3);
935935
});
936936
test('partial population', () {
937-
int accessCount = 0;
937+
var accessCount = 0;
938938
final iterable = [0, 1, 2].map((e) {
939939
accessCount++;
940940
return e;

0 commit comments

Comments
 (0)