eslint/eqeqeq Pedantic
What it does β
Requires the use of the === and !== operators, disallowing the use of == and !=.
Why is this bad? β
Using non-strict equality operators leads to unexpected behavior due to type coercion, which can cause hard-to-find bugs.
Examples β
Example JSON configuration:
{
"eqeqeq": ["error", "always", { "null": "ignore" }]
}"always" (default) β
Examples of incorrect code for this rule:
/* eqeqeq: "error" */
if (x == 42) {
}
if ("" == text) {
}
if (obj.getStuff() != undefined) {
}Examples of correct code for this rule:
/* eqeqeq: "error" */
if (x === 42) {
}
if ("" === text) {
}
if (obj.getStuff() !== undefined) {
}"smart" β
Examples of incorrect code for this rule with the "smart" option:
/* eqeqeq: ["error", "smart"] */
if (x == 42) {
}
if ("" == text) {
}Examples of correct code for this rule with the "smart" option:
/* eqeqeq: ["error", "smart"] */
if (typeof foo == "undefined") {
}
if (foo == null) {
}
if (foo != null) {
}{"null": "ignore"} (with "always" first option) β
Examples of incorrect code for this rule with the { "null": "ignore" } option:
/* eqeqeq: ["error", "always", { "null": "ignore" }] */
if (x == 42) {
}
if ("" == text) {
}Examples of correct code for this rule with the { "null": "ignore" } option:
/* eqeqeq: ["error", "always", { "null": "ignore" }] */
if (foo == null) {
}
if (foo != null) {
}{"null": "always"} (default - with "always" first option) β
Examples of incorrect code for this rule with the { "null": "always" } option:
/* eqeqeq: ["error", "always", { "null": "always" }] */
if (foo == null) {
}
if (foo != null) {
}Examples of correct code for this rule with the { "null": "always" } option:
/* eqeqeq: ["error", "always", { "null": "always" }] */
if (foo === null) {
}
if (foo !== null) {
}{"null": "never"} (with "always" first option) β
Examples of incorrect code for this rule with the { "null": "never" } option:
/* eqeqeq: ["error", "always", { "null": "never" }] */
if (x == 42) {
}
if ("" == text) {
}
if (foo === null) {
}
if (foo !== null) {
}Examples of correct code for this rule with the { "null": "never" } option:
/* eqeqeq: ["error", "always", { "null": "never" }] */
if (x === 42) {
}
if ("" === text) {
}
if (foo == null) {
}
if (foo != null) {
}Configuration β
The 1st option β
type: "always" | "smart"
"always" β
Always require triple-equal comparisons, ===/!==. This is the default.
"smart" β
Allow certain safe comparisons to use ==/!= (typeof, literals, nullish).
The 2nd option β
This option is an object with the following properties:
null β
type: "always" | "never" | "ignore"
"always" β
Always require triple-equals when comparing with null, === null/!== null. This is the default.
"never" β
Never require triple-equals when comparing with null, always use == null/!= null.
"ignore" β
Ignore null comparisons, allow either == null/!= null or === null/!== null.
How to use β
To enable this rule using the config file or in the CLI, you can use:
{
"rules": {
"eqeqeq": "error"
}
}oxlint --deny eqeqeq