vitest/prefer-hooks-in-order
@vitest/eslint-plugin
No autofix
eslint.config.js
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-hooks-in-order": "error",
},
},
];describe('foo', () => {
beforeEach(() => {});
beforeAll(() => {});
});describe('foo', () => {
afterEach(() => {});
afterAll(() => {});
beforeAll(() => {});
});describe('foo', () => {
beforeAll(() => {});
beforeEach(() => {});
afterEach(() => {});
afterAll(() => {});
});// Hooks separated by test cases are treated independently.
describe('foo', () => {
beforeEach(() => {});
it('a test', () => {});
afterAll(() => {});
});Examples from the Biome documentation.
vitest/prefer-hooks-in-order
@vitest/eslint-plugin
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-hooks-in-order": "error",
},
},
];vitest/prefer-hooks-in-order
vitest plugin · style
{
"plugins": [
"vitest"
],
"rules": {
"vitest/prefer-hooks-in-order": "error"
}
}style/useTestHooksInOrder
style · since 2.4.15
{
"linter": {
"rules": {
"style": {
"useTestHooksInOrder": "error"
}
}
}
}Prefer having hooks in a consistent order
Enforce using test or it but not both
Require describe block to be less than set max value or default value
Disallow duplicate hooks and teardown hooks