-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix: consider path prefix when matching path patterns #3571
Conversation
Hey, thank you for opening your first Pull Request ! |
@ldez: I also looked at I think this is ready for review now. |
In case someone wonders: the reason why the directory has to be changed in the Kubernetes repo is that |
When someone invokes golangci-lint in a sub-directory, they can set the path prefix to make the output look like the invocation had been done in the root. But this prefix was ignored when checking path patterns of exclude, severity, and skip files/dirs entries, so those with matching for directories only worked when golangci-lint was always invoked in the same directory. The underlying problem is that the rules from the configuration get checked before updating the path associated with the issues in the path fixer. To make the prefix work, it now gets passed down into processors and added there to the issue path before checking against the path pattern. For exclude and severity rules, this could have been done through a separate parameter, but bundling it in a new fsutils helper struct made the change a bit smaller.
3ae5acb
to
3107130
Compare
The path prefixer test failed on Windows because I was using "path.Join", not "path/filepath.Join" as before. This change should fix that: diff --git a/pkg/fsutils/files.go b/pkg/fsutils/files.go
index 542af531..3d369a23 100644
--- a/pkg/fsutils/files.go
+++ b/pkg/fsutils/files.go
@@ -1,6 +1,6 @@
package fsutils
-import "path"
+import "path/filepath"
// Files combines different operations related to handling file paths and
// content.
@@ -32,5 +32,5 @@ func WithPathPrefix(pathPrefix, relativePath string) string {
if pathPrefix == "" {
return relativePath
}
- return path.Join(pathPrefix, relativePath)
+ return filepath.Join(pathPrefix, relativePath)
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your approach can be extended to the Fixer processor, can try to fix the Fixer?
Co-authored-by: Ludovic Fernandez <[email protected]>
The problem with the fixer processor seems to be that it runs after the path prefixer (#3626). That leads to the inverse problem of what I am solving here: the fixer sees the path with prefix which doesn't match the correct path relative to the current working directory, whereas severity and exclude processors (before this PR) see the path without the prefix when they need it with prefix. The fix for the fixer in the PR above is to strip the prefix again. That doesn't seem ideal. Perhaps a simpler solution is to move the path prefixing and sorting out of the normal set of processors and do that after fixing? Either way, such a fix doesn't need to be in this PR. Thanks for the comment fixes, I included all of them in this commit - I prefer to keep the commit history clean. Let me know if you prefer it otherwise and I can restore them as a separate commit. |
I prefer to have fixes as commits, it's easier to follow the review. |
Okay, I added the second commit with the comment changes. BTW, should I also rebase each time I do a push to avoid having to merge with master? |
I prepared a separate PR with my idea of fixing the fixer. It's unrelated to the changes in this PR, but there will be a slight merge conflict. I can also add those other changes here, if you prefer a single PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LTGM
This patch enables the golangci-lint checks for csi-wrapper. The version of golangci-lint is bumped to v1.52.2, since the old version has a bug when processing the --prefix-path option, which is necessary to run the lint tool in sub modules. golangci/golangci-lint#3571 Signed-off-by: Yohei Ueda <[email protected]>
This patch enables the golangci-lint checks for csi-wrapper. The version of golangci-lint is bumped to v1.52.2, since the old version has a bug when processing the --prefix-path option, which is necessary to run the lint tool in sub modules. golangci/golangci-lint#3571 Signed-off-by: Yohei Ueda <[email protected]>
This patch enables the golangci-lint checks for csi-wrapper. The version of golangci-lint is bumped to v1.52.2, since the old version has a bug when processing the --prefix-path option, which is necessary to run the lint tool in sub modules. golangci/golangci-lint#3571 Signed-off-by: Yohei Ueda <[email protected]>
This patch enables the golangci-lint checks for csi-wrapper. The version of golangci-lint is bumped to v1.52.2, since the old version has a bug when processing the --prefix-path option, which is necessary to run the lint tool in sub modules. golangci/golangci-lint#3571 Signed-off-by: Yohei Ueda <[email protected]>
Problem
When someone invokes golangci-lint in a sub-directory, they can set the path prefix to make the output look like the invocation had been done in the root.
But this prefix was ignored when checking path patterns of exclude, severity, and skip files/dirs entries, so those with matching for directories only worked when golangci-lint was always invoked in the same directory.
Solution
The underlying problem is that the rules from the configuration get checked before updating the path associated with the issues in the path fixer.
To make the prefix work, it now gets passed down into processors and added there to the issue path before checking against the path pattern.
For exclude and severity rules, this could have been done through a separate parameter, but bundling it in a new
fsutils
helper struct made the change a bit smaller.