-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config: fix path matching when path prefix is used
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.
- Loading branch information
Showing
13 changed files
with
181 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package fsutils | ||
|
||
import "path/filepath" | ||
|
||
// Files combines different operations related to handling file paths and content. | ||
type Files struct { | ||
*LineCache | ||
pathPrefix string | ||
} | ||
|
||
func NewFiles(lc *LineCache, pathPrefix string) *Files { | ||
return &Files{ | ||
LineCache: lc, | ||
pathPrefix: pathPrefix, | ||
} | ||
} | ||
|
||
// WithPathPrefix takes a path that is relative to the current directory (as used in issues) | ||
// and adds the configured path prefix, if there is one. | ||
// The resulting path then can be shown to the user or compared against paths specified in the configuration. | ||
func (f *Files) WithPathPrefix(relativePath string) string { | ||
return WithPathPrefix(f.pathPrefix, relativePath) | ||
} | ||
|
||
// WithPathPrefix takes a path that is relative to the current directory (as used in issues) | ||
// and adds the configured path prefix, if there is one. | ||
// The resulting path then can be shown to the user or compared against paths specified in the configuration. | ||
func WithPathPrefix(pathPrefix, relativePath string) string { | ||
if pathPrefix == "" { | ||
return relativePath | ||
} | ||
return filepath.Join(pathPrefix, relativePath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.