kisielk/errcheck

report missing ok return arguments for hashmap lookups

mcandre opened this issue · 1 comments

Could errcheck report when a hashmap lookup neglects to check for existence, via the pattern ok, v := h[expression]? If the developer neglects to specify ok, then the lookup can silently fail.

I'm afraid not. It's totally valid to omit the , ok portion of a map lookup, if you are fine with using the zero value that is returned in that case. For instance, consider this algorithm:

m := make(map[K][]V)
for _, k := range Ks {
  vs := m[k]
  vs = append(vs, someV)
  m[k] = vs
}