Closed
Description
staticcheck 2023.1.3 (v0.4.3)
Compiled with Go version: go1.20.3
Main module:
honnef.co/go/[email protected] (sum: h1:o/n5/K5gXqk8Gozvs2cnL0F2S1/g1vcGCAx2vETjITw=)
Dependencies:
github.com/BurntSushi/[email protected] (sum: h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=)
golang.org/x/[email protected] (sum: h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=)
golang.org/x/exp/[email protected] (sum: h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE=)
golang.org/x/[email protected] (sum: h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=)
golang.org/x/[email protected] (sum: h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=)
golang.org/x/[email protected] (sum: h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=)
golang.org/x/[email protected] (sum: h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=)
golang.org/x/[email protected] (sum: h1:9ZNWAi4CYhNv60mXGgAncgq7SGc5qa7C8VZV8Tg7Ggs=)
go version:
go1.20.3 windows/amd64
go env:
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\<user>\AppData\Local\go-build
set GOENV=C:\Users\<user>\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\<user>\go\pkg\mod
set GOOS=windows
set GOPATH=C:\Users\<user>go
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.20.3
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\<user>\AppData\Local\Temp\go-build1304471075=/tmp/go-build -gno-record-gcc-switches
Staticcheck command:
staticcheck .
staticcheck.conf:
checks = ["all", "-ST1003", "-ST1005", "-ST1006", "-ST1020", "-ST1021", "-ST1022"]
I got the following message:
transports.go:241:3: should replace loop with itemMap[items[i].TransportLetterId] = append(itemMap[items[i].TransportLetterId], items...) (S1011)
This is the code block that has the problem:
items, err := GetLetterItemsByTransportId(ctx, id)
if err != nil {
return err
}
itemMap := make(map[int][]TransportItem, 0)
for i := range items {
itemMap[items[i].TransportLetterId] = append(itemMap[items[i].TransportLetterId], items[i])
}
Here I can't replace the loop, because I need to assign each item to a different map value based on their TransportLetterId since each map value is a slice of TransporItem.