golangci-lint
golangci-lint copied to clipboard
Normalize exclude-rules paths for Windows
Minor change to normalize the paths in exclude-rules. This re-uses the same logic that is already in place for skip-dirs.
Fixes #1398
Hey, thank you for opening your first Pull Request !
I blocked this PR because I think it will create regressions and side effects. I'm not using Windows so I'm not quickly able to validate the behavior.
@ldez Can you elaborate on what you think this will break? As a Windows user, it looks correct to me, but I'd like to see if there's anything specific that you think should be tested. This code is already used for skip-files and skip-dirs, so why would it not work for exclude-rules.path?
When a PR is blocked, put an approved without any comment is weird.
OK, got it. normalizePathInRegex is already used by SkipDirs and SkipFiles, and
This re-uses the same logic that is already in place for skip-dirs
sounds safe and valid.
Also, separatorToReplace = regexp.QuoteMeta(string(filepath.Separator)) looks OK for Windows
package main
import (
"regexp"
"strings"
)
func main() {
path := '\\'
separatorToReplace := regexp.QuoteMeta(string(path))
file := "some/.*/file.go"
file = strings.ReplaceAll(file, "/", separatorToReplace)
re := regexp.MustCompile(file)
if !re.MatchString("some\\path\\to\\file.go") {
panic("wrong")
}
}
on Windows I see paths in format pkg\lint\lintersdb\manager.go, see https://github.com/golangci/golangci-lint/runs/7469347948?check_suite_focus=true
So, I think there are no risks, but it will be great if some windows-specific tests will be added here.