# oxc/double-comparisons

> Disallow two comparisons of the same values that one operator can express

`a === b || a < b` is a long way to write `a <= b`. Readers have to check that both halves compare the same two values before they can see what the condition means.

| Written | Means |
| --- | --- |
| `a == b \|\| a < b`, `a === b \|\| a < b` | `a <= b` |
| `a == b \|\| a > b`, `a === b \|\| a > b` | `a >= b` |
| `a < b \|\| a > b` | `a != b` |
| `a <= b && a >= b` | `a == b` |

The halves can be in either order, and one of them can be flipped, so `a < b || b < a` is reported too.

`--fix-suggestions` rewrites the condition with the single operator.

{/* 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]
"oxc/double-comparisons" = "error" # or "warn"
```

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

## Examples

Reported:

{/* bad {"count": 2} */}
```js
if (stock === minimum || stock < minimum) {
  reorder();
}

const changed = before < after || before > after;
```

Not reported:

{/* good */}
```js
if (stock <= minimum) {
  reorder();
}

const changed = before !== after;
```

## When not to use it

The short form doesn't always mean the same thing. `a < b || a > b` is `false` when one side is `NaN`, but `a != b` is `true`. For two `Date` objects, `a <= b && a >= b` compares the times, but `a == b` only tests whether they're the same object.
