sindresorhus/eslint-plugin-unicorn

Rule change proposal regarding `prefer-ternary`:

Closed

#1,620 opened on Nov 24, 2021

 (4 comments) (3 reactions) (0 assignees)JavaScript (468 forks)user submission
enhancementhelp wanted

Repository metrics

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

Description

Description

prefer-ternary currently only supports

'simple' if-else statements, where 'simple' means the consequent and alternate are each one line and have the same basic type and form.

Would it be possible to also detect the following example?:

Fail

const data = getData();
const defaultData = getDefaultData();

let items = defaultData;

if (data.length) {
    items = data;
}

Pass

const data = getData();
const defaultData = getDefaultData();

const items = data.length ? data : defaultData;

Contributor guide