golangci / golangci-lint

Fast linters runner for Go
https://golangci-lint.run
GNU General Public License v3.0
15.36k stars 1.37k forks source link

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

Closed amass01 closed 2 years ago

amass01 commented 2 years ago

Welcome

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

```console $ golangci-lint --version v1.48 ```

Configuration file

```console $ 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

```console $ go version && go env 1.19 ```

Verbose output of running

```console $ 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

```go // nolint ```
boring-cyborg[bot] commented 2 years ago

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

ldez commented 2 years ago

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: https://github.com/golangci/golangci-lint/pull/3002 https://github.com/golangci/golangci-lint/issues/1658#issuecomment-1183148066

amass01 commented 2 years ago

Noted, thank you