Skip to main content

avoid-empty-spread

added in: 1.15.0
🛠
Pro+
preset: recommended

Warns when a collection literal in spread (...[]) has no elements.

Example

❌ Bad:

void fn(bool flag) {
final another = [
...<String>[], // LINT: This spread has no elements. Try adding elements or removing it.
if (flag) ...<String>[], // LINT: This spread has no elements. Try adding elements or removing it.
];
}

✅ Good:

void fn(bool flag) {
final another = [
...<String>['some', 'elements'], // Correct, no empty spread
];
}

Additional Resources