Skip to content
tai-kun's Vite+ Lint Plugins
Esc
↑↓navigate↵open⌘Jpreview
On this page

blank-line

Require blank lines between statements, class members, and switch cases.

  • Rule ID: tai-kun/blank-line
  • Auto-fix: Yes

Requires one blank line between statements, class members, and non-empty switch cases. This rule consolidates six former rules (blank-line-after-control-block, blank-line-after-declaration, blank-line-after-variable-declaration, blank-line-before-return, blank-line-between-class-members, and blank-line-between-switch-cases), each of which can be toggled with an option. Each boundary produces at most one diagnostic, so the items never contradict each other.

Configuration

Add the rule to lint.rules in vite.config.ts to enable it. All options default to true.

"tai-kun/blank-line": ["error", {
  afterControlBlock: true,
  afterDeclaration: true,
  afterVariableDeclaration: true,
  beforeReturn: true,
  betweenClassMembers: true,
  betweenSwitchCases: true,
  betweenTypeMembers: true,
}],
Option Description
afterControlBlock Require a blank line after if, for, while, switch, try, and similar blocks when another statement follows.
afterDeclaration Require a blank line after function, class, interface, type, and similar declarations when another statement follows.
afterVariableDeclaration Require a blank line after a variable declaration group when another statement follows, and remove blank lines inside the group.
beforeReturn Require a blank line before a return statement when another statement precedes it.
betweenClassMembers Require a blank line between class members.
betweenSwitchCases Require a blank line between non-empty cases.
betweenTypeMembers Require a blank line above JSDoc comments between interface and type literal members.

Examples

Invalid

const ready = getItems();
ready.sort(compareNames);
const sorted = [];

Valid

const ready = getItems();
ready.sort(compareNames);

const sorted = [];

Notes

  • Expression statements that use the declared variables, such as ready.sort(compareNames), belong to the same group, and blank lines between them are removed.
  • Consecutive variable declarations are treated as one group, with or without blank lines between them.
  • Overload signatures, getter/setter pairs, and empty fallthrough cases are excluded.
  • Blank lines around intervening line comments (//) and plain block comments (/* */) are optional.
  • A blank line is required above JSDoc-style block comments (starting with /**).
  • Extra blank lines are collapsed to one by Oxfmt.

Was this page helpful?