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

Use path exclude rules on absolute paths instead of relative paths #1178

Closed
xtonyjiang opened this issue Jun 6, 2020 · 7 comments · Fixed by #5339
Closed

Use path exclude rules on absolute paths instead of relative paths #1178

xtonyjiang opened this issue Jun 6, 2020 · 7 comments · Fixed by #5339
Labels
area: exclusions enhancement New feature or improvement

Comments

@xtonyjiang
Copy link

Is your feature request related to a problem? Please describe.
Using path exclude rules is difficult because the issue path depends on which directory I run golangci-lint from.

Describe the solution you'd like
I'd like path exclude rules to be evaluated on the absolute path of the issue, not the relative path that is output.

Describe alternatives you've considered
Can't think of a great alternative here.

Additional context
Example: If I have an exclude rule on a file a/b/c.go, this rule will not apply if I run golangci-lint from directory a/b/.

@xtonyjiang xtonyjiang added the enhancement New feature or improvement label Jun 6, 2020
@boring-cyborg
Copy link

boring-cyborg bot commented Jun 6, 2020

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@majodev
Copy link

majodev commented Sep 21, 2020

Note that this feature would be especially important for editor integrations like VSCode's vscode-go.

Users have no option to control the cwd from which golangci-lint will be executed there (lint of save), it's always going to be the path were the file lives.

Typically, the only configuration that happens there is something like:

"go.lintTool": "golangci-lint",
"go.lintFlags": [
  "--fast",
  "--timeout",
  "5m"
],

@gganley
Copy link

gganley commented Feb 8, 2021

Are there any efforts related to this? It seems like a common enough issue. I can take a crack at it if it's a feature that would be accepted by the golangci team

@stale
Copy link

stale bot commented Mar 30, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale No recent correspondence or work activity label Mar 30, 2022
@ldez ldez removed the stale No recent correspondence or work activity label Mar 30, 2022
@serbrech
Copy link

This is really painful to enable a monorepo global ruleset.
we can't run golangci-lint from the root of the monorepo, so you have to pushd into the module directory, but that means you can't have path based exclude rules in the root config file.

given

/monorepo
    /module1
    /module2
/.golangci.yml

I can't have any path based rules in golangci.yml, because they have to be relative to where the golangci-lint command is being run, which has to be from module1 or module2 folder.

@ldez
Copy link
Member

ldez commented Jan 9, 2025

Why this is not trivial:

home
└── user
    └── john
        └── sources
            └── a
                ├── b
                │   └── c
                │       ├── d.go
                │       └── e.go
                └── c
                    ├── d.go
                    └── f.go

c/d.go will match the 2 absolute paths:

  • /home/user/john/a/b/c/d.go
  • /home/user/john/c/d.go

If you use ^c/d.go, you will match 0 absolute paths.

The option path of the exclude rules (same thing for path-expect, exclude-files, exclude-dirs, etc.) is a regular expression, not a path, so it cannot be "joined" like paths. (ex .*/c/d.go)

You can think "You can use the configuration as reference" to "trim" the report path and have strict matching (^<my expression>$).
But the configuration can be everywhere when using --config or coming from stdin or placed into a parent directory.

We can say "This is always related to the configuration" (and skip the stdin case), but there is problem, this will limit the fact to share the configuration between projects locally (no monorepo here):

sources
├── .golangci.yml
├── projectA
│   └── a
│       └── b
│           └── c.go
├── projectB
│   └── a
│       └── b
│           └── c.go
└── group
        ├── projectC
        │   └── a
        │       └── b
        │           └── c.go
        └── projectD
            └── a
                └── b
                    └── c.go

So this is not a trivial problem.

@xtonyjiang
Copy link
Author

Yay, great to see this get resolved! Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: exclusions enhancement New feature or improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants