Skip to content

Comments rules

Reports executable code left in comments. Documentation and tool directives stay valid.

On in the all config.

Disabled code goes stale and makes the active implementation harder to find. Git keeps its history.

Delete disabled code. Explain the active behavior in prose, and put examples in documentation comments.

// const user = readUser(); reports disabled code. Delete it or restore it as active code.

Reports each comment within or immediately after an import block, including TypeScript import-equals declarations. Exempts tool directives and each run of comments that leads the next declaration with at most one blank line between its parts.

On in the all config. eslint --fix fixes it.

An import block lists dependencies. A file header belongs before it, and a behavior comment belongs with the code it explains.

Move the comment above the first import or beside its declaration. eslint --fix moves a comment inside the block above it. A comment after the block gets no fix, because only you know which code it explains.

A file header after an import reports comment. A comment between imports does too. Move the comment above the first import or beside the code it explains. A comment that leads the next declaration remains in place, and so does a run of comments, such as a section label above a JSDoc block, separated by at most one blank line and ending directly above the declaration. Tool directives, such as // @ts-expect-error above the import it targets, are allowed anywhere in the block. CommonJS require declarations follow the same rule when ESLint selects the commonjs source type.

Reports a blank line between a /** */ comment and the declaration or member below it. Exempts a comment with a tag that documents the file or a type of its own, such as @file, @module, @typedef, and @callback.

On in the all config. eslint --fix fixes it.

A doc comment documents the declaration directly below it. After a blank line, editors and documentation tools read the declaration as undocumented.

Remove the blank line. eslint --fix removes it. For a comment about the whole file, add the @file tag or write a // comment.

A /** Doubles a number. */ comment, an empty line, and then function twice reports detached, and the fix removes the empty line. The fix of an unused // eslint-disable-next-line comment leaves such a line between a doc comment and its function. A comment with @file or @typedef, a comment above an import, and a // comment pass.