beforeEachPaddingLines
Enforces padding around
beforeEachblocks.
✅ 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.
Examples
Section titled “Examples”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(); });});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(); });});Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 around the world by
the Flint team and contributors.