Skip to content

Commit

Permalink
Fix null_closures bug with Iterable.singleWhere (dart-lang#1881)
Browse files Browse the repository at this point in the history
* Fix null_closures bug with Iterable.singleWhere

* test

* Oops; code that parse
  • Loading branch information
srawlins authored and pq committed Dec 11, 2019
1 parent 021be5f commit 2c23a08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/src/rules/null_closures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ in the following locations:
parameter `orElse`
* `Iterable.map` at the 0th positional parameter
* `Iterable.reduce` at the 0th positional parameter
* `Iterable.singleWhere` at the 0th positional parameter
* `Iterable.singleWhere` at the 0th positional parameter, and the named
parameter `orElse`
* `Iterable.skipWhile` at the 0th positional parameter
* `Iterable.takeWhile` at the 0th positional parameter
* `Iterable.where` at the 0th positional parameter
Expand Down Expand Up @@ -152,7 +153,7 @@ final Map<String, Set<NonNullableFunction>>
},
'singleWhere': {
NonNullableFunction('dart.core', 'Iterable', 'singleWhere',
positional: [0]),
positional: [0], named: ['orElse']),
},
'skipWhile': {
NonNullableFunction('dart.core', 'Iterable', 'skipWhile', positional: [0]),
Expand Down
6 changes: 6 additions & 0 deletions test/rules/null_closures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ void list_firstWhere() {
<int>[2, 4, 6].where((e) => e.isEven); // OK
}

void iterable_singleWhere() {
// singleWhere has a _named_ closure argument.
<int>{2, 4, 6}.singleWhere((e) => e.isEven, orElse: null); // LINT
<int>[2, 4, 6].singleWhere((e) => e.isEven, orElse: () => null); // OK
}

void map_putIfAbsent() {
// putIfAbsent has a _required_ closure argument.
var map = <int, int>{};
Expand Down

0 comments on commit 2c23a08

Please sign in to comment.