sindresorhus/eslint-plugin-unicorn

Rule proposal: `no-unnecessary-negation`

已关闭

#856 创建于 2020年10月12日

 (20 条评论) (12 个反应) (0 位负责人)JavaScript (468 个派生)user submission
help wantednew rule

仓库指标

星标
 (5,022 个星标)
PR 合并指标
 (平均合并 4小时 30分钟) (30 天内合并 26 个 PR)

描述

Description

This rule would enforce users to simplify negations: !(a === b) -> a !== b. There might be other conditions like this that could be simplified.

Fail

if (!(a > b)) {}
const foo = !(bar === baz);
const foo = !(typeof bar === 'undefined');

Pass

if (a <= b) {}
const foo = bar !== baz;
const foo = typeof bar !== 'undefined';
const foo = !Array.isArray(bar);

贡献者指南