Skip to content

noUselessFallbackInSpread (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noUselessFallbackInSpread": "error"
}
}
}
}

Disallow empty object fallbacks when spreading a value into an object.

Spreading null, undefined, or another falsy value (a value treated as false in a condition, such as false, 0, or "") into an object literal adds no properties. Writing {...(value || {})} or {...(value ?? {})} therefore gives the same result as {...value}, and the {} fallback only adds noise.

This doesn’t apply to arrays: spreading null or undefined into an array or a function call throws an error, so [...(value || [])] is allowed.

const object = { ...(options || {}) };
code-block.js:1:30 lint/nursery/noUselessFallbackInSpread  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This empty object fallback is unnecessary.

> 1 │ const object = { ...(options || {}) };
│ ^^^^^
2 │

ℹ Spreading null, undefined, or another falsy value such as false, 0, or "" into an object adds no properties, so the fallback has no effect.

ℹ Remove the fallback and spread the value directly.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Remove the empty object fallback.

1 │ const·object·=·{·...(options·||·{})·};
│ - -------
const object = { ...(options ?? {}) };
code-block.js:1:30 lint/nursery/noUselessFallbackInSpread  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This empty object fallback is unnecessary.

> 1 │ const object = { ...(options ?? {}) };
│ ^^^^^
2 │

ℹ Spreading null, undefined, or another falsy value such as false, 0, or "" into an object adds no properties, so the fallback has no effect.

ℹ Remove the fallback and spread the value directly.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Remove the empty object fallback.

1 │ const·object·=·{·...(options·??·{})·};
│ - -------
const object = { ...options };
const withDefaults = { ...(options || { verbose: true }) };
const conditional = { ...(enabled && {}) };
const array = [...(items || [])];