consistent-conditional-object-spread
June 23, 2026 Β· View on GitHub
π Enforce consistent conditional object spread style.
πΌπ« This rule is enabled in the β
recommended config. This rule is disabled in the βοΈ unopinionated config.
π§ This rule is automatically fixable by the --fix CLI option.
When conditionally spreading properties into an object literal, pick one style consistently.
By default, this rule prefers && because it avoids an unnecessary empty object branch.
Examples
// β
const object = {...(condition ? {property} : {})};
// β
const object = {...(condition && {property})};
An undefined or null fallback branch spreads nothing, so it is treated the same as an empty object:
// β
const object = {...(condition ? {property} : undefined)};
// β
const object = {...(condition && {property})};
With the 'ternary' option:
// eslint unicorn/consistent-conditional-object-spread: ["error", "ternary"]
// β
const object = {...(condition && {property})};
// β
const object = {...(condition ? {property} : {})};
Options
Type: string
Default: 'logical'
Available options:
'logical'- Prefer...(condition && object).'ternary'- Prefer...(condition ? object : {}).