staticcheck: allow exceptions to rule against underscores in constants
We have some constants like TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 that get flagged by ST1003. Ideally, I'd be able to add them to something similar to initialisms so that they're never flagged.
I know I can add //lint:ignore ST1003 blah blah blah, but that seems wrong here: the reason Go uses TLS_ECDHE... is because (1) it's well-known, (2) TLSECDHEECDSAWITHAES256GCMSHA384 is utterly un-parsable, and (3) TlsEcdheEcdsaWithAes256GcmSha384 doesn't properly capitalize initialisms. So, in that sense it's a valid exception to Go's rule about no underscores.
staticcheck 2020.1.3
Compiled with Go version: go1.14.1
Main module:
honnef.co/go/[email protected] (sum: h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=)
Dependencies:
github.com/BurntSushi/[email protected] (sum: h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=)
golang.org/x/[email protected] (sum: h1:2PHG+Ia3gK1K2kjxZnSylizb//eyaMG8gDFbOG7wLV8=)
I'll have to spend some time thinking about this.
@dominikh I'm using golangcli-lint with a lot of linters, staticcheck is one of them, as is revive.
In revive there is a setting var-naming to allow the usage of upper case snake case for const:
[rule.var-naming]
arguments = [["ID"], ["VM"], [{upperCaseConst=true}]]
The following is then acceptable by revive, but it fails for staticcheck:
const (
COMPLETIONS_URL = "https://api.openai.com/v1/chat/completions"
MODEL_3_5_TURBO_0125 = "gpt-3.5-turbo-0125"
ROLE_SYSTEM = "system"
ROLE_USER = "user"
)
I was looking for the same setting that would allow upper case snake case for consts.
I was looking for the same setting that would allow upper case snake case for consts.
I would use the revive setting you found, and I would disable ST1003 via golangci-lint.
@ccoVeille Doesn't ST1003 check more than just const names?
That's right, but I think revive namevar checker covers most of what this staticcheck rule.
I might be wrong. I'm a random Gopher after all.
Let's wait for other people to reply you