# no-hooks

Rule `vitest/no-hooks`. Disallow setup and teardown hooks

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

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `vitest/no-hooks` | no | no | package `@vitest/eslint-plugin` | [docs](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-hooks.md) |
| Oxlint | `vitest/no-hooks` | no | no | plugin `vitest`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/vitest/no-hooks.html) |
| Biome | `nursery/noTestHooks` | no | no | group nursery, since 2.6.9 | [docs](https://biomejs.dev/linter/rules/no-test-hooks/) |

## Code examples

### Incorrect: the rule reports this

```js
function setupFoo(options) {
  /* ... */
}

function setupBar(options) {
  /* ... */
}

describe('foo', () => {
  let foo

  beforeEach(() => {
    foo = setupFoo()
  })

  afterEach(() => {
    foo = null
  })

  it('does something', () => {
    expect(foo.doesSomething()).toBe(true)
  })

  describe('with bar', () => {
    let bar

    beforeEach(() => {
      bar = setupBar()
    })

    afterEach(() => {
      bar = null
// …
```

### Correct: the rule accepts this

```js
function setupFoo(options) {
  /* ... */
}

function setupBar(options) {
  /* ... */
}

describe('foo', () => {
  it('does something', () => {
    const foo = setupFoo()
    expect(foo.doesSomething()).toBe(true)
  })

  it('does something with bar', () => {
    const foo = setupFoo()
    const bar = setupBar()
    expect(foo.doesSomething(bar)).toBe(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/no-hooks": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "vitest"
  ],
  "rules": {
    "vitest/no-hooks": "error"
  }
}
```

### Biome: `biome.json`

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

## Related rules

- [jest/no-hooks](https://lintradar.dev/rules/jest/no-hooks.md): Disallow setup and teardown hooks
- [vitest/no-duplicate-hooks](https://lintradar.dev/rules/vitest/no-duplicate-hooks.md): Disallow duplicate hooks and teardown hooks
- [vitest/no-test-return-statement](https://lintradar.dev/rules/vitest/no-test-return-statement.md): Disallow return statements in tests
- [vitest/max-nested-describe](https://lintradar.dev/rules/vitest/max-nested-describe.md): Require describe block to be less than set max value or default value
- [vitest/prefer-called-times](https://lintradar.dev/rules/vitest/prefer-called-times.md): Enforce using `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)`
- [vitest/prefer-called-with](https://lintradar.dev/rules/vitest/prefer-called-with.md): Enforce using `toBeCalledWith()` or `toHaveBeenCalledWith()`

---

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