Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule suggestion: disallow !a instanceof b

See original GitHub issue

As the existing rule no-negated-in-lhs, it seems like it would be good to also disallow

if (!a instanceof b) // do something

since the developer certainly meant to write

if (!(a instanceof b)) // do something

instead. This prevents errors, and there’s no legitimate case for the former that I can think of, so I think this could be enabled by default as with no-negated-in-lhs. I’ve thrown together a quick copy and paste job of no-negated-in-lhs which works; will attach PR.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:36 (31 by maintainers)

github_iconTop GitHub Comments

mysticateacommented, Jul 28, 2016

@nzakas I think this is a rule to prevent enough common problem and this is accepted.

Accepted issues are good start points for new contributors, but until now, rule’s deprecation process is not clear; I guess it was a barrier to contributing to this issue. Just now, we are making some rules deprecated. I think we can go to advance this as well. (I can work on this later)

nzakascommented, Nov 30, 2015

For this, we are strictly talking about using ! with in and instanceof, though. I’m not sure it makes sense to extend the rule further than that.

I’m still thinking that no-unsafe-negation is clearest for this use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-unsafe-negation - ESLint - Pluggable JavaScript Linter
This rule disallows negating the left operand of the following relational operators: in operator. instanceof operator. Examples of incorrect code for this rule:....
Read more >
How to avoid 'instanceof' when implementing factory design ...
From what I've read on Stack Overflow, using 'instanceof' is a code smell. Is there a better way to check the type of...
Read more >
False-Positive of rule "Expressions should not be too complex ...
In my opinion the rule “squid:S1067: Expressions should not be too complex” creates a false-positive in case of just multiple instanceof ...
Read more >
Pattern matching for instanceof (Preview)
A variable of an interface type can hold a null reference or a reference to an instance of any class that implements the...
Read more >
Java instanceof and Clean architecture
The problem is the use of instanceof in the save method of EntityRepository . If we want to prevent using instanceof, one solution...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found