vitest/padding-around-after-all-blocks

Require a blank line before each afterAll call

fixable

An afterAll hook written right under another statement is easy to miss when you look for a file's cleanup code. A blank line above it sets it apart.

The rule only checks the line above the call, not the line below. Comments directly above the call count as part of it, so the blank line goes above them. An afterAll that comes first in a file or in a describe callback doesn't need a blank line.

--fix inserts the blank line.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"vitest/padding-around-after-all-blocks" = "error" # or "warn"

Examples#

example.ts1 problem
import { afterAll, describe } from "vitest";

describe("database", () => {
  const db = connect();
  afterAll(() => db.close());
});

Two afterAll calls in a row need a blank line between them too:

example.ts2 problems
import { afterAll } from "vitest";

const server = startServer();
afterAll(() => server.stop());
afterAll(() => removeTempFiles());
example.tsNo problems
import { afterAll, describe } from "vitest";

describe("database", () => {
  const db = connect();

  // Close the connection so the process can exit.
  afterAll(() => db.close());
});