sindresorhus/eslint-plugin-unicorn

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

已关闭

#2,363 创建于 2024年5月21日

 (6 条评论) (3 个反应) (0 位负责人)JavaScript (468 个派生)user submission
help wantednew rule

仓库指标

星标
 (5,022 个星标)
PR 合并指标
 (平均合并 1天 16小时) (30 天内合并 399 个 PR)

描述

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

贡献者指南