sindresorhus/eslint-plugin-unicorn

Report useless check when accessing array elements in `no-useless-undefined`

Chiusa

#1689 aperta il 11 gen 2022

 (1 commento) (2 reazioni) (0 assegnatari)JavaScript (468 fork)user submission
enhancementhelp wanted

Metriche repository

Star
 (5022 stelle)
Metriche merge PR
 (Merge medio 1g 16h) (399 PR mergiate in 30 g)

Descrizione

Fail

const foo = index >= 0 ? array[index] : undefined;
const foo = index < 0 ? undefined : array[index];
const foo = index <= array.length - 1 ? array[index] : undefined;
const foo = index > array.length - 1 ? undefined : array[index];
const foo = index >= 5 ? array[index - 5] : undefined;

Pass

const foo = array[index];
const foo = index >= 0 ? array[index] : bar;

I'm not sure if we should add this to no-useless-undefined or add a new rule.

Guida contributor