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.