-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove redundant character escape '\/' (#3278)
- Loading branch information
Showing
12 changed files
with
46 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//go:build !windows | ||
|
||
package fsutils | ||
|
||
// NormalizePathInRegex it's a noop function on Unix. | ||
func NormalizePathInRegex(path string) string { | ||
return path | ||
} |
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,28 @@ | ||
//go:build windows | ||
|
||
package fsutils | ||
|
||
import ( | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
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 { | ||
// remove redundant character escape "\/" https://github.com/golangci/golangci-lint/issues/3277 | ||
clean := regexp.MustCompile(`\\+/`). | ||
ReplaceAllStringFunc(path, func(s string) string { | ||
if strings.Count(s, "\\")%2 == 0 { | ||
return s | ||
} | ||
return s[1:] | ||
}) | ||
|
||
return strings.ReplaceAll(clean, "/", separatorToReplace) | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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