Redundant Single-Argument Append
ID |
go.redundant_append_single_arg |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Code Smell |
Language |
Go |
Tags |
CWE:1164, code-style, readability |
Description
Reports a call to the builtin append with a single argument and no elements to add — append(x).
With nothing to append the call returns its slice argument unchanged.
Rationale
y = append(x) is exactly y = x. The call does no work and is usually a leftover from an edit
that removed the appended elements. The check resolves the call so that only the genuine builtin
append matches; a locally shadowed append is left alone.
func fn(x []int) {
y := append(x) // FLAW — equivalent to y := x
z := append(x, 1) // OK — appends an element
_, _ = y, z
}