Check `!foo === bar` in `no-unsafe-negation` rule
See original GitHub issueWhat rule do you want to change?
Forbid use !foo === bar
and !foo !== bar
Does this change cause the rule to produce more or fewer warnings?
more
How will the change be implemented? (New option, new default behavior, etc.)?
Not sure
Please provide some example code that this change will affect:
if (!foo === bar);
What does the rule currently do for this code?
Nothing
What will the rule do after it’s changed?
Forbid it.
Are you willing to submit a pull request to implement this change?
Maybe.
I understand !foo === bar
maybe just coverting falsely value to compare to a boolean, but most time it’s a mistake,
I guess we should allow
// it's type-casting
if (!!foo === bar);
if (!(foo === bar));
if ((!foo) === bar);
I understand that stylistic rules are frozen, but still worth to make a proposal. I can understand if you decide not to accept.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:21 (18 by maintainers)
Top Results From Across the Web
Google Foobar Challenge. What You Should Know | by
Check that your imports are correct. The Foobar Challenge uses Java 8, which is pretty ancient. Check that you don't use any Java...
Read more >Rules - JavaScript Standard Style
This is a summary of the standard JavaScript rules. The best way to learn about standard is to just install it and give...
Read more >Rule overview - Deno
Deno supports the triple-slash reference directives of types , path , lib , and no-default-lib . This lint rule checks if there is...
Read more >The Foobar challenge: Google's hidden test for developers
by Daniel Simmons The Foobar challenge: Google's hidden test for developers You're just sitting at your desk, minding your own business, ...
Read more >Code Issues - Embold Help Center
We have discovered some checks and rules for C#. ... if a constructor Foo() calls a private method bar() that calls a public...
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
I agree with @nzakas on this.
!a in b
or!a < b
almost never make sense, but!a === b
is valid code ifb
is a boolean. Since we don’t have type info, an error reported on such code would be a false positive, or could be interpreted as stylistic enforcement which isn’t the intent of this rule.I was in favor of this option in
no-unsafe-negation
, but now I think that we should report!a === b
as a potential problem only if we’re sure that the right side is not a boolean, so this rather belongs tono-constant-binary-expression
rule (proposal https://github.com/eslint/eslint/issues/13752, there’s!foo == null
example in the original post), which will be based on determining types of the operands when possible. That would catch https://github.com/prettier/prettier/commit/c7e354e38cfd051d3f64b56aeda35e9a0a669de6#r47946398 as<boolean> === <string>
.@coderaiser Stop, please!