hooks-order

July 23, 2026 ยท View on GitHub

๐Ÿ“ Enforce a consistent order of hook declarations.

๐Ÿ’ผ This rule is enabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

๐Ÿ”ง This rule is automatically fixable by the --fix CLI option.

Enforce a consistent declaration order for node:test hooks. The canonical order is: before, beforeEach, afterEach, after.

Examples

import {describe, before, beforeEach, afterEach, after} from 'node:test';

// โŒ
describe('user', () => {
	afterEach(() => {});
	before(() => {});
});

// โœ…
describe('user', () => {
	before(() => {});
	beforeEach(() => {});
	afterEach(() => {});
	after(() => {});
});