-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
nolintlint: reports false positive warnings about used nolint directive #3228
Comments
Hello, I change some elements related to facts (they are used by staticcheck) maybe the problem will be fixed with the next release (v1.50.0) |
The issue happend again with golangci-lint 1.50.0. |
This comment was marked as off-topic.
This comment was marked as off-topic.
The lint task was failing at head, due to a nolint:exhaustive error directive that golangci nolintlint believes is unused. Issue seems to be golangci/golangci-lint#3228 and seems to be a bug in golang-ci / nolintlint.
The lint task was failing at head, due to a nolint:exhaustive error directive that golangci nolintlint believes is unused. Issue seems to be golangci/golangci-lint#3228 and seems to be a bug in golang-ci / nolintlint, using the workaround proposed in golangci/golangci-lint#1940 which is to clear the cache between runs.
golangci/golangci-lint#3228 Signed-off-by: Andrew Haines <[email protected]>
golangci/golangci-lint#3228 Signed-off-by: Andrew Haines <[email protected]>
golangci/golangci-lint#3228 Signed-off-by: Andrew Haines <[email protected]>
…ons (#1778) * Unify type of `request` in expressions * Support `P.derivedRoles` in checks * Add `yaml-language-server` modelines to query planner test policies * Support `P.derivedRoles` in plans * Add documentation * Fix broken link in v0.3.0 release notes * Disable flaky unused `nolint` detection golangci/golangci-lint#3228 * Support `request.auxData` as well as `request.aux_data` in plans * Rename to `runtime.effectiveDerivedRoles`, and compute lazily Signed-off-by: Andrew Haines <[email protected]>
Happened with golangci-lint v1.54.2, too. |
Hitting golangci/golangci-lint#3228 when adding nolint.
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints.
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints.
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints.
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints.
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints.
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints.
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints.
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints. (cherry picked from commit 31b0732)
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints.
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints.
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints.
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints.
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints. (cherry picked from commit 4336f38)
Have this issue also when dealing with switch/case: |
If you are facing the same problem, the best way to contribute is to provide the following information:
And a code example or link to a public repository. |
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints. (cherry picked from commit 4336f38)
Here's a reliable repro: #!/bin/sh -e
## setup module
rm -rf nolintrepro
mkdir nolintrepro && cd $_
## go.mod
cat > go.mod <<EOF
module example.com/nolintrepro
go 1.21
require github.com/jackc/pgx/v5 v5.5.3
require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
EOF
## main.go
cat > main.go <<EOF
package main
import (
"fmt"
"github.com/jackc/pgx/v5"
)
func main() {
var conn *pgx.Conn
fmt.Println(conn.PgConn().CheckConn() == nil)
fmt.Println(conn.PgConn().CheckConn() == nil) //nolint: staticcheck
}
EOF
go mod tidy
## .golangci.yml
cat > .golangci.yml <<EOF
linters:
disable-all: true
enable:
- staticcheck
- nolintlint
EOF
## Run
golangci-lint run
## Clean
cd ..
rm -rf nolintrepro version and env$ go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
$ golangci-lint --version
golangci-lint has version v1.56.2 built with go1.22.0 from (unknown, mod sum: "h1:dgQzlWHgNbCqJjuxRJhFEnHDVrrjuTGQHJ3RIZMpp/o=") on (unknown) $ go version && go env
go version go1.22.0 darwin/arm64
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/me/Library/Caches/go-build'
GOENV='/Users/me/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/me/.local/share/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/me/.local/share/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.0/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.0/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/me/nolintrepro/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/yd/g6bkd_fd7qs40y6q_8w2fh2w0000gn/T/go-build3765820227=/tmp/go-build -gno-record-gcc-switches -fno-common' $ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /Users/me/nolintrepro /Users/me /Users /]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 2 linters: [nolintlint staticcheck]
INFO [loader] Go packages loading at mode 575 (deps|name|types_sizes|compiled_files|exports_file|files|imports) took 523.977875ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 161µs
INFO [linters_context/goanalysis] analyzers took 2.663033296s with top 10 stages: buildir: 2.039481668s, fact_deprecated: 150.111285ms, nilness: 126.620753ms, fact_purity: 125.42288ms, SA5012: 115.692744ms, typedness: 103.558214ms, SA4006: 222µs, isgenerated: 130.292µs, SA4027: 99.542µs, SA9004: 88.75µs
INFO [runner] Issues before processing: 3, after processing: 1
INFO [runner] Processors filtering stat (out/in): path_shortener: 1/1, cgo: 3/3, filename_unadjuster: 3/3, uniq_by_line: 1/1, nolint: 1/3, severity-rules: 1/1, fixer: 1/1, skip_files: 3/3, autogenerated_exclude: 3/3, exclude: 3/3, max_from_linter: 1/1, skip_dirs: 3/3, identifier_marker: 3/3, diff: 1/1, max_same_issues: 1/1, source_code: 1/1, path_prefixer: 1/1, sort_results: 1/1, path_prettifier: 3/3, exclude-rules: 3/3, max_per_file_from_linter: 1/1
INFO [runner] processing took 519.497µs with stages: exclude-rules: 189.292µs, nolint: 94.251µs, autogenerated_exclude: 71.416µs, identifier_marker: 69.291µs, source_code: 52.833µs, path_prettifier: 31.583µs, skip_dirs: 4.959µs, uniq_by_line: 1.417µs, cgo: 1.041µs, max_same_issues: 749ns, path_shortener: 458ns, max_from_linter: 417ns, filename_unadjuster: 292ns, sort_results: 292ns, diff: 209ns, fixer: 208ns, max_per_file_from_linter: 208ns, skip_files: 167ns, severity-rules: 166ns, exclude: 166ns, path_prefixer: 82ns
INFO [runner] linters took 1.05964275s with stages: goanalysis_metalinter: 1.059068917s
main.go:11:14: SA1019: conn.PgConn().CheckConn is deprecated: CheckConn is deprecated in favor of Ping. CheckConn cannot detect all types of broken connections where the write would still appear to succeed. Prefer Ping unless on a high latency connection. (staticcheck)
fmt.Println(conn.PgConn().CheckConn() == nil)
^
INFO File cache stats: 1 entries of total size 213B
INFO Memory: 19 samples, avg is 131.1MB, max is 309.6MB
INFO Execution took 1.774828083s This is the correct behavior— But if we modify the file (which I assume affects the cache), we get the incorrect behavior. I added a newline after
Now it complains about the unused If you run |
Thank you for the repro. As a workaround for issues:
exclude-rules:
- linters:
- staticcheck
text: "SA1019: conn.PgConn().CheckConn is deprecated: CheckConn is deprecated in favor of Ping" Side note: a directive should not contain space after the
|
Seeing this in combination with pkg/mything.go:9:78: directive `//nolint:ireturn // Returns one of multiple types which implement MyThinger.` is unused for linter "ireturn" (nolintlint)
func Testfunc() MyThinger { //nolint:ireturn // Returns one of multiple types which implement MyThinger. |
May be related to #3476 @stevenh If you are facing the same problem, the best way to contribute is to provide the following information:
And a code example or link to a public repository. |
Hitting golangci/golangci-lint#3228 when adding nolint. So allow to ignore unused nolints.
Instead of using `//nolint:ireturn` the linter allows a use of `generic` return types (on top of the listed defaults which now have been explicitly set). This approach also eliminates a re-occuring issue where `nolintlint` reports aforementioned directive as not used by defined linter. Related issue: golangci/golangci-lint#3228 On top of that we have `--fix` flag enabled for golangci-lint runner. This results in removal of these comments as `nolintlint` tries to autofix. As a consequence the subsequent run of `make lint` yields errors for previously disabled linters and the cycle continues :) > [!IMPORTANT] > This behaviour has also been observed for other linters. As part of this the declarations of kustomize plugin constructor funcs has been reworkted to return struct pointers instead.
Instead of using `//nolint:ireturn` the linter allows a use of `generic` return types (on top of the listed defaults which now have been explicitly set). This approach also eliminates a re-occuring issue where `nolintlint` reports aforementioned directive as not used by defined linter. Related issue: golangci/golangci-lint#3228 On top of that we have `--fix` flag enabled for golangci-lint runner. This results in removal of these comments as `nolintlint` tries to autofix. As a consequence the subsequent run of `make lint` yields errors for previously disabled linters and the cycle continues :) > [!IMPORTANT] > This behaviour has also been observed for other linters. As part of this the declarations of kustomize plugin constructor funcs has been reworkted to return struct pointers instead. \#stack-pr
Instead of using `//nolint:ireturn` the linter allows a use of `generic` return types (on top of the listed defaults which now have been explicitly set). This approach also eliminates a re-occuring issue where `nolintlint` reports aforementioned directive as not used by defined linter. Related issue: golangci/golangci-lint#3228 On top of that we have `--fix` flag enabled for golangci-lint runner. This results in removal of these comments as `nolintlint` tries to autofix. As a consequence the subsequent run of `make lint` yields errors for previously disabled linters and the cycle continues :) > [!IMPORTANT] > This behaviour has also been observed for other linters. As part of this the declarations of kustomize plugin constructor funcs has been reworkted to return struct pointers instead. The reason for this is that in our feature branch we are relying on kustomize plugins and want to iterate over a slice of resmap.Transfomers but in the current form these functions cannot be used due to the fact that structs returned have pointer receivers. From the current functionality standpoint (on incubation branch) this change is harmless.
Instead of using `//nolint:ireturn` the linter allows a use of `generic` return types (on top of the listed defaults which now have been explicitly set). This approach also eliminates a re-occuring issue where `nolintlint` reports aforementioned directive as not used by defined linter. Related issue: golangci/golangci-lint#3228 On top of that we have `--fix` flag enabled for golangci-lint runner. This results in removal of these comments as `nolintlint` tries to autofix. As a consequence the subsequent run of `make lint` yields errors for previously disabled linters and the cycle continues :) > [!IMPORTANT] > This behaviour has also been observed for other linters. As part of this the declarations of kustomize plugin constructor funcs has been reworkted to return struct pointers instead. The reason for this is that in our feature branch we are relying on kustomize plugins and want to iterate over a slice of resmap.Transfomers but in the current form these functions cannot be used due to the fact that structs returned have pointer receivers. From the current functionality standpoint (on incubation branch) this change is harmless.
) Instead of using `//nolint:ireturn` the linter allows a use of `generic` return types (on top of the listed defaults which now have been explicitly set). This approach also eliminates a re-occuring issue where `nolintlint` reports aforementioned directive as not used by defined linter. Related issue: golangci/golangci-lint#3228 On top of that we have `--fix` flag enabled for golangci-lint runner. This results in removal of these comments as `nolintlint` tries to autofix. As a consequence the subsequent run of `make lint` yields errors for previously disabled linters and the cycle continues :) > [!IMPORTANT] > This behaviour has also been observed for other linters. As part of this the declarations of kustomize plugin constructor funcs has been reworkted to return struct pointers instead. The reason for this is that in our feature branch we are relying on kustomize plugins and want to iterate over a slice of resmap.Transfomers but in the current form these functions cannot be used due to the fact that structs returned have pointer receivers. From the current functionality standpoint (on incubation branch) this change is harmless. (cherry picked from commit 613d552)
) Instead of using `//nolint:ireturn` the linter allows a use of `generic` return types (on top of the listed defaults which now have been explicitly set). This approach also eliminates a re-occuring issue where `nolintlint` reports aforementioned directive as not used by defined linter. Related issue: golangci/golangci-lint#3228 On top of that we have `--fix` flag enabled for golangci-lint runner. This results in removal of these comments as `nolintlint` tries to autofix. As a consequence the subsequent run of `make lint` yields errors for previously disabled linters and the cycle continues :) > [!IMPORTANT] > This behaviour has also been observed for other linters. As part of this the declarations of kustomize plugin constructor funcs has been reworkted to return struct pointers instead. The reason for this is that in our feature branch we are relying on kustomize plugins and want to iterate over a slice of resmap.Transfomers but in the current form these functions cannot be used due to the fact that structs returned have pointer receivers. From the current functionality standpoint (on incubation branch) this change is harmless. (cherry picked from commit 613d552)
Welcome
Description of the problem
We have staticcheck and nonolint enabled.
Sometimes in our CI builds golangci-lint reports a false warnings from nonolint about unused
nolint:staticcheck
comments.All warnings that I checked are wrong, the
//nolint:staticcheck
directives always silence existing deprecation warnings from staticcheck.I was not able to reproduce this issue.
In CI we reuse the golangci-lint and go cache when running checks on different branches.
It can happen that the same cache was used previously with older go and/or golangci-lint versions.
I believe #1940 (comment) refers to the same issue.
Version of golangci-lint
Configuration file
Go environment
Verbose output of running
N/A
Code example or link to a public repository
Example case, output from golangci-lint:
The referenced Description field has a deprecation comment set:
The text was updated successfully, but these errors were encountered: