Skip to content
← Back to rules

vitest/padding-around-expect-groups Style

🛠️ An auto-fix is available for this rule.

What it does ​

This rule enforces a line of padding before and after 1 or more expect statements.

It doesn't add or enforce a padding line when the statement is the last one in its scope, or between two or more adjacent expect statements.

The Vitest version applies the same grouping to expectTypeOf statements. Adjacent expect and expectTypeOf statements still need a padding line.

Why is this bad? ​

Inconsistent formatting of code can make the code more difficult to read and follow. This rule helps ensure that groups of assertions are visually separated from the rest of the code, making them easier to identify while looking through test files.

Examples ​

Examples of incorrect code for this rule:

js
test("thing one", () => {
  let abc = 123;
  expect(abc).toEqual(123);
  expect(123).toEqual(abc);
  abc = 456;
  expect(abc).toEqual(456);
});

Examples of correct code for this rule:

js
test("thing one", () => {
  let abc = 123;

  expect(abc).toEqual(123);
  expect(123).toEqual(abc);

  abc = 456;

  expect(abc).toEqual(456);
});

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["vitest"],
  "rules": {
    "vitest/padding-around-expect-groups": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["vitest"],
  rules: {
    "vitest/padding-around-expect-groups": "error",
  },
});
bash
oxlint --deny vitest/padding-around-expect-groups --vitest-plugin

Version ​

This rule was added in vnext.

References ​