Unused Function Parameter
ID |
go.unused_method_parameter |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Go |
Tags |
code-style, unused-code |
Description
Reports function and method parameters that are never referenced in the body. The blank
identifier _ is treated as an explicit "intentionally unused" marker and is never reported.
Because interface satisfaction in Go is structural and cannot be proven from a single file, the
rule is deliberately conservative: functions with an empty body (the classic interface-stub
shape) and unnamed parameters are skipped.
Rationale
Unused parameters bloat function signatures, confuse callers about what the function actually
needs, and accumulate as dead code when contracts evolve. Go already provides the blank
identifier _ to mark a parameter as deliberately ignored, so a genuinely unused named
parameter is almost always a mistake or leftover.
// Bad - 'unused' is never referenced
func process(used string, unused int) { // FLAW on 'unused'
fmt.Println(used)
}
// Good - all parameters used
func process(used string, count int) {
for i := 0; i < count; i++ {
fmt.Println(used)
}
}
// Good - blank identifier marks the parameter as intentionally ignored
func handler(_ http.ResponseWriter, r *http.Request) {
log(r.URL.Path)
}
Remediation
Remove the unused parameter from the signature, or use it in the body. If the parameter is
required to satisfy an interface, rename it to the blank identifier _ to make the intent
explicit.