Closed
Description
Welcome
- Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
- Yes, I've searched similar issues on GitHub and didn't find any.
- Yes, I've included all information below (version, config, etc.).
- Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.). (https://golangci-lint.run/usage/linters/)
Description of the problem
There are several places in golangci-lint
where paths are specified, including:
run.skip-dirs
pathsissues.exclude-rules.*.path
linters-settings.gocritic.ruleguard.rules
linters-settings.depguard.additional-guards.*.ignore-file-rules
custom.*.path
The handling of these paths is inconsistent, leading to various issues when golangci-lint run
is run from the directory other than the one containing the .golangci-lint.yml
:
run.skip-dirs
,issues.exclude-rules.*.path
are matched textually, so ifgolangci-lint run
is called from a subdirectory, these matches are silently skippedlinters-settings.gocritic.ruleguard.rules
accepts{configDir}
to make it look up proper ruleguard config file. However this directive does not seem to be accepted in any other places of the configuration file.linters-settings.depguard.additional-guards.*.ignore-file-rules
appear to match full file paths.custom.*.path
seem to always be relative to the configuration file, so at least this configuration works.
As it stands, the only way to run golangci-lint run
from a subdirectory is to avoid any paths in configuration file, except ruleguard
and custom linters.
It would be very useful to make all paths in configuration file behave the same. Treating them as relative to the location of the configuration file appears to be the most reasonable option.
There is already one issue for a specific case of path excludes: #1178, however this issue is more general.
Version of golangci-lint
golangci-lint has version v1.51.0 built from (unknown, mod sum: "h1:M1bpDymgdaPKNzPwQdebCGki/nzvVkr2f/eUfk9C9oU=") on (unknown)
Configuration file
run:
skip-dirs:
- some/path # matched textually, won't be matched if run as `cd some && golangci-lint run`
issues:
exclude-rules:
- path: some/other/path # matched textually, won't be matched if run as `cd some && golangci-lint run`
linters:
- errcheck
linters-settings:
gocritic:
settings:
ruleguard:
rules: "${configDir}/ruleguard.go" # this works due to ${configDir}
depguard:
additional-guards:
- list-type: denylist
ignore-file-rules:
# There is no way to anchor the match to the root of the repository!
- "**/some/third/path/*.go" # this seems to match full paths, unlike everything else
custom:
mycustomlinter:
path: ./customlinter.so # this seems to be relative to the configuration file