Go-tools: staticcheck: check functions taking an even number of arguments

Created on 3 May 2019  Â·  8Comments  Â·  Source: dominikh/go-tools

Some functions accept varargs but expect an even number of arguments. Check these calls where possible.

  • [x] runtime/pprof.Labels
  • [ ] (github.com/go-kit/kit/log.Logger).Log
  • [ ] Some functions in github.com/inconshreveable/log15
  • [x] google.golang.org/grpc/metadata.Pairs
  • [ ] google.golang.org/grpc/metadata.AppendToOutgoingContext
  • [ ] Some methods on go.uber.org/zap.SugaredLogger
  • [x] strings.NewReplacer

(Well, that list ended up a lot shorter than expected. Well, that list is getting depressingly long.)

new-check started

All 8 comments

https://godoc.org/github.com/go-kit/kit/log#Logger does too, if suggestions related to #461 are good here

Same for https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md#creating-a-new-metadata

Edit: metadata.Pairsand metadata.AppendToOutgoingContext

go.uber.org/zap has a SugaredLogger type that’s similar to go-kit’s logger.

Can we make this configurable? At work we have private packages that have this same pattern

Don't forget about strings.NewReplacer.

@frioux I do have vague plans for custom rule sets that users can write, but nothing has materialized yet and it would be a future feature that I might add to staticcheck.

We can probably detect some of these functions automatically, if we detect the following pattern in functions:

if len(args)%2 != 0 {
    panic("some message")
}

(plus the expected constraints: args must be the unmodified vararg, all paths through the function must hit the condition)

I built this, but it's painfully slow:
https://godoc.org/github.com/ZipRecruiter/splinter/pairs

On Tue, May 19, 2020, 11:02 PM Dominik Honnef notifications@github.com
wrote:

We can probably detect some of these functions automatically, if we detect
the following pattern in functions:

if len(args)%2 != 0 {
panic("some message")
}

(plus the expected constraints: args must be the unmodified vararg, all
paths through the function must hit the condition)

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/dominikh/go-tools/issues/464#issuecomment-631255754,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAB7Y4QJQ4ADDOTQZ33GGLRSNW5RANCNFSM4HKWTWAQ
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dominikh picture dominikh  Â·  3Comments

dominikh picture dominikh  Â·  3Comments

dominikh picture dominikh  Â·  4Comments

igungor picture igungor  Â·  3Comments

stamm picture stamm  Â·  4Comments