dominikh / go-tools

Staticcheck - The advanced Go linter
https://staticcheck.dev
MIT License
6.03k stars 362 forks source link

staticcheck: check functions taking an even number of arguments #464

Open dominikh opened 5 years ago

dominikh commented 5 years ago

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

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

fortytw2 commented 5 years ago

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

sj14 commented 5 years ago

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

Edit: metadata.Pairsand metadata.AppendToOutgoingContext

akshayjshah commented 5 years ago

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

frioux commented 5 years ago

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

ChrisHines commented 5 years ago

Don't forget about strings.NewReplacer.

dominikh commented 5 years ago

@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.

dominikh commented 4 years ago

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)

frioux commented 4 years ago

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 .