Skip to content

beforeEachPaddingLines

Enforces padding around beforeEach blocks.

✅ This rule is included in the vitest stylisticStrict presets.

Blank lines around beforeEach() hooks make per-test setup stand out from assertions and suite declarations. They also help readers distinguish recurring setup work from the test cases that consume it.

import { beforeEach, describe } from "vitest";
const state = {
reset() {},
};
beforeEach(() => {
state.reset();
});
describe("state", () => {
// ...
});
import { beforeEach, describe } from "vitest";
describe("worker", () => {
const cache = {
clear() {},
};
const mocks = {
restore() {},
};
beforeEach(() => {
cache.clear();
});
beforeEach(() => {
mocks.restore();
});
});

This rule is not configurable.

If you prefer beforeEach() hooks to stay visually attached to the code they prepare, this rule may add more vertical space than your team wants. That can be a reasonable choice in short test files with minimal setup.

Made with ❤️‍🔥 around the world by the Flint team and contributors.