Skip to content

no-commented-code

Reports comments that look like real code.

The rule groups adjacent line comments, checks block comments on their own, and tries to parse the comment text as JavaScript or TypeScript. If the result looks like real code, it reports the whole comment range and offers a removal suggestion.

It intentionally skips a lot of comments that would be noisy to flag, including empty comments, JSDoc, linter directives, many plain-English notes, URLs, and a few short parseable forms that are common in prose.

Incorrect
function calculate(x: number) {
// const result = x * 2;
// return result;
return x + 1;
}
Correct
function calculate(x: number) {
// TODO: switch back to multiplication after the API lands
// The offset is temporary because the upstream value can overflow.
return x + 1;
}
  • adjacent // lines that form a code block
  • /* ... */ comments that parse as statements or expressions
  • incomplete commented code where the rule can infer missing braces and still parse it
  • JSX-like commented code when the parser can recover with TSX parsing

The rule does not auto-fix by default. It adds a suggestion to remove the commented block.