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 合併指標
 (平均合併 4小時 30分鐘) (30 天內合併 26 個 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

貢獻者指南