question-mark
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.

Enforce use of non-strict equality (`==`/`!=`) when comparing to `null`

See original GitHub issue

Right now I use eqeqeq to enforce strict (===) equality everywhere, except when comparing to null. That is great, but I actually want to go one step further and enforce non-strict (==) equality when comparing any value to null literal.

To put it another way, this will NOT currently throw any lint warning:

let foo;
console.log('is it null', foo == null);
console.log('is it really null', foo === null);

Those two statements are not easy to tell apart during code review. The issue can arise that a coder will use strict equality out of habit yet (in our codebase) they should always use loose equality when comparing to null in order to also catch undefined. Similar code will pass lint and pass tests and then later it might fail in production when undefined sneaks in somehow. I’d like to statically enforce loose equality for null.

Would you be open to a PR?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

7reactions
nzakascommented, Jun 28, 2016

I don’t think we should use “eqeq” in option names as it’s the opposite of the rule. “always” , “never”, etc. Should mean “always use ===” and “never use ===”.

It might be easiest to deprecate allow-null in favor of an options object:

eqeqeq: [error, always, {
    null: always | never | ignore
}]

Where “ignore” is equivalent to allow-null

1reaction
btmillscommented, Jul 8, 2016

@sstur Just checking in, how are things coming along? Is there anything I can do to help?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strict equality (===) - JavaScript - MDN Web Docs
The strict equality (===) operator checks whether its two operands are equal, ... operator attempts to convert them to the same type before...
Read more >
Which equals operator (== vs ===) should be used in ...
The == operator will compare for equality after doing any necessary type conversions. The === operator will not do the conversion, so if...
Read more >
When is it OK to use == in JavaScript? - 2ality
The “normal” (or lenient) equality operator == tries to convert values of different types, before comparing like strict equality.
Read more >
Truth, Equality and JavaScript
This is the formula JavaScript uses to classify values as truthy ( true , "potato" , 36 , [1,2,4] and {a:16} ) or...
Read more >
eqeqeq - ESLint - Pluggable JavaScript Linter
It is considered good practice to use the type-safe equality operators === and ... enforce strict equality except when comparing with the null...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found