eqeqeq
Require === and !== instead of == and !=
fixable
== and != convert their operands before comparing them, so "" == 0 and [] == false are both true. === and !== compare without converting.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"eqeqeq" = "error" # or "warn"Every option, set to its default:
bunfig.toml
[lint.rules]
"eqeqeq" = [
"error",
"always", # "always", "smart" or "allow-null"
{
null = "always", # "always", "never" or "ignore"
},
]Examples#
example.js1 problem
if (count ==Expected === and instead saw ==. 0) {
reset();
}example.jsNo problems
if (count === 0) {
reset();
}Options#
bunfig.toml
[lint.rules]
eqeqeq = ["error", "smart"]| Option | What it does |
|---|---|
"always" (default) | Report every == and !=. |
"smart" | Allow == when comparing with null, comparing two literals, or comparing the result of typeof. |
With "always", a second option decides what happens with null: { "null": "always" } (default) reports x == null, "ignore" allows it, and "never" reports x === null instead.
With "smart", this is allowed, because == null is a common way to test for both null and undefined:
example.jswith
"smart"No problemsif (value == null) {
value = fallback;
}And this is still reported:
example.jswith
"smart"1 problemif (value ==Expected === and instead saw ==. other) {
merge(value, other);
}