Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S1011 - should replace loop with s = append(s, items...) #1399

Closed
fenisteel opened this issue Apr 28, 2023 · 1 comment
Closed

S1011 - should replace loop with s = append(s, items...) #1399

fenisteel opened this issue Apr 28, 2023 · 1 comment

Comments

@fenisteel
Copy link

staticcheck 2023.1.3 (v0.4.3)
Compiled with Go version: go1.20.3
Main module:
        honnef.co/go/tools@v0.4.3 (sum: h1:o/n5/K5gXqk8Gozvs2cnL0F2S1/g1vcGCAx2vETjITw=)
Dependencies:
        github.com/BurntSushi/toml@v1.2.1 (sum: h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=)
        golang.org/x/crypto@v0.8.0 (sum: h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=)
        golang.org/x/exp/typeparams@v0.0.0-20221208152030-732eee02a75a (sum: h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE=)
        golang.org/x/mod@v0.7.0 (sum: h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=)
        golang.org/x/net@v0.9.0 (sum: h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=)
        golang.org/x/sys@v0.7.0 (sum: h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=)
        golang.org/x/text@v0.9.0 (sum: h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=)
        golang.org/x/tools@v0.4.1-0.20221208213631-3f74d914ae6d (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.

@fenisteel fenisteel added false-positive needs-triage Newly filed issue that needs triage labels Apr 28, 2023
@dominikh dominikh removed the needs-triage Newly filed issue that needs triage label Apr 28, 2023
@dominikh
Copy link
Owner

You're absolutely right.

dominikh added a commit that referenced this issue Aug 17, 2023
Closes: gh-1399
(cherry picked from commit bb0858e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants