
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.
14 lines
330 B
Go
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
|
|
}
|