Commented-out Code

ID

javascript.commented_out_code

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

JavaScript

Tags

code-style

Description

Reports // and /* …​ */ comments whose body parses as JavaScript / TypeScript, indicating disabled or leftover source rather than prose.

// x = compute(y);                  // FLAW — parses as assignment
// if (cond) return value;          // FLAW — parses as if-statement
/* return cached.get(key); */       // FLAW — parses as return

// TODO: revisit caching            // OK — prose marker
// the result is cached for reuse   // OK — does not parse as JS

Rationale

Commented-out code is dead weight: it clutters the source, confuses readers about what is active, makes diffs noisier, and inevitably drifts out of sync with the live code. Version control already preserves history; there is no need to keep old code in comments.

The rule is intentionally conservative — it feeds the stripped comment body to the JavaScript parser and only fires when the parser accepts a non-trivial statement (declaration, call, assignment, control flow, etc.). Tooling directive prefixes and prose markers (TODO, FIXME, XXX, NOTE, HACK) are skipped so legitimate comments do not trip it.

Remediation

Delete the commented-out lines. The commit history preserves them. If the lines are reference material (e.g., an alternative implementation kept for later), move them into a JSDoc block or a separate experiments.js file so they are not silently rotting next to the live code.