The linter reports the warning:
slice 'result' does not have non-zero initial length (makezero)
even when the slice is explicitly created with a non-zero length.
func initUserScores(users []string, defaultScore int) map[string][]int {
result := make(map[string][]int, len(users))
template := []int{defaultScore, defaultScore}
for _, u := range users {
// Pre-allocate exact slice length
result[u] = make([]int, len(template))
copy(result[u], template)
}
return result
}
Can we handle these type of cases where function like copy are immediately next to declaration.