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, and this page is available as Markdown at https://rslint.rs/rules/rstest/no-hooks.md.
close

no-hooks

Added in v0.8.2

Configuration

PresetConfigured Value
✅ rstestPlugin.configs.all"warn"
rslint.config.ts
import { defineConfig, rstestPlugin } from '@rslint/core';

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

Rule Details

Disallows lifecycle hooks when a project prefers each test to set up and clean up its own state explicitly.

The rule covers beforeAll, beforeEach, afterEach, and afterAll from globals, imports, aliases, and Playwright test objects.

Incorrect

beforeEach(() => {
  resetDatabase();
});

test('creates a user', () => {});

Correct

test('creates a user', () => {
  const database = createTestDatabase();

  expect(database.users.create({ name: 'Ada' }).name).toBe('Ada');
});

Options

{
  "rstest/no-hooks": [
    "error",
    {
      "allow": ["afterEach"]
    }
  ]
}
OptionTypeDefaultDescription
allowstring[][]Lifecycle hooks to allow: beforeAll, beforeEach, afterEach, or afterAll.