no-single-line-comment
Disallow // comments and require block comments instead.
Targeted pattern scopeโ
This rule targets all line comments (// ...) in source files.
What this rule reportsโ
This rule reports line comments unless they are directive comments that are explicitly allowed by configuration.
Why this rule existsโ
Single-line comments are easy to accumulate as stale notes and are harder to format consistently in long explanations. This rule reports line comments and encourages block comments.
โ Incorrectโ
// update this later
const value = 1;
โ Correctโ
/* update this later */
const value = 1;
Behavior and migration notesโ
This rule reports only and does not provide an autofix.
Optionsโ
type Options = [
{
allowDirectiveComments?: boolean;
}?,
];
Default configurationโ
Default:
[{ allowDirectiveComments: true }];
When allowDirectiveComments is true, comments such as
// eslint-disable-next-line ... and // @ts-expect-error are allowed.
Additional examplesโ
// eslint-disable-next-line no-console
console.log("x");
// โ
allowed by default (`allowDirectiveComments: true`)
// TODO: refactor this
const value = 1;
// โ reported
/* TODO: refactor this */
const nextValue = 2;
// โ
valid
ESLint flat config exampleโ
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-single-line-comment": "error",
},
},
];
When not to use itโ
Disable this rule if your team standardizes on // comments for short inline
notes.
Package documentationโ
Rule catalog ID: R042
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.