# prefer-comparison-matcher

Rule `vitest/prefer-comparison-matcher`. Enforce using the built-in comparison matchers

- Source: vitest
- Technologies: Testing
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1792 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `vitest/prefer-comparison-matcher` | no | safe | package `@vitest/eslint-plugin` | [docs](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-comparison-matcher.md) |
| Oxlint | `vitest/prefer-comparison-matcher` | no | safe | plugin `vitest`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/vitest/prefer-comparison-matcher.html) |

## Code examples

### Incorrect: the rule reports this

```js
expect(x > 5).toBe(true)
expect(x < 7).not.toEqual(true)
expect(x <= y).toStrictEqual(true)
```

### Correct: the rule accepts this

```js
expect(x).toBeGreaterThan(5)
expect(x).not.toBeLessThanOrEqual(7)
expect(x).toBeLessThanOrEqual(y)

// special case - see below
expect(x < 'Carl').toBe(true)
// Rule only works on inters and big integers
```

```js
export default [
  {
    settings: {
      vitest: {
        typecheck: true,
      },
    },
  },
]
```

Examples from the ESLint documentation.

## Enable it

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

```js
import vitest from "@vitest/eslint-plugin";

export default [
  {
    plugins: { vitest },
    rules: {
      "vitest/prefer-comparison-matcher": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "vitest"
  ],
  "rules": {
    "vitest/prefer-comparison-matcher": "error"
  }
}
```

## Related rules

- [jest/prefer-comparison-matcher](https://lintradar.dev/rules/jest/prefer-comparison-matcher.md): Suggest using the built-in comparison matchers
- [vitest/prefer-called-once](https://lintradar.dev/rules/vitest/prefer-called-once.md): Enforce using `toBeCalledOnce()` or `toHaveBeenCalledOnce()`
- [vitest/prefer-each](https://lintradar.dev/rules/vitest/prefer-each.md): Enforce using `each` rather than manual loops
- [vitest/padding-around-test-blocks](https://lintradar.dev/rules/vitest/padding-around-test-blocks.md): Enforce padding around `test` blocks
- [vitest/prefer-expect-assertions](https://lintradar.dev/rules/vitest/prefer-expect-assertions.md): Enforce using expect assertions instead of callbacks
- [vitest/padding-around-expect-groups](https://lintradar.dev/rules/vitest/padding-around-expect-groups.md): Enforce padding around `expect` groups

---

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