golangci / golangci-lint

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

golangci-lint says "File is not `gofmt`-ed", but `gofmt` thinks it's fine #3101

Closed barrettj12 closed 2 years ago

barrettj12 commented 2 years ago

Welcome

Description of the problem

I'm running golangci-lint on this file and it's outputting the error:

$  golangci-lint run ./core/devices/constraints.go
core/devices/constraints.go:42: File is not `gofmt`-ed with `-s` (gofmt)
//    <device-name>=[<count>,]<device-class>|<vendor/type>[,<attributes>]
$

However, when I run gofmt on it, there is no issue:

$ gofmt -d -s ./core/devices/constraints.go                                                     
$

Version of golangci-lint

```console $ golangci-lint --version golangci-lint has version 1.48.0 built from 2d8fea81 on 2022-08-04T18:44:38Z ```

Configuration file

```console $ cat .golangci.yml linters-settings: gci: sections: - standard - default - Prefix(github.com/juju/juju) skip-generated: true gofmt: simplify: true govet: disable-all: true enable: - asmdecl - assign - atomic - bools - buildtag - copylocks - httpresponse - loopclosure - lostcancel - nilfunc - printf - shift - stdmethods - structtag - tests - unmarshal - unreachable - unsafeptr - unusedresult linters: disable-all: true enable: - gci - govet - gofmt - ineffassign - misspell - unconvert - deadcode - varcheck run: timeout: 30m skip-dirs: - acceptancetests ```

Go environment

```console $ go version && go env go version go1.18.5 linux/amd64 GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/runner/.cache/go-build" GOENV="/home/runner/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/runner/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/runner/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/opt/hostedtoolcache/go/1.18.5/x64" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/opt/hostedtoolcache/go/1.18.5/x64/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.18.5" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/runner/work/juju/juju/go.mod" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build144994506=/tmp/go-build -gno-record-gcc-switches" ```

Verbose output of running

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

Code example or link to a public repository

```go // add your code here ```
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.

barrettj12 commented 2 years ago

Another peculiarity is that I can only reproduce this on the GitHub Actions runners, not on my local machine.

bombsimon commented 2 years ago

This is because of a change in Go 1.19 how gofmt format comments: https://go.dev/doc/comment

You're running Go 1.18 locally but GitHub Actions is running Go 1.19. The issue is reproducible with Go 1.19 locally as well.

Dupliacte of #3069

1658 is somewhat related since it's also affected by this change.

Closing in favour of https://github.com/golangci/golangci-lint-action/issues/535