Simplify Make

ID

go.simplify_make

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Code Smell

Language

Go

Tags

code-smell, readability

Description

Reports a slice make([]T, length, 0) whose explicit capacity — the third argument — is the literal 0. A zero capacity is identical to supplying no capacity, so the argument is redundant.

Rationale

make([]T, n, 0) allocates a slice of length n and capacity 0…​ except a capacity below the length is ignored, leaving it exactly equivalent to make([]T, n). The redundant 0 reads like a deliberate pre-allocation hint that in fact does nothing, so it misleads the reader and adds noise.

make([]int, 0, 0)  // FLAW — redundant zero capacity
make([]int, 5, 0)  // FLAW — capacity 0 is a no-op
make([]int, 0, 8)  // OK — real capacity
make([]int, 0)     // OK — no capacity argument
make(chan int, 0)  // OK — channel buffer size, not a capacity

Remediation

Drop the third argument: write make([]T, n). If a real pre-allocation was intended, supply the expected capacity instead of 0.