unnecessary-to-list-in-spreads
Same as unnecessary_to_list_in_spreads in Dart lints
- Group
- Performance
- Path
lint/performance/unnecessary-to-list-in-spreads- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 476 of 512
Flags a .toList() call on the operand of a spread, e.g. ...x.toList().
A spread element accepts any iterable, so converting to a list first
allocates a throwaway List for no reason — spread the iterable directly.
The rule matches a no-argument .toList() call spread into a list, set, or
map literal, including null-aware spreads (...?x.toList()).
Invalid
void bad() {
var a = [...items.toList()];
var b = [1, ...more.toList()];
var c = <int>{...values.toList()};
var d = [...?maybe.toList()];
var e = [...first.toList(), ...second.toList()];
}void bad() { var a = [...items.toList()]; var a = [...items.toList()]; var b = [1, ...more.toList()]; var b = [1, ...more.toList()]; var c = <int>{...values.toList()}; var c = <int>{...values.toList()}; var d = [...?maybe.toList()]; var d = [...?maybe.toList()]; var e = [...first.toList(), ...second.toList()]; var d = [...?maybe.toList()]; var e = [...first.toList(), ...second.toList()];Valid
void good() {
var a = [...items];
var b = [1, ...more];
var c = <int>{...values};
var d = [...?maybe];
var e = [...items.map((e) => e * 2)];
var f = [items.toList()];
}Configure unnecessary-to-list-in-spreads
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"performance": {
"unnecessary-to-list-in-spreads": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/performance/unnecessary-to-list-in-spreads: <reason>More performance rules
- use-is-even-rather-than-modulo
use_is_even_rather_than_moduloPrefers
isEven/isOddto comparingx % 2with0or1. - use-string-buffers
use_string_buffersrecommendedPrefers a
StringBufferto growing aStringwith+inside a loop. - avoid-border-allflutter
Avoids Flutter's non-const
Border.allfactory. - avoid-shrink-wrap-in-listsflutter
Avoids shrink-wrapped Flutter lists nested in rows, columns, or other lists.
- avoid-slow-async-io
avoid_slow_async_ioAvoid the slow asynchronous
dart:iofile-system queries. - avoid-slow-collection-methods
Reports filtered iterable searches that have a direct search-method alternative.
- avoid-unnecessary-collections
Avoid singleton collection literals where SDK APIs accept a single value.
- avoid-unnecessary-consumer-widgetsriverpod
Flags Riverpod consumer widgets whose build reference is unused.