sindresorhus/eslint-plugin-unicorn

Rule proposal: `consistent-conditional-object-spread`

Closed

#2,363 opened on May 21, 2024

 (6 comments) (3 reactions) (0 assignees)JavaScript (468 forks)user submission
help wantednew rule

Repository metrics

Stars
 (5,022 stars)
PR merge metrics
 (Avg merge 1d 16h) (399 merged PRs in 30d)

Description

Description

When spreading an object conditionally, we have two style: ? : and &&. I prefer user consistently to use &&.

Pass

const name = Math.random() > 0.5 'foo' : undefined;
const student = {age: 12, ...(name&&{name})};

Fail

const name = Math.random() > 0.5 'foo' : undefined;
const student = {age: 12, ...(name ? {name} : {})};

Proposed rule name

consistent-conditional-object-spread

Additional Info

No response

Contributor guide