Skip to content

avoid_empty_spread

v0.8.0 Warning Fix Collection Type

This rule flags a spread element whose operand is an empty collection literal — ...[], ...{}, ...<int>[].

Spreading an empty literal contributes nothing to the surrounding collection. It is dead syntax, usually left behind after a refactor removed the elements, or written as a placeholder that was never filled in.

Beyond the noise, it misleads: a reader scanning a widget’s children sees a spread and assumes something conditional is happening there.

Column(
children: [
const Header(),
// Contributes nothing
...[],
const Footer(),
],
)
Column(
children: [
const Header(),
const Footer(),
],
)

If the spread was a placeholder for conditional content, make the condition explicit:

Column(
children: [
const Header(),
if (showDetails) const Details(),
const Footer(),
],
)

Only literal empty collections are reported. A spread of a variable that happens to be empty at runtime (...items) is never flagged, since emptiness is not knowable at analysis time. Null-aware spreads of a variable (...?items) are likewise left alone.

This rule is in the recommended preset, so it is on with preset: recommended or preset: opinionated. Add it to preset: core with avoid_empty_spread: true.

To turn it off:

many_lints.yaml
rules:
avoid_empty_spread: false

To keep the rule on but skip certain paths, use per-rule exclude.