Enforce use of non-strict equality (`==`/`!=`) when comparing to `null`
See original GitHub issueRight 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:
- Created 7 years ago
- Reactions:1
- Comments:23 (23 by maintainers)
Top GitHub Comments
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:
Where “ignore” is equivalent to
allow-null
@sstur Just checking in, how are things coming along? Is there anything I can do to help?