Skip to content

eslint/eqeqeq Pedantic

⚠️🛠️️ A dangerous auto-fix is available for this rule for some violations.

What it does

Requires the use of the === and !== operators.

Why is this bad?

Using non-strict equality operators leads to hard to track bugs due to type coercion.

Examples

Examples of incorrect code for this rule:

js
const a = [];
const b = true;
a == b;

The above will evaluate to true, but that is almost surely not what you want.

Examples of correct code for this rule:

js
const a = [];
const b = true;
a === b;

The above will evaluate to false (an array is not boolean true).

Options

null

json
  "eslint/eqeqeq": ["error", "always", {"null": "ignore"}]

Allow nullish comparison (foo == null). The alternative (foo === null || foo === undefined) is verbose and has no other benefit.

smart

json
  "eslint/eqeqeq": ["error", "smart"]

Allow == when comparing:

  • the result from typeof
  • literal values
  • nullish

Examples of incorrect code for this option:

js
a == b
[] == true

Examples of correct code for this option:

js
typeof foo == "undefined";
"foo" == "bar";
42 == 42;
foo == null;

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny eqeqeq
json
{
  "rules": {
    "eqeqeq": "error"
  }
}

References

Released under the MIT License.