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

v1.48: nolint default config conlicts with go fmt #3098

Closed
4 tasks done
amass01 opened this issue Aug 14, 2022 · 3 comments
Closed
4 tasks done

v1.48: nolint default config conlicts with go fmt #3098

amass01 opened this issue Aug 14, 2022 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@amass01
Copy link

amass01 commented Aug 14, 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

Latest (v1.48) nolintlint default config has a conflict with 1.19 gofmt.
After #3002 nolintlint complains about leading spaces in //nolint comments
by default and the gofmt command re-adds the leading space.

Version of golangci-lint

$ golangci-lint --version
v1.48

Configuration file

$ cat .golangci.yml
linters:
  enable:
    - bodyclose
    - deadcode
    - depguard
    - dogsled
    - dupl
    - errcheck
    - exhaustive
    - exportloopref
    - funlen
    - gochecknoinits
    - goconst
    - gocritic
    - gocyclo
    - gofmt
    - goimports
    - gomnd
    - goprintffuncname
    - gosec
    - gosimple
    - govet
    - ineffassign
    - misspell
    - nakedret
    - noctx
    - nolintlint
    - revive
    - rowserrcheck
    - staticcheck
    - structcheck
    - stylecheck
    - typecheck
    - unconvert
    - unparam
    - unused
    - varcheck
    - whitespace

Go environment

$ go version && go env
1.19

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
Error: directive `// nolint` should be written without leading space as `//nolint` (nolintlint)

Code example or link to a public repository

// nolint 
@amass01 amass01 added the bug Something isn't working label Aug 14, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 14, 2022

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@amass01 amass01 changed the title v1.48: nolintlint default config conlicts with go fmt v1.48: nolint default config conlicts with go fmt Aug 14, 2022
@ldez
Copy link
Member

ldez commented Aug 14, 2022

Hello,

Due to a change of go fmt inside go1.19.
We have to enforce the directive style.

So the option allow-leading-space has been dropped.

The syntax of directives is: [a-zA-Z]+:[a-zA-Z].*.
The spaces around : and after the // must be removed.

If you do that your IDE or go fmt will format the directive as a directive and it will not add extra space.

Related to:
#3002
#1658 (comment)

@ldez ldez closed this as completed Aug 14, 2022
@ldez ldez added duplicate This issue or pull request already exists and removed bug Something isn't working labels Aug 14, 2022
@amass01
Copy link
Author

amass01 commented Aug 15, 2022

Noted, thank you

@ldez ldez mentioned this issue Sep 9, 2022
4 tasks
ungtb10d pushed a commit to blckhodl/gitaly that referenced this issue Sep 30, 2022
With recent changes `gofmt` [1] started reformatting godoc comments.
This causes a problem wherein it reformats `//nolint: staticcheck` to
`// nolint: staticcheck`.

But it does ignore directives [2]. So let's change all our nolint to
directive format. This avoids the conflict with `gofmt`.

This fix was done by running:
`grep -r --include="*.go" -E "//nolint: .*" -l | xargs sed -i 's/nolint:
stylecheck/nolint:stylecheck/g'`
as such, we can skip it from review.

[1]:
golangci/golangci-lint#1658 (comment)
[2]:
golangci/golangci-lint#3098 (comment)
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