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

staticcheck linter does not exclude checks for Go versions greater than specified in go.mod file #4948

Open
6 of 7 tasks
atc0005 opened this issue Aug 23, 2024 · 3 comments
Open
6 of 7 tasks
Labels
bug Something isn't working

Comments

@atc0005
Copy link

atc0005 commented Aug 23, 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

golangci-lint versions greater than v1.59.1 apply staticcheck lints for Go versions greater than that specified in the go.mod file. If I use staticcheck directly (recent versions up to and including v0.5.1), it honors the version of Go specified in the go.mod file.


NOTE:

Yes, I've searched similar issues on GitHub and didn't find any.

Based on what I can tell, I have to check this box to proceed with GH issue submission, though that statement isn't accurate.

I did search issues (and PRs) in this project, and I did find similar issues, but they're marked as resolved:

That they're marked as resolved and do not link to a parent or follow-up GH issue suggests that the problem is believed to be fixed. Submitting this GH issue to provide detailed feedback showing that's unfortunately not the case.

Version of golangci-lint

Tested specifically with two versions.

This version works as expected:

root@db40bb848f57:/go/go-teams-notify# golangci-lint --version
golangci-lint has version 1.59.1 built with go1.22.3 from 1a55854a on 2024-06-09T18:08:33Z

This version does not:

root@db40bb848f57:/go/go-teams-notify# golangci-lint --version
golangci-lint has version 1.60.3 built with go1.23.0 from c2e095c0 on 2024-08-22T21:51:56Z

Configuration

grep -vE '#|^$' .golangci.yml
linters:
  enable:
    - dogsled
    - dupl
    - gocognit
    - goconst
    - gocritic
    - gocyclo
    - gofmt
    - revive
    - gosec
    - nakedret
    - prealloc
    - exportloopref
    - unconvert
    - unparam
    - whitespace
linters-settings:
  funlen:
    lines: 60
    statements: 40
  gocognit:
    min-complexity: 10
  gocyclo:
    min-complexity: 15
  nakedret:
    max-func-lines: 2
  unparam:
    check-exported: true
  unused:
    check-exported: false
  whitespace:
    multi-if: true
    multi-func: true
issues:
  exclude-use-default: false
run:
  tests: false
  modules-download-mode: vendor

Go environment

root@db40bb848f57:/go/go-teams-notify# go version && go env
go version go1.22.6 linux/amd64
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.6'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/go/go-teams-notify/go.mod'
GOWORK=''
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-build3963440304=/tmp/go-build -gno-record-gcc-switches'

Verbose output of running

root@db40bb848f57:/go/go-teams-notify# golangci-lint cache clean
root@db40bb848f57:/go/go-teams-notify# golangci-lint run -v
INFO golangci-lint has version 1.60.3 built with go1.23.0 from c2e095c0 on 2024-08-22T21:51:56Z
INFO [config_reader] Config search paths: [./ /go/go-teams-notify /go / /root]
INFO [config_reader] Used config file .golangci.yml
WARN The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar.
INFO [lintersdb] Active 21 linters: [dogsled dupl errcheck exportloopref gocognit goconst gocritic gocyclo gofmt gosec gosimple govet ineffassign nakedret prealloc revive staticcheck unconvert unparam unused whitespace]
INFO [loader] Go packages loading at mode 575 (deps|files|types_sizes|compiled_files|exports_file|imports|name) took 160.821468ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 6.938107ms
INFO [linters_context/goanalysis] analyzers took 22.528472099s with top 10 stages: buildir: 5.936452266s, the_only_name: 2.198717409s, gocritic: 703.35718ms, dupl: 673.341772ms, gosec: 647.086466ms, unconvert: 493.338621ms, fact_deprecated: 291.609663ms, SA4030: 265.262064ms, buildssa: 262.156467ms, inspect: 240.063887ms
INFO [runner/skip_dirs] Skipped 4 issues from dir examples/adaptivecard/table-with-headers by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 4 issues from dir examples/adaptivecard/toggle-visibility-column-action by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 5 issues from dir examples/adaptivecard/user-mention-verbose by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 3 issues from dir examples/messagecard/basic by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 3 issues from dir examples/adaptivecard/toggle-visibility-single-button by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 4 issues from dir examples/adaptivecard/table-manually-created by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 3 issues from dir examples/messagecard/custom-user-agent by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 4 issues from dir examples/messagecard/proxy by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 3 issues from dir examples/adaptivecard/custom-user-agent by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 3 issues from dir examples/adaptivecard/disable-validation by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 3 issues from dir examples/adaptivecard/toggle-visibility-container-action by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 4 issues from dir examples/adaptivecard/proxy by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 4 issues from dir examples/adaptivecard/table-unordered-grid by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 4 issues from dir examples/adaptivecard/toggle-visibility-multiple-buttons by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 4 issues from dir examples/adaptivecard/user-mention-multiple by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 3 issues from dir examples/messagecard/disable-validation by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 3 issues from dir examples/adaptivecard/basic by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 3 issues from dir examples/adaptivecard/user-mention-single by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 3 issues from dir examples/messagecard/actions by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 3 issues from dir examples/messagecard/custom-validation by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 3 issues from dir examples/adaptivecard/actions by pattern (^|/)examples($|/)
INFO [runner/skip_dirs] Skipped 3 issues from dir examples/adaptivecard/custom-validation by pattern (^|/)examples($|/)
INFO [runner] Issues before processing: 77, after processing: 1
INFO [runner] Processors filtering stat (in/out): fixer: 1/1, sort_results: 1/1, filename_unadjuster: 77/77, invalid_issue: 77/77, exclude: 1/1, nolint: 1/1, max_same_issues: 1/1, diff: 1/1, source_code: 1/1, path_shortener: 1/1, path_prettifier: 77/77, identifier_marker: 1/1, exclude-rules: 1/1, uniq_by_line: 1/1, severity-rules: 1/1, max_from_linter: 1/1, path_prefixer: 1/1, cgo: 77/77, skip_files: 77/77, skip_dirs: 77/1, autogenerated_exclude: 1/1, max_per_file_from_linter: 1/1
INFO [runner] processing took 1.825ms with stages: nolint: 740µs, skip_dirs: 560.1µs, path_prettifier: 234.4µs, source_code: 101µs, autogenerated_exclude: 59µs, identifier_marker: 47.4µs, invalid_issue: 24.5µs, filename_unadjuster: 21.2µs, sort_results: 12.3µs, cgo: 10.4µs, uniq_by_line: 5.2µs, max_same_issues: 3.9µs, path_shortener: 1.8µs, max_from_linter: 900ns, max_per_file_from_linter: 500ns, fixer: 400ns, exclude-rules: 400ns, skip_files: 400ns, path_prefixer: 400ns, exclude: 400ns, diff: 300ns, severity-rules: 100ns
INFO [runner] linters took 3.3697957s with stages: goanalysis_metalinter: 3.367807s
send.go:16:2: SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)
        "io/ioutil"
        ^
INFO File cache stats: 1 entries of total size 21.7KiB
INFO Memory: 37 samples, avg is 240.3MB, max is 318.8MB
INFO Execution took 3.540814878s

A minimal reproducible example or link to a public repository

Steps taken to reproduce:

podman container run --platform linux/amd64 --rm -it golang:1.22.6
git clone https://github.com/atc0005/go-teams-notify
cd go-teams-notify
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.59.1
golangci-lint --version
golangci-lint run
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.60.3
golangci-lint --version
golangci-lint run
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck ./...
sed -i 's/1.14/1.19/' go.mod
go mod tidy
git diff go.mod
staticcheck ./...

If I run staticcheck directly it honors the Go version specified the go.mod file, but not if I use that linter with golangci-lint versions after v1.59.1.

Detailed output below.

$ podman container run --platform linux/amd64 --rm -it golang:1.22.6
Resolving "golang" using unqualified-search registries (/etc/containers/registries.conf)
Trying to pull docker.io/library/golang:1.22.6...
Getting image source signatures
Copying blob 903681d87777 skipped: already exists
Copying blob 3cbbe86a28c2 skipped: already exists
Copying blob 70aa3786ec5f skipped: already exists
Copying blob 288f02cee7a9 skipped: already exists
Copying blob 6ed93aa58a52 skipped: already exists
Copying blob c4c08045297c skipped: already exists
Copying blob 4f4fb700ef54 skipped: already exists
Copying config e39037e2be done
Writing manifest to image destination
Storing signatures
root@db40bb848f57:/go# git clone https://github.com/atc0005/go-teams-notify
Cloning into 'go-teams-notify'...
remote: Enumerating objects: 1824, done.
remote: Counting objects: 100% (469/469), done.
remote: Compressing objects: 100% (232/232), done.
remote: Total 1824 (delta 267), reused 318 (delta 228), pack-reused 1355 (from 1)
Receiving objects: 100% (1824/1824), 711.02 KiB | 2.63 MiB/s, done.
Resolving deltas: 100% (967/967), done.
root@db40bb848f57:/go# cd go-teams-notify
root@db40bb848f57:/go/go-teams-notify# curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.59.1
golangci/golangci-lint info checking GitHub for tag 'v1.59.1'
golangci/golangci-lint info found version: 1.59.1 for v1.59.1/linux/amd64
golangci/golangci-lint info installed /go/bin/golangci-lint
root@db40bb848f57:/go/go-teams-notify# golangci-lint --version
golangci-lint has version 1.59.1 built with go1.22.3 from 1a55854a on 2024-06-09T18:08:33Z
root@db40bb848f57:/go/go-teams-notify# golangci-lint run
root@db40bb848f57:/go/go-teams-notify# curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.60.3
golangci/golangci-lint info checking GitHub for tag 'v1.60.3'
golangci/golangci-lint info found version: 1.60.3 for v1.60.3/linux/amd64
golangci/golangci-lint info installed /go/bin/golangci-lint
root@db40bb848f57:/go/go-teams-notify# golangci-lint --version
golangci-lint has version 1.60.3 built with go1.23.0 from c2e095c0 on 2024-08-22T21:51:56Z
root@db40bb848f57:/go/go-teams-notify# golangci-lint run
WARN The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar.
send.go:16:2: SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)
        "io/ioutil"
        ^

root@db40bb848f57:/go/go-teams-notify# go install honnef.co/go/tools/cmd/staticcheck@latest
go: downloading honnef.co/go/tools v0.5.1
go: downloading golang.org/x/tools v0.21.1-0.20240531212143-b6235391adb3
go: downloading golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678
go: downloading github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c
go: downloading golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
go: downloading golang.org/x/sync v0.7.0
go: downloading golang.org/x/mod v0.17.0
root@db40bb848f57:/go/go-teams-notify# staticcheck ./...
root@db40bb848f57:/go/go-teams-notify#
root@db40bb848f57:/go/go-teams-notify# sed -i 's/1.14/1.19/' go.mod
root@db40bb848f57:/go/go-teams-notify# go mod tidy
go: downloading github.com/stretchr/testify v1.9.0
go: downloading gopkg.in/yaml.v3 v3.0.1
go: downloading github.com/davecgh/go-spew v1.1.1
go: downloading github.com/pmezard/go-difflib v1.0.0
go: downloading gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405
root@db40bb848f57:/go/go-teams-notify# go mod vendor
root@db40bb848f57:/go/go-teams-notify# staticcheck ./...
send.go:16:2: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details.  (SA1019)
send_test.go:14:2: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details.  (SA1019)
root@db40bb848f57:/go/go-teams-notify# git diff go.mod
diff --git a/go.mod b/go.mod
index 548ac9d..56617ef 100644
--- a/go.mod
+++ b/go.mod
@@ -8,6 +8,12 @@

 module github.com/atc0005/go-teams-notify/v2

-go 1.14
+go 1.19

 require github.com/stretchr/testify v1.9.0
+
+require (
+       github.com/davecgh/go-spew v1.1.1 // indirect
+       github.com/pmezard/go-difflib v1.0.0 // indirect
+       gopkg.in/yaml.v3 v3.0.1 // indirect
+)

Validation

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

Supporter

@atc0005 atc0005 added the bug Something isn't working label Aug 23, 2024
@atc0005 atc0005 changed the title staticcheck linter does not exclude checks for Go versions greater than go.mod staticcheck linter does not exclude checks for Go versions greater than specified in go.mod file Aug 23, 2024
@atc0005
Copy link
Author

atc0005 commented Aug 23, 2024

See also:

EDIT:

Does not appear related after all.

@ldez
Copy link
Member

ldez commented Aug 23, 2024

It is expected: currently the version doesn't depend on go.mod but on the version of Go used to compile.

This is explained here: #4907 (comment)

@atc0005
Copy link
Author

atc0005 commented Aug 23, 2024

Hi @ldez,

I reviewed your notes from that PR, but it wasn't apparent to me that the behavior is as you noted here. Thank you for clarifying.

I'll continue to ignore the reported issues for affected projects until the root issue is resolved.

Thanks for taking the time to respond and provide the additional details!

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