A common Go programming error we've seen is:
for _, item := range items {
item.SomeField = value // oops
}
As range copies the value, assigning to the struct field effectively does nothing.
The correct way is to use the index: https://stackoverflow.com/a/16013949/161457
Is there a way to detect this error with golangci-lint? (If not, is there another linter that will catch this?)
golangci-linthas the linterineffassignenabled by default. But this lintermisses some cases because it does not consider any type information in its analysis. For example, assignments to struct fields are never marked as ineffectual. Also see this bug report: github.com/gordonklaus/ineffassign/issues/70.