Fix null_closures bug with Iterable.singleWhere (#1881)
* Fix null_closures bug with Iterable.singleWhere
* test
* Oops; code that parse
diff --git a/lib/src/rules/null_closures.dart b/lib/src/rules/null_closures.dart
index c149bc9..856b580 100644
--- a/lib/src/rules/null_closures.dart
+++ b/lib/src/rules/null_closures.dart
@@ -60,7 +60,8 @@
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
@@ -152,7 +153,7 @@
},
'singleWhere': {
NonNullableFunction('dart.core', 'Iterable', 'singleWhere',
- positional: [0]),
+ positional: [0], named: ['orElse']),
},
'skipWhile': {
NonNullableFunction('dart.core', 'Iterable', 'skipWhile', positional: [0]),
diff --git a/test/rules/null_closures.dart b/test/rules/null_closures.dart
index a66ce19..d1a5ac7 100644
--- a/test/rules/null_closures.dart
+++ b/test/rules/null_closures.dart
@@ -25,6 +25,12 @@
<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>{};