Skip to content

golangci-lint incorrectly complains about Go version being lower than needed (Go workspace) #4894

Closed
@ghost

Description

Welcome

  • Yes, I'm using a binary release within 2 latest releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've read the typecheck section of the FAQ.
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.).
  • I agree to follow this project's Code of Conduct

Description of the problem

go list -m -json outputs multiple JSON documents when in a workspace, but gomoddirectives only decodes the first one. That can lead to golangci-lint wrongly complaining

WARN [linters_context] copyloopvar: this linter is disabled because the Go version (1.20) of your project is lower than Go 1.22
WARN [linters_context] intrange: this linter is disabled because the Go version (1.20) of your project is lower than Go 1.22

file, _ := gomoddirectives.GetModuleFile()

https://github.com/ldez/gomoddirectives/blob/7ed1901522539e1461a03c3237fba32af0f70523/module.go#L24-L33

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.59.1 built with go1.22.3 from 1a55854a on 2024-06-09T18:08:33Z

Configuration

linters:
  enable:
    - asasalint
    - asciicheck
    - bidichk
    - bodyclose
    - canonicalheader
    - containedctx
    - contextcheck
    - copyloopvar
    - decorder
    - dogsled
    - dupword
    - durationcheck
    - err113
    - errcheck
    - errchkjson
    - errname
    - errorlint
    - exhaustive
    - exhaustruct
    - exportloopref
    - fatcontext
    - forbidigo
    - forcetypeassert
    - gci
    - ginkgolinter
    - gocheckcompilerdirectives
    - gochecknoglobals
    - gochecknoinits
    - gochecksumtype
    - goconst
    - gocritic
    - gocyclo
    - godot
    - godox
    - gofmt
    - gofumpt
    - goheader
    - goimports
    - gomoddirectives
    - gomodguard
    - goprintffuncname
    - gosec
    - gosimple
    - gosmopolitan
    - govet
    - grouper
    - importas
    - inamedparam
    - ineffassign
    - interfacebloat
    - intrange
    - ireturn
    - loggercheck
    - maintidx
    - makezero
    - mirror
    - misspell
    - musttag
    - nakedret
    - nestif
    - nilerr
    - nilnil
    - noctx
    - nolintlint
    - nonamedreturns
    - nosprintfhostport
    - paralleltest
    - prealloc
    - predeclared
    - promlinter
    - protogetter
    - reassign
    - revive
    - rowserrcheck
    - sloglint
    - spancheck
    - sqlclosecheck
    - staticcheck
    - stylecheck
    - tagalign
    - tenv
    - testableexamples
    - testifylint
    - testpackage
    - thelper
    - tparallel
    - unconvert
    - unparam
    - unused
    - wastedassign
    - whitespace
    - wrapcheck
    - zerologlint

Go environment

$ go version && go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/xxx/.cache/go-build'
GOENV='/home/xxx/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/xxx/gocode/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/xxx/gocode'
GOPRIVATE=''
GOPROXY='direct'
GOROOT='/home/xxx/go'
GOSUMDB='off'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/xxx/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.5'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/xxx/gosource/app/go.mod'
GOWORK='/home/xxx/gosource/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build634417022=/tmp/go-build -gno-record-gcc-switches'

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
level=info msg="golangci-lint has version 1.59.1 built with go1.22.3 from 1a55854a on 2024-06-09T18:08:33Z"
level=info msg="[config_reader] Config search paths: [./ /home/xxx/gosource/autocrack /home/xxx/gosource /home/xxx /home /]"
level=info msg="[config_reader] Used config file .golangci.yml"
level=info msg="[lintersdb] Active 93 linters: [asasalint asciicheck bidichk bodyclose canonicalheader containedctx contextcheck copyloopvar decorder dogsled dupword durationcheck err113 errcheck errchkjson errname errorlint exhaustive exhaustruct exportloopref fatcontext forbidigo forcetypeassert gci ginkgolinter gocheckcompilerdirectives gochecknoglobals gochecknoinits gochecksumtype goconst gocritic gocyclo godot godox gofmt gofumpt goheader goimports gomoddirectives gomodguard goprintffuncname gosec gosimple gosmopolitan govet grouper importas inamedparam ineffassign interfacebloat intrange ireturn loggercheck maintidx makezero mirror misspell musttag nakedret nestif nilerr nilnil noctx nolintlint nonamedreturns nosprintfhostport paralleltest prealloc predeclared promlinter protogetter reassign revive rowserrcheck sloglint spancheck sqlclosecheck staticcheck stylecheck tagalign tenv testableexamples testifylint testpackage thelper tparallel unconvert unparam unused wastedassign whitespace wrapcheck zerologlint]"
level=info msg="[loader] Go packages loading at mode 575 (compiled_files|exports_file|imports|name|types_sizes|deps|files) took 120.087359ms"
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 967.688µs"
level=warning msg="[linters_context] copyloopvar: this linter is disabled because the Go version (1.20) of your project is lower than Go 1.22"
level=info msg="[linters_context] importas settings found, but no aliases listed. List aliases under alias: key."
level=info msg="[linters_context/goanalysis] analyzers took 6.988948422s with top 10 stages: buildir: 3.312416762s, buildssa: 1.424201739s, the_only_name: 596.519998ms, exhaustive: 427.059617ms, inspect: 245.522072ms, ctrlflow: 196.423534ms, fact_deprecated: 128.238874ms, printf: 102.011834ms, fact_purity: 76.415965ms, nilness: 60.41538ms"
level=warning msg="[linters_context] intrange: this linter is disabled because the Go version (1.20) of your project is lower than Go 1.22"
level=info msg="[runner] Issues before processing: 70, after processing: 0"
level=info msg="[runner] Processors filtering stat (out/in): filename_unadjuster: 70/70, autogenerated_exclude: 70/70, cgo: 70/70, path_prettifier: 70/70, skip_dirs: 70/70, exclude: 70/70, invalid_issue: 70/70, skip_files: 70/70, identifier_marker: 70/70, exclude-rules: 16/70, nolint: 0/16"
level=info msg="[runner] processing took 2.489774ms with stages: nolint: 967.061µs, exclude-rules: 741.818µs, identifier_marker: 651.015µs, path_prettifier: 58.283µs, autogenerated_exclude: 53.146µs, skip_dirs: 6.119µs, invalid_issue: 4.443µs, cgo: 3.747µs, filename_unadjuster: 1.825µs, max_same_issues: 460ns, uniq_by_line: 316ns, fixer: 278ns, sort_results: 186ns, skip_files: 179ns, exclude: 174ns, max_from_linter: 153ns, diff: 145ns, source_code: 112ns, path_shortener: 91ns, max_per_file_from_linter: 81ns, path_prefixer: 73ns, severity-rules: 69ns"
level=info msg="[runner] linters took 3.042585283s with stages: goanalysis_metalinter: 3.040012914s, copyloopvar: 11.791µs, intrange: 7.46µs"
level=info msg="File cache stats: 8 entries of total size 23.3KiB"
level=info msg="Memory: 33 samples, avg is 266.3MB, max is 349.9MB"
level=info msg="Execution took 3.165790382s"

A minimal reproducible example or link to a public repository

// add your code here

Validation

  • Yes, I've included all information above (version, config, etc.).

Supporter

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions