sindresorhus/eslint-plugin-unicorn

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

Fermée

#1 689 ouverte le 11 janv. 2022

 (1 commentaire) (2 réactions) (0 personne assignée)JavaScript (468 forks)user submission
enhancementhelp wanted

Métriques du dépôt

Stars
 (5 022 étoiles)
Métriques de merge PR
 (Merge moyen 1j 16h) (399 PRs mergées en 30 j)

Description

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.

Guide contributeur