golangci / golangci-lint

Fast linters runner for Go
https://golangci-lint.run
GNU General Public License v3.0
15.66k stars 1.39k forks source link

`exclude-dirs` not working #5015

Closed nekohasekai closed 1 month ago

nekohasekai commented 1 month ago

Welcome

Description of the problem

exclude-dirs seems to be ignored since v1.60.0, the same steps worked fine in v1.59.0 with go1.22.7.

Version of golangci-lint

```console $ golangci-lint --version # golangci-lint has version v1.61.0 built with go1.23.1 from (unknown, modified: ?, mod sum: "h1:VvbOLaRVWmyxCnUIMTbf1kDsaJbTzH20FAMXTAlQGu8=") on (unknown) ```

Configuration

```console golangci-lint run --exclude-dirs bugpkg ```

Go environment

```console $ go version && go env go version go1.23.1 darwin/arm64 GO111MODULE='' GOARCH='arm64' GOBIN='' GOCACHE='/Users/sekai/Library/Caches/go-build' GOENV='/Users/sekai/Library/Application Support/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='arm64' GOHOSTOS='darwin' GOINSECURE='' GOMODCACHE='/Users/sekai/go/pkg/mod' GONOPROXY='' GONOSUMDB='' GOOS='darwin' GOPATH='/Users/sekai/go' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/opt/homebrew/Cellar/go/1.23.1/libexec' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='local' GOTOOLDIR='/opt/homebrew/Cellar/go/1.23.1/libexec/pkg/tool/darwin_arm64' GOVCS='' GOVERSION='go1.23.1' GODEBUG='' GOTELEMETRY='local' GOTELEMETRYDIR='/Users/sekai/Library/Application Support/go/telemetry' GCCGO='gccgo' GOARM64='v8.0' AR='ar' CC='cc' CXX='c++' CGO_ENABLED='1' GOMOD='/dev/null' 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/62/0rdd_81n5jbf6j4w3pcmwycr0000gn/T/go-build3375113623=/tmp/go-build -gno-record-gcc-switches -fno-common' ```

Verbose output of running

```console $ golangci-lint cache clean $ golangci-lint run --exclude-dirs bugpkg/ -v INFO golangci-lint has version v1.61.0 built with go1.23.1 from (unknown, modified: ?, mod sum: "h1:VvbOLaRVWmyxCnUIMTbf1kDsaJbTzH20FAMXTAlQGu8=") on (unknown) INFO [config_reader] Config search paths: [./ /Users/sekai/Projects/lintbug /Users/sekai/Projects /Users/sekai /Users /] INFO [lintersdb] Active 6 linters: [errcheck gosimple govet ineffassign staticcheck unused] INFO [loader] Go packages loading at mode 575 (compiled_files|deps|exports_file|imports|files|name|types_sizes) took 80.058458ms INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 83.375µs INFO [linters_context/goanalysis] analyzers took 12.492663ms with top 10 stages: ctrlflow: 874.917µs, fact_deprecated: 609.834µs, printf: 565.625µs, SA4006: 494.626µs, buildir: 494.208µs, SA4000: 467.583µs, timeformat: 366.75µs, inspect: 340.75µs, SA9002: 327.583µs, S1008: 325.626µs INFO [runner] Issues before processing: 170, after processing: 1 INFO [runner] Processors filtering stat (in/out): nolint: 170/170, max_same_issues: 1/1, path_prefixer: 1/1, sort_results: 1/1, autogenerated_exclude: 170/170, path_prettifier: 170/170, skip_files: 170/170, exclude: 170/170, exclude-rules: 170/170, severity-rules: 1/1, invalid_issue: 170/170, diff: 1/1, path_shortener: 1/1, fixer: 1/1, identifier_marker: 170/170, filename_unadjuster: 170/170, skip_dirs: 170/170, uniq_by_line: 170/1, max_per_file_from_linter: 1/1, max_from_linter: 1/1, source_code: 1/1, cgo: 170/170 INFO [runner] processing took 2.395041ms with stages: identifier_marker: 2.2965ms, path_prettifier: 47.749µs, source_code: 12.375µs, nolint: 7.459µs, cgo: 5.249µs, invalid_issue: 4.459µs, filename_unadjuster: 4.416µs, uniq_by_line: 3.917µs, skip_dirs: 3.876µs, autogenerated_exclude: 3.251µs, exclude-rules: 2.541µs, path_shortener: 876ns, max_same_issues: 750ns, max_from_linter: 374ns, max_per_file_from_linter: 291ns, diff: 250ns, skip_files: 208ns, exclude: 167ns, sort_results: 167ns, fixer: 125ns, severity-rules: 41ns, path_prefixer: 0s INFO [runner] linters took 18.300208ms with stages: goanalysis_metalinter: 15.869416ms bugpkg/bug.go:3:10: could not import golang.org/x/sys/windows (-: build constraints exclude all Go files in /Users/sekai/go/pkg/mod/golang.org/x/sys@v0.25.0/windows) (typecheck) import _ "golang.org/x/sys/windows" ^ INFO File cache stats: 1 entries of total size 52B INFO Memory: 3 samples, avg is 29.4MB, max is 30.9MB INFO Execution took 103.869042ms ```

A minimal reproducible example or link to a public repository

go.mod ```go.mod module lintbug go 1.23.1 require golang.org/x/sys v0.25.0 ``` main.go ```go package main func main() { println("Hello world") } ``` bugpkg/bug.go ```go package bugpkg import _ "golang.org/x/sys/windows" // some platform specified code without //go:build ``` ```console $ golangci-lint run --exclude-dirs bugpkg bugpkg/bug.go:3:10: could not import golang.org/x/sys/windows (-: build constraints exclude all Go files in /Users/sekai/go/pkg/mod/golang.org/x/sys@v0.25.0/windows) (typecheck) import _ "golang.org/x/sys/windows" ^ ```

Validation

Supporter

ldez commented 1 month ago

hello, typecheck errors cannot be ignored, this section of the FAQ explains why: https://golangci-lint.run/welcome/faq/#why-is-it-not-possible-to-skipignore-typecheck-errors

joaopapereira commented 1 month ago

I'm not 100% sure I understand this restriction. Shouldn't golangci-lint respect the user's request to exclude directories?

ldez commented 1 month ago

If you try to compile, it's not possible to exclude a file (except with build tags), it's the same thing for golangci-lint.

Please read https://golangci-lint.run/welcome/faq/#why-is-it-not-possible-to-skipignore-typecheck-errors