# 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.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

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

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
function isSameUser(user, other) {
  return user.id === user.id;
}
```

Not reported:

{/* good */}
```js
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:

{/* bad */}
```js
if (price !== price) {
  price = 0;
}
```

{/* good */}
```js
if (Number.isNaN(price)) {
  price = 0;
}
```
