Empty Blocks
ID |
swift.empty_blocks |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Swift |
Tags |
code-smell, reliability |
Description
Reports loops (while, for, repeat … while) and if statements
with an empty body. Almost always a typo, a stub left from incremental
development, or a busy-wait.
while cond { } // FLAW
for x in xs { } // FLAW
if cond { } // FLAW
while cond { tick() } // OK
if cond { f() } // OK
Rationale
An empty body discards the control structure’s purpose. Empty if bodies
often indicate a forgotten implementation; empty loops are usually
incomplete refactors or accidental busy-waits.
Remediation
Either fill the body, remove the control statement, or — if the intent is to consume an iterator — be explicit:
// Materialize an iterator (rare; explicit).
let it = makeIterator()
_ = it.makeIterator()
// Comment when you intentionally suppress the block.
if cond {
// intentionally no-op, see <reason>
}