Andrew Shannon Brown cf32a7b706
Add makezero linter (#1520)
makezero ensures that objects recognized as slices are initialized with length 0.  By default, this is only required when we find a subsequent append to the object, but can also be enabled at all times as a way of discouraging the use of integer variables (i.e. "i") to index slices.
2020-12-05 07:37:37 -08:00

13 lines
315 B
Go

//args: -Emakezero
package testdata
func Makezero() []int {
x := make([]int, 5)
return append(x, 1) // ERROR "append to slice `x` with non-zero initialized length"
}
func MakezeroNolint() []int {
x := make([]int, 5)
return append(x, 1) //nolint:makezero // ok that we're appending to an uninitialized slice
}