Skip to content

Commit

Permalink
Make pana happy
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy committed Mar 1, 2021
1 parent 8ca82ba commit 0167449
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 44 deletions.
12 changes: 11 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
include: package:lint/analysis_options.yaml
include: package:lint/analysis_options_package.yaml

analyzer:
strong-mode:
implicit-casts: false

linter:
rules:
# Make pana happy
prefer_single_quotes: true
omit_local_variable_types: true
54 changes: 27 additions & 27 deletions lib/src/iterable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension IterableX<E> on Iterable<E> {
/// ```
E? elementAtOrNull(int index) {
if (index < 0) return null;
int count = 0;
var count = 0;
for (final element in this) {
if (index == count++) return element;
}
Expand Down Expand Up @@ -65,7 +65,7 @@ extension IterableX<E> on Iterable<E> {
/// ```
E elementAtOrElse(int index, E Function(int index) defaultValue) {
if (index < 0) return defaultValue(index);
int count = 0;
var count = 0;
for (final element in this) {
if (index == count++) return element;
}
Expand Down Expand Up @@ -148,8 +148,8 @@ extension IterableX<E> on Iterable<E> {
/// If [end] is omitted, it is being set to `lastIndex`.
List<E> slice(int start, [int end = -1]) {
final list = this is List ? this as List<E> : toList();
int _start = start;
int _end = end;
var _start = start;
var _end = end;

if (_start < 0) {
_start = _start + list.length;
Expand All @@ -166,7 +166,7 @@ extension IterableX<E> on Iterable<E> {
/// Performs the given [action] on each element, providing sequential index
/// with the element.
void forEachIndexed(void Function(E element, int index) action) {
int index = 0;
var index = 0;
for (final element in this) {
action(element, index++);
}
Expand Down Expand Up @@ -284,7 +284,7 @@ extension IterableX<E> on Iterable<E> {
String truncated = '...',
}) {
final buffer = StringBuffer();
int count = 0;
var count = 0;
for (final element in this) {
if (limit != null && count >= limit) {
buffer.write(truncated);
Expand All @@ -311,7 +311,7 @@ extension IterableX<E> on Iterable<E> {
/// Returns the sum of all values produced by [selector] function applied to
/// each element in the collection.
double sumBy(num Function(E element) selector) {
double sum = 0.0;
var sum = 0.0;
for (final current in this) {
sum += selector(current);
}
Expand All @@ -321,7 +321,7 @@ extension IterableX<E> on Iterable<E> {
/// Returns the average of values returned by [selector] for all elements in
/// the collection.
double averageBy(num Function(E element) selector) {
int count = 0;
var count = 0;
num sum = 0;

for (final current in this) {
Expand Down Expand Up @@ -367,7 +367,7 @@ extension IterableX<E> on Iterable<E> {
if (!it.moveNext()) {
return null;
}
E currentMin = it.current;
var currentMin = it.current;

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

E currentMin = it.current;
Comparable currentMinValue = selector(it.current);
var currentMin = it.current;
var currentMinValue = selector(it.current);
while (it.moveNext()) {
final comp = selector(it.current);
if (comp.compareTo(currentMinValue) == order) {
Expand All @@ -402,7 +402,7 @@ extension IterableX<E> on Iterable<E> {
if (!it.moveNext()) {
return null;
}
E currentMin = it.current;
var currentMin = it.current;

while (it.moveNext()) {
if (comparator(it.current, currentMin) == order) {
Expand All @@ -417,7 +417,7 @@ extension IterableX<E> on Iterable<E> {
///
/// If no [predicate] is given, this equals to [length].
int count([bool Function(E element)? predicate]) {
int count = 0;
var count = 0;
if (predicate == null) {
return length;
} else {
Expand Down Expand Up @@ -543,7 +543,7 @@ extension IterableX<E> on Iterable<E> {
/// Returns all elements that satisfy the given [predicate].
Iterable<E> whereIndexed(
bool Function(E element, int index) predicate) sync* {
int index = 0;
var index = 0;
for (final element in this) {
if (predicate(element, index++)) {
yield element;
Expand All @@ -565,7 +565,7 @@ extension IterableX<E> on Iterable<E> {
/// [destination].
void whereIndexedTo(
List<E> destination, bool Function(E element, int index) predicate) {
int index = 0;
var index = 0;
for (final element in this) {
if (predicate(element, index++)) {
destination.add(element);
Expand All @@ -585,7 +585,7 @@ extension IterableX<E> on Iterable<E> {
/// Returns all elements not matching the given [predicate].
Iterable<E> whereNotIndexed(
bool Function(E element, int index) predicate) sync* {
int index = 0;
var index = 0;
for (final element in this) {
if (!predicate(element, index++)) {
yield element;
Expand All @@ -607,7 +607,7 @@ extension IterableX<E> on Iterable<E> {
/// [destination].
void whereNotToIndexed(
List<E> destination, bool Function(E element, int index) predicate) {
int index = 0;
var index = 0;
for (final element in this) {
if (!predicate(element, index++)) {
destination.add(element);
Expand All @@ -634,7 +634,7 @@ extension IterableX<E> on Iterable<E> {
/// given [transform] function to each element and its index in the original
/// collection.
Iterable<R> mapIndexed<R>(R Function(int index, E) transform) sync* {
int index = 0;
var index = 0;
for (final element in this) {
yield transform(index++, element);
}
Expand All @@ -644,7 +644,7 @@ extension IterableX<E> on Iterable<E> {
/// applying the given [transform] function to each element and its index
/// in the original collection.
Iterable<R> mapIndexedNotNull<R>(R? Function(int index, E) transform) sync* {
int index = 0;
var index = 0;
for (final element in this) {
final result = transform(index++, element);
if (result != null) {
Expand Down Expand Up @@ -703,7 +703,7 @@ extension IterableX<E> on Iterable<E> {
throw ArgumentError('Requested chunk size $size is less than one.');
}

List<E> currentChunk = [];
var currentChunk = <E>[];
for (final current in this) {
currentChunk.add(current);
if (currentChunk.length >= size) {
Expand Down Expand Up @@ -731,8 +731,8 @@ extension IterableX<E> on Iterable<E> {
/// See also:
/// - [splitWhen], which works similarly but with a reverted [predicate].
Iterable<List<E>> chunkWhile(bool Function(E, E) predicate) sync* {
List<E> currentChunk = [];
bool hasPrevious = false;
var currentChunk = <E>[];
var hasPrevious = false;
late E previous;

for (final element in this) {
Expand Down Expand Up @@ -784,8 +784,8 @@ extension IterableX<E> on Iterable<E> {
}) sync* {
final gap = step - size;
if (gap >= 0) {
List<E> buffer = [];
int skip = 0;
var buffer = <E>[];
var skip = 0;
for (final element in this) {
if (skip > 0) {
skip -= 1;
Expand All @@ -794,7 +794,7 @@ extension IterableX<E> on Iterable<E> {
buffer.add(element);
if (buffer.length == size) {
yield buffer;
buffer = [];
buffer = <E>[];
skip = gap;
}
}
Expand Down Expand Up @@ -842,7 +842,7 @@ extension IterableX<E> on Iterable<E> {
///
/// If [n] is omitted, the Iterable cycles forever.
Iterable<E> cycle([int? n]) sync* {
Iterator<E> it = iterator;
var it = iterator;
if (!it.moveNext()) {
return;
}
Expand All @@ -855,7 +855,7 @@ extension IterableX<E> on Iterable<E> {
it = iterator;
}
} else {
int count = 0;
var count = 0;
yield it.current;
while (count++ < n) {
while (it.moveNext()) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension ListX<E> on List<E> {
int get lastIndex => length - 1;

Iterable<int> get indices sync* {
int index = 0;
var index = 0;
while (index <= lastIndex) {
yield index++;
}
Expand All @@ -50,7 +50,7 @@ extension ListX<E> on List<E> {
/// satisfy the given [predicate].
List<E> dropWhile(bool Function(E element) predicate) {
int? startIndex;
for (int i = 0; i < length; i++) {
for (var i = 0; i < length; i++) {
if (!predicate(this[i])) {
startIndex = i;
break;
Expand All @@ -77,7 +77,7 @@ extension ListX<E> on List<E> {
/// satisfy the given [predicate].
List<E> dropLastWhile(bool Function(E element) predicate) {
int? endIndex;
for (int i = lastIndex; i >= 0; i--) {
for (var i = lastIndex; i >= 0; i--) {
if (!predicate(this[i])) {
endIndex = i;
break;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/range.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class _IntRangeIterator extends Iterator<int> {
}

final now = _current ?? first;
int next = now;
var next = now;
if (_current != null) {
assert(first != last);
if (first <= last) {
Expand Down
24 changes: 12 additions & 12 deletions test/iterable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void main() {
});

test('.forEachIndexed()', () {
int index = 0;
var index = 0;
[6, 5, 4, 3, 2, 1, 0].forEachIndexed((it, i) {
expect(it, 6 - index);
expect(i, index);
Expand Down Expand Up @@ -352,7 +352,7 @@ void main() {
});

test('.filterIndexed()', () {
int index = 0;
var index = 0;
final result = [6, 5, 4, 3, 2, 1, 0].filterIndexed((it, i) {
expect(it, 6 - index);
expect(i, index);
Expand All @@ -369,7 +369,7 @@ void main() {
});

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

test('.filterNotIndexed()', () {
int index = 0;
var index = 0;
expect(
[1, 2, 3, 4, 3, 2, 1].filterNotIndexed((e, i) {
expect(index++, i);
Expand All @@ -400,7 +400,7 @@ void main() {
});

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

test('.whereIndexed()', () {
int index = 0;
var index = 0;
final result = [6, 5, 4, 3, 2, 1, 0].whereIndexed((it, i) {
expect(it, 6 - index);
expect(i, index);
Expand All @@ -431,7 +431,7 @@ void main() {
});

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

test('.whereNotIndexed()', () {
int index = 0;
var index = 0;
expect(
[1, 2, 3, 4, 3, 2, 1].whereNotIndexed((e, i) {
expect(index++, i);
Expand All @@ -462,7 +462,7 @@ void main() {
});

test('.whereToIndexed()', () {
int index = 0;
var index = 0;
final list = <int>[];
[1, 2, 3, 4, 3, 2, 1].whereNotToIndexed(list, (e, i) {
expect(index++, i);
Expand Down Expand Up @@ -908,7 +908,7 @@ void main() {

group('cached', () {
test('does not re-evaluate elements when re-accessed', () {
int accessCount = 0;
var accessCount = 0;
final iterable = [0, 1, 2].map((e) {
accessCount++;
return e;
Expand All @@ -921,7 +921,7 @@ void main() {
expect(accessCount, 3);
});
test('concurrent access', () {
int accessCount = 0;
var accessCount = 0;
final iterable = [0, 1, 2].map((e) {
accessCount++;
return e;
Expand All @@ -934,7 +934,7 @@ void main() {
expect(accessCount, 3);
});
test('partial population', () {
int accessCount = 0;
var accessCount = 0;
final iterable = [0, 1, 2].map((e) {
accessCount++;
return e;
Expand Down

0 comments on commit 0167449

Please sign in to comment.