Skip to content

Exclusion rules break if config is in parent directory #5628

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

Closed
6 of 7 tasks
abhinav opened this issue Mar 25, 2025 · 1 comment · Fixed by #5629
Closed
6 of 7 tasks

Exclusion rules break if config is in parent directory #5628

abhinav opened this issue Mar 25, 2025 · 1 comment · Fixed by #5629
Assignees
Labels
area: exclusions bug Something isn't working

Comments

@abhinav
Copy link

abhinav commented Mar 25, 2025

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

How did you install golangci-lint?

I don't know

Description of the problem

With v2, if a rule in linters.exclusions.rules contains source: ... matches, and the tool is invoked from a subdirectory (instead of the directory where the .golangci.yml resides), the exclusions are ignored and a warning similar to the following is printed:

WARN [runner/exclusion_rules] Failed to get line bar/bar.go:11 from line cache: failed to get file bar/bar.go lines cache: can't get file bar/bar.go bytes from cache: can't read file bar/bar.go: open bar/bar.go: no such file or directory

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 2.0.1 built with go1.24.1 from e8927ce2 on 2025-03-24T20:34:31Z

Configuration

version: "2"

linters:
  exclusions:
    rules:
      - linters: [errcheck]
        text: Error return value of `[^`]+.Close` is not checked
        source: ^\s*defer\s

Go environment

$ go version && go env
go version go1.24.1 darwin/arm64
AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/abhinav/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/abhinav/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/pd/cc8pg8hn42vg9dz7r_84t_rm0000gn/T/go-build1105924328=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/abhinav/src/exp/golangci-lint-v2-repro/go.mod'
GOMODCACHE='/Users/abhinav/go/pkg/mod'
GOOS='darwin'
GOPATH='/Users/abhinav/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/abhinav/.local/share/mise/installs/go/1.24.1'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/Users/abhinav/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/abhinav/.local/share/mise/installs/go/1.24.1/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.1'
GOWORK=''
PKG_CONFIG='pkg-config'

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO golangci-lint has version 2.0.1 built with go1.24.1 from e8927ce2 on 2025-03-24T20:34:31Z
INFO [config_reader] Config search paths: [./ /Users/abhinav/src/exp/golangci-lint-v2-repro/bar /Users/abhinav/src/exp/golangci-lint-v2-repro /Users/abhinav/src/exp /Users/abhinav/src /Users/abhinav /Users /]
INFO [config_reader] Used config file ../.golangci.yml
INFO maxprocs: Leaving GOMAXPROCS=10: CPU quota undefined
INFO [goenv] Read go env for 5.933667ms: map[string]string{"GOCACHE":"/Users/abhinav/Library/Caches/go-build", "GOROOT":"/Users/abhinav/.local/share/mise/installs/go/1.24.1"}
INFO [lintersdb] Active 5 linters: [errcheck govet ineffassign staticcheck unused]
INFO [loader] Go packages loading at mode 8767 (name|types_sizes|compiled_files|exports_file|files|imports|deps) took 454.833417ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 900.5µs
INFO [linters_context/goanalysis] analyzers took 481.463863ms with top 10 stages: buildir: 297.471829ms, printf: 28.921206ms, ctrlflow: 27.20283ms, fact_deprecated: 26.42971ms, SA5012: 24.823462ms, fact_purity: 23.408038ms, nilness: 16.751123ms, inspect: 15.411585ms, typedness: 14.123455ms, tokenfileanalyzer: 4.07767ms
WARN [runner/exclusion_rules] Failed to get line bar/bar.go:11 from line cache: failed to get file bar/bar.go lines cache: can't get file bar/bar.go bytes from cache: can't read file bar/bar.go: open bar/bar.go: no such file or directory
INFO [runner/exclusion_rules] Skipped 0 issues by rules: [Text: "Error return value of `[^`]+.Close` is not checked", Source: "^\\s*defer\\s", Linters: "errcheck"]
INFO [runner] Processors filtering stat (in/out): diff: 1/1, path_prettifier: 1/1, filename_unadjuster: 1/1, invalid_issue: 1/1, nolint_filter: 1/1, max_per_file_from_linter: 1/1, max_from_linter: 1/1, severity-rules: 1/1, path_absoluter: 1/1, cgo: 1/1, exclusion_paths: 1/1, fixer: 1/1, max_same_issues: 1/1, source_code: 1/1, path_relativity: 1/1, generated_file_filter: 1/1, exclusion_rules: 1/1, uniq_by_line: 1/1, path_shortener: 1/1, sort_results: 1/1
INFO [runner] processing took 98.418µs with stages: nolint_filter: 24.292µs, generated_file_filter: 20.708µs, exclusion_rules: 17.792µs, cgo: 14.25µs, source_code: 13µs, sort_results: 3.25µs, path_relativity: 1.291µs, uniq_by_line: 1.167µs, max_same_issues: 500ns, path_shortener: 459ns, invalid_issue: 375ns, fixer: 292ns, filename_unadjuster: 209ns, max_from_linter: 209ns, exclusion_paths: 167ns, path_absoluter: 167ns, max_per_file_from_linter: 124ns, diff: 83ns, path_prettifier: 83ns, severity-rules: 0s
INFO [runner] linters took 404.248375ms with stages: goanalysis_metalinter: 404.117459ms
bar/bar.go:11:15: Error return value of `f.Close` is not checked (errcheck)
        defer f.Close()
                     ^
1 issues:
* errcheck: 1
INFO File cache stats: 1 entries of total size 114B
INFO Memory: 10 samples, avg is 107.4MB, max is 289.1MB
INFO Execution took 866.396291ms

A minimal reproducible example or link to a public repository

Given the following layout:

-- go.mod --
module example.com/foo

go 1.24.1

-- .golangci.yml --
version: "2"

linters:
  exclusions:
    rules:
      - linters: [errcheck]
        text: Error return value of `[^`]+.Close` is not checked
        source: ^\s*defer\s

-- foo.go --
package foo

import "os"

func Foo() {
	f, err := os.Open("foo")
	if err != nil {
		return
	}

	defer f.Close()
}

-- bar/bar.go --
package foo

import "os"

func Bar() {
	f, err := os.Open("foo")
	if err != nil {
		return
	}

	defer f.Close()
}

golangci-lint run from the root directory passes just fine, but from the bar directory fails with:

❮ golangci-lint run
WARN [runner/exclusion_rules] Failed to get line bar/bar.go:11 from line cache: failed to get file bar/bar.go lines cache: can't get file bar/bar.go bytes from cache: can't read file bar/bar.go: open bar/bar.go: no such file or directory
bar/bar.go:11:15: Error return value of `f.Close` is not checked (errcheck)
        defer f.Close()

Validation

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

Supporter

@abhinav abhinav added the bug Something isn't working label Mar 25, 2025
Copy link

boring-cyborg bot commented Mar 25, 2025

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 bug Something isn't working area: exclusions and removed bug Something isn't working question Further information is requested labels Mar 25, 2025
@ldez ldez self-assigned this Mar 25, 2025
@ldez ldez changed the title [v2] exclusion rules break if config is in parent directory Exclusion rules break if config is in parent directory Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: exclusions bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants