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

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

Closed
4 tasks done
barrettj12 opened this issue Aug 16, 2022 · 3 comments
Closed
4 tasks done
Labels
bug Something isn't working

Comments

@barrettj12
Copy link

barrettj12 commented Aug 16, 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'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

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

Configuration file

$ 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

$ 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

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

Code example or link to a public repository

// add your code here
@barrettj12 barrettj12 added the bug Something isn't working label Aug 16, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 16, 2022

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

@barrettj12 barrettj12 changed the title golangci-lint says and Go's `go golangci-lint says "File is not gofmt-ed", but gofmt thinks it's fine Aug 16, 2022
@barrettj12
Copy link
Author

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

@bombsimon
Copy link
Member

bombsimon commented Aug 16, 2022

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 golangci/golangci-lint-action#535

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants