avoid-unnecessary-collections
preset: recommended
Warns when a collection literal can be replaced by its first and only element.
Example
❌ Bad:
Future<void> fn() async {
await Future.wait([future]); // LINT
await Future.any([future]); // LINT
_array.addAll([value]); // LINT
_array.addAll({value}); // LINT
Stream.fromFutures([future]); // LINT
Stream.fromIterable([value]); // LINT
set.addAll([value]); // LINT
set.containsAll([value]); // LINT
}
✅ Good:
Future<void> fn() async {
await future;
_array.add(value);
Stream.fromFuture(future);
Stream.value(value);
set.add(value);
set.contains(value);
}