Skip to content

Commit 9f0c8b6

Browse files
committed
docs: add comments
1 parent 9efdab0 commit 9f0c8b6

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

pkg/result/processors/path_unix.go

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package processors
44

5+
// normalizePathInRegex it's a noop function on Unix.
56
func normalizePathInRegex(path string) string {
67
return path
78
}

pkg/result/processors/path_windows.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import (
1010

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

13+
// normalizePathInRegex normalizes path in regular expressions.
14+
// noop on Unix.
15+
// This replacing should be safe because "/" are disallowed in Windows
16+
// https://docs.microsoft.com/windows/win32/fileio/naming-a-file
1317
func normalizePathInRegex(path string) string {
14-
if filepath.Separator == '/' {
15-
return path
16-
}
17-
18-
// This replacing should be safe because "/" are disallowed in Windows
19-
// https://docs.microsoft.com/ru-ru/windows/win32/fileio/naming-a-file
2018
return strings.ReplaceAll(path, "/", separatorToReplace)
2119
}

test/testshared/runner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ func (r *RunnerResult) ExpectExitCode(possibleCodes ...int) *RunnerResult {
297297
func (r *RunnerResult) ExpectOutputRegexp(s string) *RunnerResult {
298298
r.tb.Helper()
299299

300-
assert.Regexp(r.tb, normalizeFilePathInRegex(s), r.output, "exit code is %d", r.exitCode)
300+
assert.Regexp(r.tb, normalizePathInRegex(s), r.output, "exit code is %d", r.exitCode)
301301
return r
302302
}
303303

test/testshared/runner_unix.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,30 @@ import (
77
"testing"
88
)
99

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

13+
// NormalizeFilePathInJSON it's a noop function on Unix.
1214
func NormalizeFilePathInJSON(in string) string {
1315
return in
1416
}
1517

16-
// NormalizeFileInString normalizes in quoted string.
18+
// NormalizeFileInString it's a noop function on Unix.
1719
func NormalizeFileInString(in string) string {
1820
return in
1921
}
2022

23+
// defaultBinaryName returns the path to the default binary.
2124
func defaultBinaryName() string {
2225
return filepath.Join("..", "golangci-lint")
2326
}
2427

28+
// normalizeFilePath it's a noop function on Unix.
2529
func normalizeFilePath(in string) string {
2630
return in
2731
}
2832

29-
func normalizeFilePathInRegex(path string) string {
33+
// normalizePathInRegex it's a noop function on Unix.
34+
func normalizePathInRegex(path string) string {
3035
return path
3136
}

test/testshared/runner_windows.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import (
99
"testing"
1010
)
1111

12+
// SkipOnWindows skip test on Windows.
1213
func SkipOnWindows(tb testing.TB) {
1314
tb.Skip("not supported on Windows")
1415
}
1516

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

@@ -21,15 +23,17 @@ func NormalizeFilePathInJSON(in string) string {
2123
})
2224
}
2325

24-
func defaultBinaryName() string {
25-
return filepath.Join("..", "golangci-lint.exe")
26-
}
27-
28-
// NormalizeFileInString normalizes in quoted string, ie. `\\\\`.
26+
// NormalizeFileInString normalizes in quoted string, ie. replace `\\` by `\\\\`.
2927
func NormalizeFileInString(in string) string {
3028
return strings.ReplaceAll(filepath.FromSlash(in), "\\", "\\\\")
3129
}
3230

31+
// defaultBinaryName returns the path to the default binary.
32+
func defaultBinaryName() string {
33+
return filepath.Join("..", "golangci-lint.exe")
34+
}
35+
36+
// normalizeFilePath find Go file path and replace `/` by `\\`.
3337
func normalizeFilePath(in string) string {
3438
exp := regexp.MustCompile(`(?:^|\b)[\w-/.]+\.go`)
3539

@@ -38,9 +42,10 @@ func normalizeFilePath(in string) string {
3842
})
3943
}
4044

41-
// normalizeFilePathInRegex normalizes path in regular expressions.
42-
func normalizeFilePathInRegex(path string) string {
43-
// This replacing should be safe because "/" are disallowed in Windows
44-
// https://docs.microsoft.com/windows/win32/fileio/naming-a-file
45+
// normalizePathInRegex normalizes path in regular expressions.
46+
// Replace all `/` by `\\`.
47+
// This replacing should be safe because "/" are disallowed in Windows
48+
// https://docs.microsoft.com/windows/win32/fileio/naming-a-file
49+
func normalizePathInRegex(path string) string {
4550
return strings.ReplaceAll(path, "/", regexp.QuoteMeta(string(filepath.Separator)))
4651
}

0 commit comments

Comments
 (0)