Commented Out Code

ID

swift.commented_out_code

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Swift

Tags

code-smell, dead-code, maintainability

Description

Reports a // comment whose contents look like Swift code — it starts with a Swift keyword, is an assignment, or is a function call expression — and isn’t a recognised prose marker or tooling directive (TODO, FIXME, MARK:, doc comment ///, …).

// if x > 0 { return 1 }                  // FLAW
// let value = compute(x)                 // FLAW

// TODO: implement this properly          // OK
// MARK: - Setup                          // OK
/// Doc comment describing nextDecl       // OK

Rationale

Commented-out code is dead weight. Readers waste effort decoding what it once did and whether it still applies. Version control already preserves the history — if a snippet might be useful again, it lives in the git log, not in the working tree.

Remediation

Delete the commented-out lines. Use prose comments to explain why something is the way it is, not to keep an older version of the code on life support. Reach for #if DEBUG blocks (or a feature flag) when you actually want to keep behaviour conditionally compiled in.