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 incorrectly complains about Go version being lower than needed (Go workspace) #4894

Open
6 of 7 tasks
ghost opened this issue Aug 8, 2024 · 5 comments
Open
6 of 7 tasks
Labels
question Further information is requested

Comments

@ghost
Copy link

ghost commented Aug 8, 2024

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

@ghost ghost added the bug Something isn't working label Aug 8, 2024
Copy link

boring-cyborg bot commented Aug 8, 2024

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

@ldez ldez added question Further information is requested and removed bug Something isn't working labels Aug 8, 2024
@ldez
Copy link
Member

ldez commented Aug 8, 2024

Hello,

You checked:

[x] Yes, I've included all the information above (version, config, etc.).

But you didn't provide the required minimal reproducible example or link to a public repository.

You can use the following option:

run:
  go: '1.22'

@ldez ldez changed the title golangci-lint incorrectly complains about Go version being lower than needed golangci-lint incorrectly complains about Go version being lower than needed (Go workspace) Aug 8, 2024
@ghost
Copy link
Author

ghost commented Aug 8, 2024

To reproduce:

$ mkdir golangci
$ cd golangci
$ go work init
$ mkdir a b
$ echo module a > a/go.mod
$ echo go 1.20 >> a/go.mod
$ echo module b > b/go.mod
$ echo go 1.22 >> b/go.mod
$ echo package main > b/main.go
$ go work use a
$ go work use b
$ cd b
$ golangci-lint run --enable=copyloopvar,intrange
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 

@TaylorBarrick

This comment was marked as off-topic.

@ldez

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants