Skip to content

Commit

Permalink
docs: add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Aug 24, 2022
1 parent 9efdab0 commit 61c900a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 0 deletions pkg/result/processors/path_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package processors

// normalizePathInRegex it's a noop function on Unix.
func normalizePathInRegex(path string) string {
return path
}
10 changes: 4 additions & 6 deletions pkg/result/processors/path_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import (

var separatorToReplace = regexp.QuoteMeta(string(filepath.Separator))

// normalizePathInRegex normalizes path in regular expressions.
// noop on Unix.
// This replacing should be safe because "/" are disallowed in Windows
// https://docs.microsoft.com/windows/win32/fileio/naming-a-file
func normalizePathInRegex(path string) string {
if filepath.Separator == '/' {
return path
}

// This replacing should be safe because "/" are disallowed in Windows
// https://docs.microsoft.com/ru-ru/windows/win32/fileio/naming-a-file
return strings.ReplaceAll(path, "/", separatorToReplace)
}
2 changes: 1 addition & 1 deletion test/testshared/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (r *RunnerResult) ExpectExitCode(possibleCodes ...int) *RunnerResult {
func (r *RunnerResult) ExpectOutputRegexp(s string) *RunnerResult {
r.tb.Helper()

assert.Regexp(r.tb, normalizeFilePathInRegex(s), r.output, "exit code is %d", r.exitCode)
assert.Regexp(r.tb, normalizePathInRegex(s), r.output, "exit code is %d", r.exitCode)
return r
}

Expand Down
9 changes: 7 additions & 2 deletions test/testshared/runner_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,30 @@ import (
"testing"
)

// SkipOnWindows it's a noop function on Unix.
func SkipOnWindows(_ testing.TB) {}

// NormalizeFilePathInJSON it's a noop function on Unix.
func NormalizeFilePathInJSON(in string) string {
return in
}

// NormalizeFileInString normalizes in quoted string.
// NormalizeFileInString it's a noop function on Unix.
func NormalizeFileInString(in string) string {
return in
}

// defaultBinaryName returns the path to the default binary.
func defaultBinaryName() string {
return filepath.Join("..", "golangci-lint")
}

// normalizeFilePath it's a noop function on Unix.
func normalizeFilePath(in string) string {
return in
}

func normalizeFilePathInRegex(path string) string {
// normalizePathInRegex it's a noop function on Unix.
func normalizePathInRegex(path string) string {
return path
}
23 changes: 14 additions & 9 deletions test/testshared/runner_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
"testing"
)

// SkipOnWindows skip test on Windows.
func SkipOnWindows(tb testing.TB) {
tb.Skip("not supported on Windows")
}

// NormalizeFilePathInJSON find Go file path and replace `/` with `\\\\`.
func NormalizeFilePathInJSON(in string) string {
exp := regexp.MustCompile(`(?:^|\b)[\w-/.]+\.go`)

Expand All @@ -21,15 +23,17 @@ func NormalizeFilePathInJSON(in string) string {
})
}

func defaultBinaryName() string {
return filepath.Join("..", "golangci-lint.exe")
}

// NormalizeFileInString normalizes in quoted string, ie. `\\\\`.
// NormalizeFileInString normalizes in quoted string, ie. replace `\\` with `\\\\`.
func NormalizeFileInString(in string) string {
return strings.ReplaceAll(filepath.FromSlash(in), "\\", "\\\\")
}

// defaultBinaryName returns the path to the default binary.
func defaultBinaryName() string {
return filepath.Join("..", "golangci-lint.exe")
}

// normalizeFilePath find Go file path and replace `/` with `\\`.
func normalizeFilePath(in string) string {
exp := regexp.MustCompile(`(?:^|\b)[\w-/.]+\.go`)

Expand All @@ -38,9 +42,10 @@ func normalizeFilePath(in string) string {
})
}

// normalizeFilePathInRegex normalizes path in regular expressions.
func normalizeFilePathInRegex(path string) string {
// This replacing should be safe because "/" are disallowed in Windows
// https://docs.microsoft.com/windows/win32/fileio/naming-a-file
// normalizePathInRegex normalizes path in regular expressions.
// Replace all `/` with `\\`.
// This replacing should be safe because "/" are disallowed in Windows
// https://docs.microsoft.com/windows/win32/fileio/naming-a-file
func normalizePathInRegex(path string) string {
return strings.ReplaceAll(path, "/", regexp.QuoteMeta(string(filepath.Separator)))
}

0 comments on commit 61c900a

Please sign in to comment.