Skip to content

unicorn/no-useless-fallback-in-spread Correctness

This rule is turned on by default.
🛠️ An auto-fix is available for this rule for some violations.

What it does

Disallow useless fallback when spreading in object literals.

Why is this bad?

Spreading falsy values in object literals won't add any unexpected properties, so it's unnecessary to add an empty object as fallback.

Examples

Examples of incorrect code for this rule:

javascript
const object = { ...(foo || {}) };

Examples of correct code for this rule:

javascript
const object = { ...foo };
const object = { ...(foo || { not: "empty" }) };

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny unicorn/no-useless-fallback-in-spread
json
{
  "rules": {
    "unicorn/no-useless-fallback-in-spread": "error"
  }
}

References

Released under the MIT License.