no-eq-null
Disallow comparing with null using == or !=
value == null is true for null and also for undefined. If you meant only null, the check lets undefined through. If you meant both, the next reader can't tell that from the code.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"no-eq-null" = "error" # or "warn"Examples#
example.js2 problems
if (user == nullUse === to compare with null.) {
redirect("/login");
}
while (node != nullUse === to compare with null.) {
node = node.next;
}example.jsNo problems
if (user === null) {
redirect("/login");
}
if (session === null || session === undefined) {
redirect("/login");
}When not to use it#
== null is a common shorthand for testing for null and undefined at once. If your code does that on purpose, leave this rule off. eqeqeq with the "smart" option allows == null and still reports value == other.