vitest/prefer-hooks-on-top
@vitest/eslint-plugin
No autofix
eslint.config.js
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-hooks-on-top": "error",
},
},
];describe('foo', () => {
it('does something', () => {});
beforeEach(() => {});
});describe('foo', () => {
beforeEach(() => {});
it('does something', () => {});
});Examples from the Biome documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
vitest/prefer-hooks-on-top
@vitest/eslint-plugin
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-hooks-on-top": "error",
},
},
];vitest/prefer-hooks-on-top
vitest plugin · style
{
"plugins": [
"vitest"
],
"rules": {
"vitest/prefer-hooks-on-top": "error"
}
}style/useTestHooksOnTop
style · since 2.4.14
{
"linter": {
"rules": {
"style": {
"useTestHooksOnTop": "error"
}
}
}
}Suggest having hooks before any test cases
Enforce using the built-in equality matchers
Enforce importing Vitest globals
Enforce using a function as a describe title over an equivalent string
Enforce using toBeCalledWith() or toHaveBeenCalledWith()