golangci-lint/test/testdata/makezero_always.go
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

14 lines
330 B
Go

//args: -Emakezero
//config: linters-settings.makezero.always=true
package testdata
func MakezeroAlways() []int {
x := make([]int, 5) // ERROR "slice `x` does not have non-zero initial length"
return x
}
func MakezeroAlwaysNolint() []int {
x := make([]int, 5) //nolint:makezero // ok that this is not initialized
return x
}