diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-03-24 10:11:16 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-03-24 16:14:51 +0100 |
commit | b5f39d23b86f9cb83c51da9fe4abb4c19c01c3b7 (patch) | |
tree | cf23180dc07698391cf47c2fe525755417729020 /helpers/path.go | |
parent | 3011f36c27ecde309325e6c75ca377f4f87fa97a (diff) | |
download | hugo-b5f39d23b86f9cb83c51da9fe4abb4c19c01c3b7.tar.gz hugo-b5f39d23b86f9cb83c51da9fe4abb4c19c01c3b7.zip |
all: Apply staticcheck recommendations
Diffstat (limited to 'helpers/path.go')
-rw-r--r-- | helpers/path.go | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/helpers/path.go b/helpers/path.go index de2c9b0a0..36bd3269b 100644 --- a/helpers/path.go +++ b/helpers/path.go @@ -29,6 +29,7 @@ import ( "github.com/gohugoio/hugo/common/hugio" _errors "github.com/pkg/errors" "github.com/spf13/afero" + "golang.org/x/text/runes" "golang.org/x/text/transform" "golang.org/x/text/unicode/norm" ) @@ -155,7 +156,7 @@ func (p *PathSpec) UnicodeSanitize(s string) string { if p.RemovePathAccents { // remove accents - see https://blog.golang.org/normalization - t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC) + t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC) result, _, _ = transform.String(t, string(target)) } else { result = string(target) @@ -164,10 +165,6 @@ func (p *PathSpec) UnicodeSanitize(s string) string { return result } -func isMn(r rune) bool { - return unicode.Is(unicode.Mn, r) // Mn: nonspacing marks -} - // ReplaceExtension takes a path and an extension, strips the old extension // and returns the path with the new extension. func ReplaceExtension(path string, newExt string) string { @@ -208,7 +205,7 @@ func makePathRelative(inPath string, possibleDirectories ...string) (string, err return strings.TrimPrefix(inPath, currentPath), nil } } - return inPath, errors.New("Can't extract relative path, unknown prefix") + return inPath, errors.New("can't extract relative path, unknown prefix") } // Should be good enough for Hugo. @@ -403,15 +400,13 @@ func ExtractRootPaths(paths []string) []string { } -var numInPathRe = regexp.MustCompile("\\.(\\d+)\\.") - // FindCWD returns the current working directory from where the Hugo // executable is run. func FindCWD() (string, error) { serverFile, err := filepath.Abs(os.Args[0]) if err != nil { - return "", fmt.Errorf("Can't get absolute path for executable: %v", err) + return "", fmt.Errorf("can't get absolute path for executable: %v", err) } path := filepath.Dir(serverFile) @@ -437,7 +432,7 @@ func SymbolicWalk(fs afero.Fs, root string, walker filepath.WalkFunc) error { // Sanity check if root != "" && len(root) < 4 { - return errors.New("Path is too short") + return errors.New("path is too short") } // Handle the root first @@ -448,7 +443,7 @@ func SymbolicWalk(fs afero.Fs, root string, walker filepath.WalkFunc) error { } if !fileInfo.IsDir() { - return fmt.Errorf("Cannot walk regular file %s", root) + return fmt.Errorf("cannot walk regular file %s", root) } if err := walker(realPath, fileInfo, err); err != nil && err != filepath.SkipDir { |