Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

vitest/padding-around-after-all-blocks

Require a blank line before each afterAll call

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

Reported:

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:

import { afterAll } from "vitest";

const server = startServer();
afterAll(() => server.stop());
afterAll(() => removeTempFiles());

Not reported:

import { afterAll, describe } from "vitest";

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

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