sindresorhus/eslint-plugin-unicorn
Rule proposal: `no-unnecessary-negation`
Closed
#856 opened on Oct 12, 2020
help wantednew rule
Repository metrics
- Stars
- (5,022 stars)
- PR merge metrics
- (Avg merge 1d 16h) (399 merged PRs in 30d)
Description
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);