close

prefer-hooks-in-order

Added in v0.8.2

Configuration

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

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

Correct

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