Linter · Rules
eqeqeq
Require === and !== instead of == and !=
== 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
Reported:
if (count == 0) {
reset();
}
Not reported:
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:
if (value == null) {
value = fallback;
}
And this is still reported:
if (value == other) {
merge(value, other);
}