Rule proposal: `no-unnecessary-negation`
See original GitHub issueDescription
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);
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:19 (8 by maintainers)
Top Results From Across the Web
Rule proposal: no-unnecessary-falsy-condition · Issue #5592 - GitHub
My proposed rule identifies when there is a specific kind of overlap such that it is safe to shorten the code. My rule...
Read more >Statement on Proposed Rule Regarding Best Execution
If not, then given that government regulation typically imposes costs, and often has unintended negative consequences, we should be circumspect.
Read more >Electricians Proposed Administrative Rules
Section 90.4 of the 2020 NEC authorizes the Department to waive specific code requirements when doing so will not have a negative impact...
Read more >A Guide to the Rulemaking Process - Federal Register
Can an agency issue a final rule without a publishing a proposed rule? ... actions under consideration; it also states why the rule...
Read more >Rule 103. Rulings on Evidence | LII / Legal Information Institute
The subdivision answers in the negative. The judge can foreclose a particular line of testimony and counsel can protect his record without a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You have to be careful simplifying expressions with
-
and+
because of automatic type inference. There are edge cases wherea - -b
is not the same asa + b
The code is not in a presentable state, but it works 🎉
https://astexplorer.net/#/gist/c922ca1591e8db763030071c09df875a/3865211cf9b06a03034a0b199d0e65f6ff8f49c5
Please let me know when you find something that does not work as you expect and generally what you have tried out, so we can include that in our test cases.