comment-spacing
Enforce consistent blank-line spacing after comments.
Targeted pattern scopeโ
This rule inspects every comment in the file and measures the number of blank lines between the comment end and the next non-comment token.
Expected spacing is content-aware:
- Line comments (
// ...) โ no blank line after the comment. - Single-line block comments (
/* ... */) โ no blank line after the comment. - Multiline block comments (
/* ...\n... */) โ exactly one blank line after the comment. - ESLint directive block comments (for example
/* eslint-disable */) โ no blank line after the comment.
What this rule reportsโ
This rule reports comments whose trailing blank-line spacing does not match the expected spacing model above.
The rule is auto-fixable and rewrites only the whitespace between the comment and the next token.
Why this rule existsโ
Inconsistent spacing after comments makes scan-reading harder and causes noisy diffs. A deterministic spacing rule keeps comment blocks visually consistent across contributors and editors.
โ Incorrectโ
/*
* Renders the profile panel.
*/
const renderProfile = () => {
// ...
};
// Validate and normalize input.
const normalize = (value: string) => value.trim();
โ Correctโ
/*
* Renders the profile panel.
*/
const renderProfile = () => {
// ...
};
// Validate and normalize input.
const normalize = (value: string) => value.trim();
Behavior and migration notesโ
This rule is autofixable (fixable: "whitespace") and rewrites only the
whitespace between a comment and the next token.
Use --fix-dry-run in CI first if you want to preview spacing churn before
mass-apply.
Optionsโ
This rule has no options.
Additional examplesโ
/* eslint-disable no-console */
const run = () => {
console.log("allowed here");
};
/*
* This multiline explanation is intentionally separated
* from the code it introduces.
*/
const createTask = () => ({ id: crypto.randomUUID() });
ESLint flat config exampleโ
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/comment-spacing": "error",
},
},
];
When not to use itโ
Disable this rule if your formatter or style guide intentionally uses different post-comment spacing conventions.
Package documentationโ
Rule catalog ID: R003
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.