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

Path for gocritic ruleguard rules depends on the current working directory #1662

Closed
oschwald opened this issue Jan 22, 2021 · 1 comment · Fixed by #2308
Closed

Path for gocritic ruleguard rules depends on the current working directory #1662

oschwald opened this issue Jan 22, 2021 · 1 comment · Fixed by #2308
Labels
bug Something isn't working

Comments

@oschwald
Copy link

I am using ruleguard via the gocritic linter. As part of using this linter, you must set the path to your rules:

ruleguard:
# path to a gorules file for the ruleguard checker
rules: ''

Unfortunately, if you currently set a relative path, it will be relative to the directory that you run golangci-lint from. This means that you must always run golangci-lint from the same directory or use an absolute path, which may not work across different environments.

#1572 dealt with a similar issue for custom plugins. It fixed the issue by adding an explicit check to see if the path was relative or absolute.

I looked into doing this for the ruleguard settings, but it appears that the settings code is very generic and doesn't know anything in particular. Would a PR that added a special case to that code for ruleguard be accepted? I would understand if it would be considered in bad taste.

A more general alternative might be if golangci-criitc changed the working directory to the configuration dir directory before running the linters. However, I suspect this would cause other problems.

@oschwald oschwald added the bug Something isn't working label Jan 22, 2021
@sebastien-rosset
Copy link
Contributor

sebastien-rosset commented Feb 15, 2021

I "solved" this by using a mustache template for the golangci.yml file. Before I invoke golangci-lint, I have a golangci.mustache file and use mustache to perform variable substitution and generate a golangci.ym.

    settings:
      ruleguard:
        rules: "{{RULEGUARD_DIR}}/myrules.go"

Though it seems it would be possible to support variable substitution directly in golangci

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants