consistent-empty-lines
Enforce configured empty-line consistency between selected nodes.
Targeted pattern scopeโ
This rule operates on the full file text and checks for runs of empty lines.
It allows:
- zero empty lines, or
- exactly one empty line between non-empty lines.
It reports when it finds two or more consecutive empty lines.
What this rule reportsโ
This rule reports files containing consecutive blank-line runs longer than one line.
An autofix is provided and collapses each run to a single blank line.
Why this rule existsโ
Extra vertical whitespace often accumulates during edits and merge conflict resolution. Enforcing a single-blank-line maximum keeps files visually dense and reduces noisy formatting diffs.
โ Incorrectโ
const first = 1;
const second = 2;
โ Correctโ
const first = 1;
const second = 2;
Behavior and migration notesโ
This rule is fully autofixable (fixable: "whitespace").
Recommended rollout:
- Run once with
--fix-dry-runto estimate churn. - Apply autofix in a dedicated formatting PR.
- Enable as
errorto keep the baseline clean.
Optionsโ
This rule has no options.
Additional examplesโ
function run(): void {
stepOne();
stepTwo();
}
ESLint flat config exampleโ
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/consistent-empty-lines": "error",
},
},
];
When not to use itโ
Disable this rule if your style guide intentionally allows multiple blank lines for sectioning or if another formatter already controls vertical spacing exactly as desired.
Package documentationโ
Rule catalog ID: R004
Further readingโ
Adoption resourcesโ
- Start at warning level in CI, then move to error after cleanup.
- Use focused codemods/autofix batches per package or directory.