sindresorhus/eslint-plugin-unicorn

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

已关闭

#1,689 创建于 2022年1月11日

 (1 条评论) (2 个反应) (0 位负责人)JavaScript (468 个派生)user submission
enhancementhelp wanted

仓库指标

星标
 (5,022 个星标)
PR 合并指标
 (平均合并 1天 16小时) (30 天内合并 399 个 PR)

描述

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.

贡献者指南