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

Relative paths handling is inconsistent between configuration options, hence unable to run golangci-lint from a subdirectory #3717

Open
4 tasks done
misha-ridge opened this issue Mar 23, 2023 · 2 comments
Labels
won't fix This will not be worked on

Comments

@misha-ridge
Copy link
Contributor

misha-ridge commented Mar 23, 2023

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 paths
  • issues.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 if golangci-lint run is called from a subdirectory, these matches are silently skipped
  • linters-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
@misha-ridge misha-ridge added the bug Something isn't working label Mar 23, 2023
@ldez
Copy link
Member

ldez commented Mar 23, 2023

Hello,

we cannot change how the linters manage paths in their configuration: in the majority of cases, we just delegate the configuration to linters. Golangci-lint is a wrapper.

@ldez ldez added won't fix This will not be worked on and removed bug Something isn't working labels Mar 23, 2023
@misha-ridge
Copy link
Contributor Author

misha-ridge commented Mar 23, 2023

run.skip-dirs and issues.exclude-rules.*.path are not coming from linters, they are invented by golangci-lint. These two options are the most problematic and don't have any workarounds.

  • linters-settings.gocritic.ruleguard.rules is from gocritic, but it works, though clunky.
  • linters-settings.depguard.additional-guards.*.ignore-file-rules is from depguard, but it works though very clunky.
  • custom.*.path works.

misha-ridge added a commit to misha-ridge/golangci-lint-langserver that referenced this issue Mar 23, 2023
golangci-lint has issues running in subdirectories of the project,
e.g. golangci/golangci-lint#3656, golangci/golangci-lint#3717, so
running it from the directory where configuration file is located
is the only option for some projects.

Make it work as an option, because not every project triggers this
problem in golangci-lint, so for these projects overhead of
looking up directory of config file and adjusting the paths after
is not needed.
misha-ridge added a commit to misha-ridge/golangci-lint-langserver that referenced this issue Mar 23, 2023
golangci-lint has issues running in subdirectories of the project,
e.g. golangci/golangci-lint#3656, golangci/golangci-lint#3717, so
running it from the directory where configuration file is located
is the only option for some projects.

Make it work as an option, because not every project triggers this
problem in golangci-lint, so for these projects overhead of
looking up directory of config file and adjusting the paths after
is not needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
won't fix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants