Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nolintlint conflicts with new go1.19 gofmt #3073

Closed
4 tasks done
dnephin opened this issue Aug 6, 2022 · 2 comments
Closed
4 tasks done

nolintlint conflicts with new go1.19 gofmt #3073

dnephin opened this issue Aug 6, 2022 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@dnephin
Copy link

dnephin commented Aug 6, 2022

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).
  • Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)

Description of the problem

I just upgraded to golangci-lint v1.48.0.

It seems that gofmt can now conflict with nolintlint. For example, I have this code:

//nolint:maintidx
func something() { ... }

When I run golangci-lint run the gofmt linter complains and says the file is not formatted properly.

filename:line: File is not `gofmt`-ed with `-s` (gofmt)
//nolint: maintidx

If I fix it (using --fix or manually), and run again, I get

filename:line: directive `// nolint: maintidx` should be written without leading space as `//nolint: maintidx` (nolintlint)
// nolint: maintidx

I have other //nolint: directives that are not impacted. It seems to be only this one, because it is on a function definition instead of in a function block. I think gofmt is considering it a godoc comment (even though the function is not exported).

Version of golangci-lint

$ golangci-lint --version
# Paste output here

Configuration file

$ cat .golangci.yml
# paste output here

Go environment

golangci-lint v1.48.0 golang v1.18.1

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
# paste output here

Code example or link to a public repository

https://github.com/gotestyourself/gotest.tools/blob/fac3030b84c98b640417ebd23001567d5f3501f7/assert/cmd/gty-migrate-from-testify/migrate.go#L144-L145

@dnephin dnephin added the bug Something isn't working label Aug 6, 2022
@dnephin
Copy link
Author

dnephin commented Aug 6, 2022

I was able to move the comment to the end of the function line to work around the issue:

func something() { //nolint:maintidx

@ldez
Copy link
Member

ldez commented Aug 6, 2022

duplicate of #3068, #3063

@ldez ldez closed this as completed Aug 6, 2022
@ldez ldez added duplicate This issue or pull request already exists and removed bug Something isn't working labels Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants