# prefer-snapshot-hint

Rule `vitest/prefer-snapshot-hint`. Enforce including a hint with external snapshots

- Source: vitest
- Technologies: Testing
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1800 by reach

## Linters

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

## Code examples

### Incorrect: the rule reports this

```ts
const snapshotOutput = ({ stdout, stderr }) => {
  expect(stdout).toMatchSnapshot()
  expect(stderr).toMatchSnapshot()
}

describe('cli', () => {
  describe('--version flag', () => {
    it('prints the version', async () => {
      snapshotOutput(await runCli(['--version']))
    })
  })

  describe('--config flag', () => {
    it('reads the config', async () => {
      const { stdout, parsedConfig } = await runCli([
        '--config',
        'vitest.config.js',
      ])

      expect(stdout).toMatchSnapshot()
      expect(parsedConfig).toMatchSnapshot()
    })

    it('prints nothing to stderr', async () => {
      const { stderr } = await runCli(['--config', 'vitest.config.js'])

      expect(stderr).toMatchSnapshot()
    })
  })
})
```

### Correct: the rule accepts this

```ts
const snapshotOutput = ({ stdout, stderr }, hints) => {
  expect(stdout).toMatchSnapshot({}, `stdout: ${hints.stdout}`)
  expect(stderr).toMatchSnapshot({}, `stderr: ${hints.stderr}`)
}

describe('cli', () => {
  describe('--version flag', () => {
    it('prints the version', async () => {
      snapshotOutput(await runCli(['--version']), {
        stdout: 'version string',
        stderr: 'empty',
      })
    })
  })

  describe('--config flag', () => {
    it('reads the config', async () => {
      const { stdout } = await runCli(['--config', 'vitest.config.js'])

      expect(stdout).toMatchSnapshot({}, 'stdout: config settings')
    })

    it('prints nothing to stderr', async () => {
      const { stderr } = await runCli(['--config', 'vitest.config.js'])

      expect(stderr).toMatchInlineSnapshot()
    })

    describe('when the file does not exist', () => {
      it('throws an error', async () => {
        await expect(
          runCli(['--config', 'does-not-exist.js']),
// …
```

```ts
const snapshotOutput = ({ stdout, stderr }, hints) => {
  expect(stdout).toMatchSnapshot({}, `stdout: ${hints.stdout}`)
  expect(stderr).toMatchSnapshot({}, `stderr: ${hints.stderr}`)
}

describe('cli', () => {
  describe('--version flag', () => {
    it('prints the version', async () => {
      snapshotOutput(await runCli(['--version']), {
        stdout: 'version string',
        stderr: 'empty',
      })
    })
  })

  describe('--config flag', () => {
    it('reads the config', async () => {
      const { stdout } = await runCli(['--config', 'vitest.config.js'])

      expect(stdout).toMatchSnapshot()
    })

    it('prints nothing to stderr', async () => {
      const { stderr } = await runCli(['--config', 'vitest.config.js'])

      expect(stderr).toMatchInlineSnapshot()
    })

    describe('when the file does not exist', () => {
      it('throws an error', async () => {
        await expect(
          runCli(['--config', 'does-not-exist.js']),
// …
```

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-snapshot-hint": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

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

## Related rules

- [jest/prefer-snapshot-hint](https://lintradar.dev/rules/jest/prefer-snapshot-hint.md): Prefer including a hint with external snapshots
- [vitest/prefer-mock-return-shorthand](https://lintradar.dev/rules/vitest/prefer-mock-return-shorthand.md): Prefer mock return shorthands
- [vitest/prefer-strict-boolean-matchers](https://lintradar.dev/rules/vitest/prefer-strict-boolean-matchers.md): Enforce using `toBe(true)` and `toBe(false)` over matchers that coerce types to boolean
- [vitest/prefer-mock-promise-shorthand](https://lintradar.dev/rules/vitest/prefer-mock-promise-shorthand.md): Enforce mock resolved/rejected shorthands for promises
- [vitest/prefer-to-be](https://lintradar.dev/rules/vitest/prefer-to-be.md): Enforce using toBe()
- [vitest/prefer-import-in-mock](https://lintradar.dev/rules/vitest/prefer-import-in-mock.md): Prefer dynamic import in mock

---

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