Q: How do I resolve this madness between the ireturn
and nolintlint
linters?
Details:
I have a Golang function with this signature
func NewClientCredentialsTokenSource(
issuer string,
clientId string,
clientSecret string,
scope []string,
) (oauth2.TokenSource, error) {
When I run golangci-lint v1.43.0 it reports
golangci-lint run
oidc/token_utils.go:19:1: NewClientCredentialsTokenSource returns interface (golang.org/x/oauth2.TokenSource) (ireturn)
func NewClientCredentialsTokenSource(
Since the function has only two return params it is easy to deduce it is complaining about oauth2.TokenSource
and not error
.
The downstream function called by NewClientCredentialsTokenSource
returns an instance of oauth2.TokenSource
so I don't have a concrete type to return. I have no choice but to return the oauth2.TokenSource
interface.
So I add a lint exception to the function like this:
//nolint:ireturn
func NewClientCredentialsTokenSource(
issuer string,
clientId string,
clientSecret string,
scope []string,
) (oauth2.TokenSource, error) {
You'd think that should fix it but no! Now there's a new lint issue is reported:
golangci-lint run
oidc/token_utils.go:19:1: directive `//nolint:ireturn` is unused for linter "ireturn" (nolintlint)
//nolint:ireturn
So now I'm chasing my tail. ireturn
complains I am returning an interface. I add an exception for that function only to have nolintlint
complain I have an exception that doesn't apply.
What's a guy to do?
nolintlint
. That seems excessive. – Beating/nolint
checking withinireturn
itself, rather then ingolangci-lint
. This is going to be fixed in next version (wating just for go version update), then patch will be deployed togolangci-lint
. – Permian