no-self-compare

Disallow comparing a value with itself

user.id === user.id gives the same answer every time, so the condition around it doesn't test anything. It's almost always a typo for a comparison with another value.

The rule checks ==, ===, !=, !==, <, >, <= and >=, and reports when both sides are written the same way.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"no-self-compare" = "error" # or "warn"

Examples#

example.js1 problem
function isSameUser(user, other) {
  return user.id === user.id;
}
example.jsNo problems
function isSameUser(user, other) {
  return user.id === other.id;
}

value !== value is true only for NaN. It's reported too. Say what you mean instead:

example.js1 problem
if (price !== price) {
  price = 0;
}
example.jsNo problems
if (Number.isNaN(price)) {
  price = 0;
}