Require Padding Lines
Require blank lines between specific statement patterns so code stays visually organized and easy to scan.
Summary
The require-padding-lines rule enforces blank lines in six situations:
- Between
process.exitCodeassignments andreturn. - Before loop statements.
- Around bare
awaitexpressions adjacent to declarations. - Before
//line comments preceded by code. - Between distinct expression-statement operations.
- Between non-empty switch cases.
Why Use This Rule?
- Separates exit-code logic from the return statement so the intent is visually clear.
- Prevents loops from running into the declarations above them.
- Keeps bare
awaitcalls visually distinct from surrounding variable declarations. - Sets off
//line comments from the code above them so each comment introduces its block. - Adds breathing room between sequential method calls and
awaitoperations. - Gives switch cases clear visual boundaries so each branch is easy to scan.
Examples
Configuration
Options
warning
ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.
| Option | Type | Default | Description |
|---|---|---|---|
bareAwait | boolean | true | Require a blank line separating bare await from declarations. |
beforeLineComment | boolean | true | Require a blank line before // line comments preceded by code. |
beforeLoops | boolean | true | Require a blank line before for/while/do...while loop statements. |
betweenOperations | boolean | true | Require a blank line between distinct expression-statement operations, and between a variable declaration and a following call/await expression statement. |
betweenSwitchCases | boolean | true | Require a blank line between non-empty switch cases. |
exitCodeBeforeReturn | boolean | true | Require a blank line between process.exitCode = N and return. |
ignoreFiles | string[] | [] | File names to skip. Supports a leading-* suffix (*.test.ts), an exact path, or a trailing path segment; ** globs are not supported. |
Set any option to false to disable that specific check.
Autofix
This rule provides automatic fixes for the beforeLineComment check. Other checks report errors that must be updated manually. Run ESLint with the --fix flag:
npx eslint --fix . --rule '@cbnventures/nova/require-padding-lines: error'
Troubleshooting
- Warning fires between two loops — The
beforeLoopscheck only fires when a loop is preceded by a non-loop statement. Consecutive loops do not trigger a warning. - Warning fires on an assigned await — The
bareAwaitcheck only targetsawaitexpressions that appear as standalone expression statements (no assignment). Assignedawaitlikeconst x = await fn()is not affected. - No warning between repeated calls — The
betweenOperationscheck compares callee names. Consecutive calls to the same function (e.g.,ok(a); ok(b);) are considered the same operation and do not require a blank line. - No warning between two plain function calls — The
betweenOperationscheck also skips when both statements are bare calls with no receiver (e.g.,foo(); bar();). It only requires a blank line when at least one side is a member-expression call (e.g.,obj.foo(); obj.bar();).