sindresorhus/eslint-plugin-unicorn
Report useless check when accessing array elements in `no-useless-undefined`
Geschlossen
#1.689 geöffnet am 11.01.2022
enhancementhelp wanted
Repository-Metriken
- Stars
- (5.022 Sterne)
- PR-Merge-Metriken
- (Durchschn. Merge 1T 16h) (399 gemergte PRs in 30 T)
Beschreibung
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.