no-useless-fallback-in-spread
UnreleasedConfiguration
Rule Details
Disallow an empty object fallback in an object spread. Spreading undefined,
null, or another falsy value into an object adds no properties, so the
fallback is unnecessary.
Examples of incorrect code:
Examples of correct code:
Automatic Fixes
Fixes preserve the left operand and its comments. When removing the fallback would delete a comment, the rule reports the empty object without offering a fix.
Like upstream, this rule assumes falsy values have no enumerable properties.
Browser code that may spread document.all should disable the rule for that
expression: document.all is falsy but can have enumerable properties, so
removing its fallback can change the result.
Options
This rule has no options.
Differences from upstream
Fixes keep the parentheses required by JavaScript JSDoc @type assertions:
This preserves the assertion when checkJs or // @ts-check is enabled.
Unicorn v79.0.0 removes these parentheses, which can introduce a spread-type
error when value has type unknown.