From 61c900a5f72924a49accd9f2023ad7b9ef62c9bc Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 24 Aug 2022 21:17:38 +0200 Subject: [PATCH] docs: add comments --- pkg/result/processors/path_unix.go | 1 + pkg/result/processors/path_windows.go | 10 ++++------ test/testshared/runner.go | 2 +- test/testshared/runner_unix.go | 9 +++++++-- test/testshared/runner_windows.go | 23 ++++++++++++++--------- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/pkg/result/processors/path_unix.go b/pkg/result/processors/path_unix.go index d61bbf67a812..b0c7c33826cb 100644 --- a/pkg/result/processors/path_unix.go +++ b/pkg/result/processors/path_unix.go @@ -2,6 +2,7 @@ package processors +// normalizePathInRegex it's a noop function on Unix. func normalizePathInRegex(path string) string { return path } diff --git a/pkg/result/processors/path_windows.go b/pkg/result/processors/path_windows.go index edd081c875e0..7f3e3622bb75 100644 --- a/pkg/result/processors/path_windows.go +++ b/pkg/result/processors/path_windows.go @@ -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) } diff --git a/test/testshared/runner.go b/test/testshared/runner.go index fa03bab34012..9ce8363f460c 100644 --- a/test/testshared/runner.go +++ b/test/testshared/runner.go @@ -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 } diff --git a/test/testshared/runner_unix.go b/test/testshared/runner_unix.go index f76b82d6ac0b..c36669b1c6b6 100644 --- a/test/testshared/runner_unix.go +++ b/test/testshared/runner_unix.go @@ -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 } diff --git a/test/testshared/runner_windows.go b/test/testshared/runner_windows.go index 867810e7ac03..69afec9c5bca 100644 --- a/test/testshared/runner_windows.go +++ b/test/testshared/runner_windows.go @@ -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`) @@ -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`) @@ -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))) }