Skip to content

eslint/no-self-compare Pedantic

What it does

Disallow comparisons where both sides are exactly the same

Why is this bad?

Comparing a variable against itself is usually an error, either a typo or refactoring error. It is confusing to the reader and may potentially introduce a runtime error.

Example

Examples of incorrect code for this rule:

javascript
var x = 10;
if (x === x) {
  x = 20;
}

How to use

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

bash
oxlint --deny no-self-compare
json
{
  "rules": {
    "no-self-compare": "error"
  }
}

References

Released under the MIT License.