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.

Examples

Examples of incorrect code for this rule:

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

How to use

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

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

References

Released under the MIT License.