Skip to main content

no-commented-out-code

Disallow comment blocks that appear to contain executable or declaration code.

Targeted pattern scopeโ€‹

This rule analyzes all comments in the file (line and block) and tries to parse their content as code.

It supports grouped consecutive line comments as one logical comment block.

What this rule reportsโ€‹

Commented-out code creates maintenance noise, hides stale implementation paths, and can mislead readers into thinking dead code is still relevant.

The rule reports comment blocks that parse as non-trivial code.

The rule intentionally ignores non-code commentary patterns like region markers and plain prose notes.

Why this rule existsโ€‹

Keeping dead code in comments makes reviews and refactors harder. This rule helps enforce a cleaner baseline.

โŒ Incorrectโ€‹

// const answer = 54;
const answer = 42;
class Example {
public a: string;
// public b: string;
public c: string;
}

โœ… Correctโ€‹

// Explanation: historical implementation tried 54 first.
const answer = 42;
class Example {
// #region Public API
public execute(): void {}
// #endregion
}

Deprecatedโ€‹

Behavior and migration notesโ€‹

This rule is deprecated in favor of no-commented-code/no-commented-code.

It reports only and does not provide an autofix.

Optionsโ€‹

This rule has no options.

Statusโ€‹

Use the Deprecated section above for lifecycle details.

Additional examplesโ€‹

// #region Helpers
// #endregion
// โœ… ignored as region marker comments

// if (flag) {
// run();
// }
// โŒ reported as commented-out executable code

ESLint flat config exampleโ€‹

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-commented-out-code": "error",
},
},
];

When not to use itโ€‹

Disable this rule if your team intentionally keeps commented examples inline instead of using docs, snippets, or tests.

Package documentationโ€‹

Rule catalog ID: R020

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.