go run honnef.co/go/tools/cmd/staticcheck@latest ./...
This complained about the following code:
argmap := make(map[string]bool)
if strings.Contains(arg, "=") {
parts := strings.SplitN(arg, "=", 2)
argmap[parts[0]] = true
}
The error I got was as follows:
/var/lib/buildkite-agent/builds/buildkite-ci-076791110486c8a56/segment/lokicli/cmd/lokicli/lokicli.go:100:13: error: Potential nil panic detected. Observed nil flow from source to dereference point:
- strings/strings.go:238:10: literal `nil` returned from `genSplit()` in position 0
- strings/strings.go:278:53: result 0 of `genSplit()` returned from `SplitN()` in position 0
- lokicli/lokicli.go:100:13: result 0 of `SplitN()` sliced into via the assignment(s):
- `strings.SplitN(...)` to `parts` at lokicli/lokicli.go:99:6
I don't think that this can nil panic because of the Contains line above. I guess one thing I could do is just try the split and check for nil, but this obscures the intention of the code more.
I ran
This complained about the following code:
The error I got was as follows:
I don't think that this can nil panic because of the Contains line above. I guess one thing I could do is just try the split and check for nil, but this obscures the intention of the code more.