Skip to content

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

Closed
@barrettj12

Description

@barrettj12

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions