diff options
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/content.go | 8 | ||||
-rw-r--r-- | helpers/emoji_test.go | 2 | ||||
-rw-r--r-- | helpers/general.go | 6 | ||||
-rw-r--r-- | helpers/path.go | 17 | ||||
-rw-r--r-- | helpers/path_test.go | 17 | ||||
-rw-r--r-- | helpers/pygments.go | 8 | ||||
-rw-r--r-- | helpers/url.go | 2 |
7 files changed, 22 insertions, 38 deletions
diff --git a/helpers/content.go b/helpers/content.go index bc19f6559..be5090c21 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -147,10 +147,8 @@ func newBlackfriday(config map[string]interface{}) *BlackFriday { siteConfig[k] = v } - if config != nil { - for k, v := range config { - siteConfig[k] = v - } + for k, v := range config { + siteConfig[k] = v } combinedConfig := &BlackFriday{} @@ -755,7 +753,7 @@ func externallyRenderContent(ctx *RenderingContext, path string, args []string) err := cmd.Run() // Most external helpers exit w/ non-zero exit code only if severe, i.e. // halting errors occurred. -> log stderr output regardless of state of err - for _, item := range strings.Split(string(cmderr.Bytes()), "\n") { + for _, item := range strings.Split(cmderr.String(), "\n") { item := strings.TrimSpace(item) if item != "" { jww.ERROR.Printf("%s: %s", ctx.DocumentName, item) diff --git a/helpers/emoji_test.go b/helpers/emoji_test.go index f9189eb43..89f9df5fa 100644 --- a/helpers/emoji_test.go +++ b/helpers/emoji_test.go @@ -80,7 +80,7 @@ func BenchmarkEmojiKyokomiFprint(b *testing.B) { defer bufferpool.PutBuffer(buff) emoji.Fprint(buff, string(in)) - bc := make([]byte, buff.Len(), buff.Len()) + bc := make([]byte, buff.Len()) copy(bc, buff.Bytes()) return bc } diff --git a/helpers/general.go b/helpers/general.go index 962b35bc6..3cf7ba8af 100644 --- a/helpers/general.go +++ b/helpers/general.go @@ -57,7 +57,7 @@ func FindAvailablePort() (*net.TCPAddr, error) { if a, ok := addr.(*net.TCPAddr); ok { return a, nil } - return nil, fmt.Errorf("Unable to obtain a valid tcp port. %v", addr) + return nil, fmt.Errorf("unable to obtain a valid tcp port: %v", addr) } return nil, err } @@ -128,7 +128,7 @@ func ReaderToBytes(lines io.Reader) []byte { b.ReadFrom(lines) - bc := make([]byte, b.Len(), b.Len()) + bc := make([]byte, b.Len()) copy(bc, b.Bytes()) return bc } @@ -417,10 +417,8 @@ func NormalizeHugoFlags(f *pflag.FlagSet, name string) pflag.NormalizedName { switch name { case "baseUrl": name = "baseURL" - break case "uglyUrls": name = "uglyURLs" - break } return pflag.NormalizedName(name) } 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 { diff --git a/helpers/path_test.go b/helpers/path_test.go index c249a519d..98291936c 100644 --- a/helpers/path_test.go +++ b/helpers/path_test.go @@ -171,7 +171,7 @@ func TestGetRealPath(t *testing.T) { t.Skip("Skip TestGetRealPath as os.Symlink needs administrator rights on Windows") } - d1, err := ioutil.TempDir("", "d1") + d1, _ := ioutil.TempDir("", "d1") defer os.Remove(d1) fs := afero.NewOsFs() @@ -418,6 +418,7 @@ func createNonZeroSizedFileInTempDir() (*os.File, error) { f, err := createZeroSizedFileInTempDir() if err != nil { // no file ?? + return nil, err } byteString := []byte("byteString") err = ioutil.WriteFile(f.Name(), byteString, 0644) @@ -430,10 +431,7 @@ func createNonZeroSizedFileInTempDir() (*os.File, error) { } func deleteFileInTempDir(f *os.File) { - err := os.Remove(f.Name()) - if err != nil { - // now what? - } + _ = os.Remove(f.Name()) } func createEmptyTempDir() (string, error) { @@ -449,7 +447,7 @@ func createEmptyTempDir() (string, error) { func createTempDirWithZeroLengthFiles() (string, error) { d, dirErr := createEmptyTempDir() if dirErr != nil { - //now what? + return "", dirErr } filePrefix := "_path_test_" _, fileErr := ioutil.TempFile(d, filePrefix) // dir is os.TempDir() @@ -467,7 +465,7 @@ func createTempDirWithZeroLengthFiles() (string, error) { func createTempDirWithNonZeroLengthFiles() (string, error) { d, dirErr := createEmptyTempDir() if dirErr != nil { - //now what? + return "", dirErr } filePrefix := "_path_test_" f, fileErr := ioutil.TempFile(d, filePrefix) // dir is os.TempDir() @@ -494,10 +492,7 @@ func createTempDirWithNonZeroLengthFiles() (string, error) { } func deleteTempDir(d string) { - err := os.RemoveAll(d) - if err != nil { - // now what? - } + _ = os.RemoveAll(d) } func TestExists(t *testing.T) { diff --git a/helpers/pygments.go b/helpers/pygments.go index 64c5b3ea8..0fe1e7592 100644 --- a/helpers/pygments.go +++ b/helpers/pygments.go @@ -153,7 +153,7 @@ func (h highlighters) pygmentsHighlight(code, lang, optsStr string) (string, err return code, err } - str := string(normalizeExternalHelperLineFeeds([]byte(out.String()))) + str := string(normalizeExternalHelperLineFeeds(out.Bytes())) str = h.injectCodeTag(str, lang) @@ -235,10 +235,8 @@ func parseOptions(defaults map[string]string, in string) (map[string]string, err in = strings.Trim(in, " ") opts := make(map[string]string) - if defaults != nil { - for k, v := range defaults { - opts[k] = v - } + for k, v := range defaults { + opts[k] = v } if in == "" { diff --git a/helpers/url.go b/helpers/url.go index a24f05b12..6dbdea299 100644 --- a/helpers/url.go +++ b/helpers/url.go @@ -142,7 +142,7 @@ func MakePermalink(host, plink string) *url.URL { } if p.Host != "" { - panic(fmt.Errorf("Can't make permalink from absolute link %q", plink)) + panic(fmt.Errorf("can't make permalink from absolute link %q", plink)) } base.Path = path.Join(base.Path, p.Path) |