Unused Function Parameter
ID |
swift.unused_function_parameter |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Swift |
Tags |
code-smell, dead-code |
Description
Reports a function parameter whose internal name is never referenced
from inside the function body. The function would behave identically
with the parameter dropped (or renamed to the wildcard _, which
already signals "intentionally ignored").
func greet(name: String, age: Int) { // FLAW on `age`
print("Hi \(name)")
}
func greet(name: String, age _: Int) { // OK — explicitly ignored
print("Hi \(name)")
}
Rationale
Unused parameters add noise to the function signature, mislead the
reader into thinking the value matters, and silently survive refactors
that should have dropped them. Swift offers _ as the conventional
"this parameter exists for the protocol / API but is not consumed"
marker, and code review should require its use.
Protocol method requirements (declarations without a body) and
parameters whose internal name is already _ are not flagged.