# no-subtraction-comparison

Rule `unicorn/no-subtraction-comparison`. Prefer comparing values directly over subtracting and comparing to `0`.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 40.5M weekly downloads of presets that enable it
- Trend: +81.2% last quarter
- Rank: #434 by reach, #426 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/no-subtraction-comparison` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/no-subtraction-comparison.md) |
| Biome | `nursery/noSubtractionComparison` | yes | unsafe | group nursery, since 2.6.6 | [docs](https://biomejs.dev/linter/rules/no-subtraction-comparison/) |

## Code examples

### Incorrect: the rule reports this

```js
if (a - b > 0) {}
```

```js
if (a - b <= 0) {}
```

```js
if (0 < a - b) {}
```

### Correct: the rule accepts this

```js
if (a > b) {}
```

```js
if (a <= b) {}
```

```js
if (a > b) {}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/no-subtraction-comparison": "error",
    },
  },
];
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "noSubtractionComparison": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Biome recommended](https://lintradar.dev/presets/biome-recommended.md) | Biome | `@biomejs/biome` | 491 | 28.5M | +106.8% |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/no-negated-array-predicate](https://lintradar.dev/rules/unicorn/no-negated-array-predicate.md): Disallow negated array predicate calls.
- [unicorn/no-unnecessary-nested-ternary](https://lintradar.dev/rules/unicorn/no-unnecessary-nested-ternary.md): Disallow unnecessary nested ternary expressions.
- [unicorn/no-for-each](https://lintradar.dev/rules/unicorn/no-for-each.md): Prefer `for…of` over the `forEach` method.
- [unicorn/no-unnecessary-string-trim](https://lintradar.dev/rules/unicorn/no-unnecessary-string-trim.md): Disallow `String#trim()` before `String#startsWith()` or `String#endsWith()`.
- [unicorn/no-double-comparison](https://lintradar.dev/rules/unicorn/no-double-comparison.md): Disallow two comparisons of the same operands that can be combined into one.
- [unicorn/no-useless-set-construction](https://lintradar.dev/rules/unicorn/no-useless-set-construction.md): Disallow unnecessary `Set` construction around `Set` methods.

---

Web page: https://lintradar.dev/rules/unicorn/no-subtraction-comparison. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
