> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# prefer-hooks-in-order

[Added in v0.8.2](https://github.com/web-infra-dev/rslint/releases/tag/v0.8.2)
## Configuration

| Preset                     | Configured Value |
| -------------------------- | ---------------- |
| ✅ rstestPlugin.configs.all | `"warn"`         |


```ts title=rslint.config.ts
import { defineConfig, rstestPlugin } from '@rslint/core';

export default defineConfig([
  rstestPlugin.configs.recommended,
  {
    rules: {
      'rstest/prefer-hooks-in-order': 'error',
    },
  },
]);
```

## Rule Details

Requires lifecycle hooks to appear in the order Rstest runs them: `beforeAll`, `beforeEach`, `afterEach`, then `afterAll`. Keeping declarations in runtime order makes test setup easier to read.

The rule checks consecutive hook declarations. A non-hook call begins a new sequence, allowing separate setup groups when needed.

## Incorrect

```ts
afterAll(() => closeDatabase());
beforeAll(() => openDatabase());
```

## Correct

```ts
beforeAll(() => openDatabase());
beforeEach(() => resetDatabase());
afterEach(() => clearDatabase());
afterAll(() => closeDatabase());
```
