summaryrefslogtreecommitdiffstats
path: root/helpers
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-12-02 13:23:25 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-12-03 13:12:58 +0100
commitd90e37e0c6e812f9913bf256c9c81aa05b7a08aa (patch)
tree7b1b14464eefec1188ca2eed53c64e4823453cc9 /helpers
parent32471b57bde51c55a15dbf1db75d6e5f7232c347 (diff)
all: Format code with gofumpt
See https://github.com/mvdan/gofumpt
Diffstat (limited to 'helpers')
-rw-r--r--helpers/content.go6
-rw-r--r--helpers/content_test.go4
-rw-r--r--helpers/docshelper.go3
-rw-r--r--helpers/emoji.go1
-rw-r--r--helpers/emoji_test.go8
-rw-r--r--helpers/general.go2
-rw-r--r--helpers/general_test.go3
-rw-r--r--helpers/path.go16
-rw-r--r--helpers/path_test.go21
-rw-r--r--helpers/pathspec.go2
-rw-r--r--helpers/pathspec_test.go1
-rw-r--r--helpers/processing_stats.go3
-rw-r--r--helpers/testhelpers_test.go1
-rw-r--r--helpers/url.go5
-rw-r--r--helpers/url_test.go3
15 files changed, 15 insertions, 64 deletions
diff --git a/helpers/content.go b/helpers/content.go
index c59e41a8c..5e56ad6bf 100644
--- a/helpers/content.go
+++ b/helpers/content.go
@@ -20,6 +20,7 @@ package helpers
import (
"bytes"
"html/template"
+ "strings"
"unicode"
"unicode/utf8"
@@ -33,8 +34,6 @@ import (
bp "github.com/gohugoio/hugo/bufferpool"
"github.com/gohugoio/hugo/config"
-
- "strings"
)
// SummaryDivider denotes where content summarization should end. The default is "<!--more-->".
@@ -66,7 +65,6 @@ type ContentSpec struct {
// NewContentSpec returns a ContentSpec initialized
// with the appropriate fields from the given config.Provider.
func NewContentSpec(cfg config.Provider, logger loggers.Logger, contentFs afero.Fs) (*ContentSpec, error) {
-
spec := &ContentSpec{
summaryLength: cfg.GetInt("summaryLength"),
BuildFuture: cfg.GetBool("buildFuture"),
@@ -81,7 +79,6 @@ func NewContentSpec(cfg config.Provider, logger loggers.Logger, contentFs afero.
ContentFs: contentFs,
Logger: logger,
})
-
if err != nil {
return nil, err
}
@@ -112,7 +109,6 @@ var stripHTMLReplacer = strings.NewReplacer("\n", " ", "</p>", "\n", "<br>", "\n
// StripHTML accepts a string, strips out all HTML tags and returns it.
func StripHTML(s string) string {
-
// Shortcut strings with no tags in them
if !strings.ContainsAny(s, "<>") {
return s
diff --git a/helpers/content_test.go b/helpers/content_test.go
index 86e5412c2..573c1c90d 100644
--- a/helpers/content_test.go
+++ b/helpers/content_test.go
@@ -118,7 +118,6 @@ func TestNewContentSpec(t *testing.T) {
c.Assert(spec.BuildFuture, qt.Equals, true)
c.Assert(spec.BuildExpired, qt.Equals, true)
c.Assert(spec.BuildDrafts, qt.Equals, true)
-
}
var benchmarkTruncateString = strings.Repeat("This is a sentence about nothing.", 20)
@@ -225,7 +224,7 @@ func TestExtractTOCGreaterThanSeventy(t *testing.T) {
content := []byte("<nav>\n<ul>\nTOC This is a very long content which will definitely be greater than seventy, I promise you that.<li><a href=\"#")
actualTocLessContent, actualToc := ExtractTOC(content)
- //Because the start of Toc is greater than 70+startpoint of <li> content and empty TOC will be returned
+ // Because the start of Toc is greater than 70+startpoint of <li> content and empty TOC will be returned
expectedToc := []byte("")
if !bytes.Equal(actualTocLessContent, content) {
@@ -255,7 +254,6 @@ func TestExtractNoTOC(t *testing.T) {
var totalWordsBenchmarkString = strings.Repeat("Hugo Rocks ", 200)
func TestTotalWords(t *testing.T) {
-
for i, this := range []struct {
s string
words int
diff --git a/helpers/docshelper.go b/helpers/docshelper.go
index 1397acc59..dbf5292d4 100644
--- a/helpers/docshelper.go
+++ b/helpers/docshelper.go
@@ -11,9 +11,7 @@ import (
// This is is just some helpers used to create some JSON used in the Hugo docs.
func init() {
-
docsProvider := func() docshelper.DocProvider {
-
var chromaLexers []interface{}
sort.Sort(lexers.Registry.Lexers)
@@ -50,7 +48,6 @@ func init() {
}
return docshelper.DocProvider{"chroma": map[string]interface{}{"lexers": chromaLexers}}
-
}
docshelper.AddDocProviderFunc(docsProvider)
diff --git a/helpers/emoji.go b/helpers/emoji.go
index a6786c005..cda0e1616 100644
--- a/helpers/emoji.go
+++ b/helpers/emoji.go
@@ -93,5 +93,4 @@ func initEmoji() {
emojiMaxSize = len(k)
}
}
-
}
diff --git a/helpers/emoji_test.go b/helpers/emoji_test.go
index 89f9df5fa..e9d634ccc 100644
--- a/helpers/emoji_test.go
+++ b/helpers/emoji_test.go
@@ -74,7 +74,6 @@ func TestEmojiCustom(t *testing.T) {
// Hugo have a byte slice, wants a byte slice and doesn't mind if the original is modified.
func BenchmarkEmojiKyokomiFprint(b *testing.B) {
-
f := func(in []byte) []byte {
buff := bufferpool.GetBuffer()
defer bufferpool.PutBuffer(buff)
@@ -89,7 +88,6 @@ func BenchmarkEmojiKyokomiFprint(b *testing.B) {
}
func BenchmarkEmojiKyokomiSprint(b *testing.B) {
-
f := func(in []byte) []byte {
return []byte(emoji.Sprint(string(in)))
}
@@ -102,7 +100,6 @@ func BenchmarkHugoEmoji(b *testing.B) {
}
func doBenchmarkEmoji(b *testing.B, f func(in []byte) []byte) {
-
type input struct {
in []byte
expect []byte
@@ -119,8 +116,8 @@ func doBenchmarkEmoji(b *testing.B, f func(in []byte) []byte) {
{"No smiles for you or " + strings.Repeat("you ", 1000), "No smiles for you or " + strings.Repeat("you ", 1000)},
}
- var in = make([]input, b.N*len(data))
- var cnt = 0
+ in := make([]input, b.N*len(data))
+ cnt := 0
for i := 0; i < b.N; i++ {
for _, this := range data {
in[cnt] = input{[]byte(this.input), []byte(this.expect)}
@@ -142,6 +139,5 @@ func doBenchmarkEmoji(b *testing.B, f func(in []byte) []byte) {
b.Fatalf("[%d] emoji std, got \n%q but expected \n%q", j, result, currIn.expect)
}
}
-
}
}
diff --git a/helpers/general.go b/helpers/general.go
index 80e303087..9589514e0 100644
--- a/helpers/general.go
+++ b/helpers/general.go
@@ -157,7 +157,6 @@ func ReaderToString(lines io.Reader) string {
// ReaderContains reports whether subslice is within r.
func ReaderContains(r io.Reader, subslice []byte) bool {
-
if r == nil || len(subslice) == 0 {
return false
}
@@ -345,7 +344,6 @@ func InitLoggers() {
func Deprecated(item, alternative string, err bool) {
if err {
DistinctErrorLog.Printf("%s is deprecated and will be removed in Hugo %s. %s", item, hugo.CurrentVersion.Next().ReleaseVersion(), alternative)
-
} else {
DistinctWarnLog.Printf("%s is deprecated and will be removed in a future release. %s", item, alternative)
}
diff --git a/helpers/general_test.go b/helpers/general_test.go
index 60248b671..518188c17 100644
--- a/helpers/general_test.go
+++ b/helpers/general_test.go
@@ -219,7 +219,6 @@ func TestGetTitleFunc(t *testing.T) {
c.Assert(GetTitleFunc("ap")(title), qt.Equals, "Somewhere Over the Rainbow")
c.Assert(GetTitleFunc("")(title), qt.Equals, "Somewhere Over the Rainbow")
c.Assert(GetTitleFunc("unknown")(title), qt.Equals, "Somewhere Over the Rainbow")
-
}
func BenchmarkReaderContains(b *testing.B) {
@@ -354,7 +353,6 @@ func BenchmarkMD5FromFileFast(b *testing.B) {
}
})
}
-
}
func BenchmarkUniqueStrings(b *testing.B) {
@@ -406,7 +404,6 @@ func BenchmarkUniqueStrings(b *testing.B) {
}
}
})
-
}
func TestHashString(t *testing.T) {
diff --git a/helpers/path.go b/helpers/path.go
index 01c452607..abc73d081 100644
--- a/helpers/path.go
+++ b/helpers/path.go
@@ -36,10 +36,8 @@ import (
"github.com/spf13/afero"
)
-var (
- // ErrThemeUndefined is returned when a theme has not be defined by the user.
- ErrThemeUndefined = errors.New("no theme set")
-)
+// ErrThemeUndefined is returned when a theme has not be defined by the user.
+var ErrThemeUndefined = errors.New("no theme set")
// filepathPathBridge is a bridge for common functionality in filepath vs path
type filepathPathBridge interface {
@@ -169,7 +167,6 @@ func ReplaceExtension(path string, newExt string) string {
}
func makePathRelative(inPath string, possibleDirectories ...string) (string, error) {
-
for _, currentPath := range possibleDirectories {
if strings.HasPrefix(inPath, currentPath) {
return strings.TrimPrefix(inPath, currentPath), nil
@@ -281,7 +278,6 @@ func fileAndExt(in string, b filepathPathBridge) (name string, ext string) {
}
func extractFilename(in, ext, base, pathSeparator string) (name string) {
-
// No file name cases. These are defined as:
// 1. any "in" path that ends in a pathSeparator
// 2. any "base" consisting of just an pathSeparator
@@ -299,7 +295,6 @@ func extractFilename(in, ext, base, pathSeparator string) (name string) {
name = base
}
return
-
}
// GetRelativePath returns the relative path of a given path.
@@ -474,21 +469,18 @@ func ExtractRootPaths(paths []string) []string {
r[i] = root
}
return r
-
}
// 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)
}
path := filepath.Dir(serverFile)
realFile, err := filepath.EvalSymlinks(serverFile)
-
if err != nil {
if _, err = os.Stat(serverFile + ".exe"); err == nil {
realFile = filepath.Clean(serverFile + ".exe")
@@ -516,7 +508,6 @@ func SymbolicWalk(fs afero.Fs, root string, walker hugofs.WalkFunc) error {
})
return w.Walk()
-
}
// LstatIfPossible can be used to call Lstat if possible, else Stat.
@@ -555,7 +546,6 @@ func OpenFilesForWriting(fs afero.Fs, filenames ...string) (io.WriteCloser, erro
}
return hugio.NewMultiWriteCloser(writeClosers...), nil
-
}
// OpenFileForWriting opens or creates the given file. If the target directory
@@ -598,7 +588,6 @@ func GetCacheDir(fs afero.Fs, cfg config.Provider) (string, error) {
// Fall back to a cache in /tmp.
return GetTempDir("hugo_cache", fs), nil
-
}
func getCacheDir(cfg config.Provider) string {
@@ -614,7 +603,6 @@ func getCacheDir(cfg config.Provider) string {
// is this project:
// https://github.com/philhawksworth/content-shards/blob/master/gulpfile.js
return "/opt/build/cache/hugo_cache/"
-
}
// This will fall back to an hugo_cache folder in the tmp dir, which should work fine for most CI
diff --git a/helpers/path_test.go b/helpers/path_test.go
index 50c23dccc..e1ac90b2f 100644
--- a/helpers/path_test.go
+++ b/helpers/path_test.go
@@ -184,7 +184,6 @@ func TestGetDottedRelativePath(t *testing.T) {
for _, f := range []func(string) string{filepath.FromSlash, func(s string) string { return s }} {
doTestGetDottedRelativePath(f, t)
}
-
}
func doTestGetDottedRelativePath(urlFixer func(string) string, t *testing.T) {
@@ -422,7 +421,6 @@ func createTempDirWithZeroLengthFiles() (string, error) {
}
// the dir now has one, zero length file in it
return d, nil
-
}
func createTempDirWithNonZeroLengthFiles() (string, error) {
@@ -451,7 +449,6 @@ func createTempDirWithNonZeroLengthFiles() (string, error) {
// the dir now has one, zero length file in it
return d, nil
-
}
func deleteTempDir(d string) {
@@ -490,7 +487,6 @@ func TestExists(t *testing.T) {
t.Errorf("Test %d failed. Expected %q got %q", i, d.expectedErr, err)
}
}
-
}
func TestAbsPathify(t *testing.T) {
@@ -544,7 +540,6 @@ func TestAbsPathify(t *testing.T) {
}
}
}
-
}
func TestExtNoDelimiter(t *testing.T) {
@@ -611,15 +606,12 @@ func TestFileAndExt(t *testing.T) {
t.Errorf("Test %d failed. Expected extension %q got %q.", i, d.expectedExt, ext)
}
}
-
}
func TestPathPrep(t *testing.T) {
-
}
func TestPrettifyPath(t *testing.T) {
-
}
func TestExtractAndGroupRootPaths(t *testing.T) {
@@ -642,16 +634,19 @@ func TestExtractAndGroupRootPaths(t *testing.T) {
// Make sure the original is preserved
c.Assert(in, qt.DeepEquals, inCopy)
-
}
func TestExtractRootPaths(t *testing.T) {
tests := []struct {
input []string
expected []string
- }{{[]string{filepath.FromSlash("a/b"), filepath.FromSlash("a/b/c/"), "b",
- filepath.FromSlash("/c/d"), filepath.FromSlash("d/"), filepath.FromSlash("//e//")},
- []string{"a", "a", "b", "c", "d", "e"}}}
+ }{{
+ []string{
+ filepath.FromSlash("a/b"), filepath.FromSlash("a/b/c/"), "b",
+ filepath.FromSlash("/c/d"), filepath.FromSlash("d/"), filepath.FromSlash("//e//"),
+ },
+ []string{"a", "a", "b", "c", "d", "e"},
+ }}
for _, test := range tests {
output := ExtractRootPaths(test.input)
@@ -667,7 +662,7 @@ func TestFindCWD(t *testing.T) {
expectedErr error
}
- //cwd, _ := os.Getwd()
+ // cwd, _ := os.Getwd()
data := []test{
//{cwd, nil},
// Commenting this out. It doesn't work properly.
diff --git a/helpers/pathspec.go b/helpers/pathspec.go
index 557261f1c..5400249eb 100644
--- a/helpers/pathspec.go
+++ b/helpers/pathspec.go
@@ -45,7 +45,6 @@ func NewPathSpec(fs *hugofs.Fs, cfg config.Provider, logger loggers.Logger) (*Pa
// NewPathSpecWithBaseBaseFsProvided creats a new PathSpec from the given filesystems and language.
// If an existing BaseFs is provided, parts of that is reused.
func NewPathSpecWithBaseBaseFsProvided(fs *hugofs.Fs, cfg config.Provider, logger loggers.Logger, baseBaseFs *filesystems.BaseFs) (*PathSpec, error) {
-
p, err := paths.New(fs, cfg)
if err != nil {
return nil, err
@@ -85,5 +84,4 @@ func (p *PathSpec) PermalinkForBaseURL(link, baseURL string) string {
baseURL += "/"
}
return baseURL + link
-
}
diff --git a/helpers/pathspec_test.go b/helpers/pathspec_test.go
index 8937b0af5..c11299516 100644
--- a/helpers/pathspec_test.go
+++ b/helpers/pathspec_test.go
@@ -56,5 +56,4 @@ func TestNewPathSpecFromConfig(t *testing.T) {
c.Assert(p.BaseURL.String(), qt.Equals, "http://base.com")
c.Assert(p.ThemesDir, qt.Equals, "thethemes")
c.Assert(p.WorkingDir, qt.Equals, "thework")
-
}
diff --git a/helpers/processing_stats.go b/helpers/processing_stats.go
index 4382d5fa5..3e3e9a3ca 100644
--- a/helpers/processing_stats.go
+++ b/helpers/processing_stats.go
@@ -83,7 +83,6 @@ func (s *ProcessingStats) Table(w io.Writer) {
table.SetHeader([]string{"", s.Name})
table.SetBorder(false)
table.Render()
-
}
// ProcessingStatsTable writes a table-formatted representation of stats to w.
@@ -108,7 +107,6 @@ func ProcessingStatsTable(w io.Writer, stats ...*ProcessingStats) {
} else {
data[j] = append(data[j], strconv.Itoa(int(tv.val)))
}
-
}
}
@@ -119,5 +117,4 @@ func ProcessingStatsTable(w io.Writer, stats ...*ProcessingStats) {
table.SetHeader(names)
table.SetBorder(false)
table.Render()
-
}
diff --git a/helpers/testhelpers_test.go b/helpers/testhelpers_test.go
index bf249059d..4a6ebd0b1 100644
--- a/helpers/testhelpers_test.go
+++ b/helpers/testhelpers_test.go
@@ -32,7 +32,6 @@ func newTestCfgFor(fs *hugofs.Fs) *viper.Viper {
v.SetFs(fs.Source)
return v
-
}
func newTestCfg() *viper.Viper {
diff --git a/helpers/url.go b/helpers/url.go
index 1e88def9e..6f4242b09 100644
--- a/helpers/url.go
+++ b/helpers/url.go
@@ -83,7 +83,7 @@ func sanitizeURLWithFlags(in string, f purell.NormalizationFlags) string {
return u.String()
// End temporary kludge
- //return s
+ // return s
}
@@ -103,7 +103,6 @@ func SanitizeURLKeepTrailingSlash(in string) string {
// urlize: vim-text-editor
func (p *PathSpec) URLize(uri string) string {
return p.URLEscape(p.MakePathSanitized(uri))
-
}
// URLizeFilename creates an URL from a filename by esacaping unicode letters
@@ -130,7 +129,6 @@ func (p *PathSpec) URLEscape(uri string) string {
// path: post/how-i-blog
// result: http://spf13.com/post/how-i-blog
func MakePermalink(host, plink string) *url.URL {
-
base, err := url.Parse(host)
if err != nil {
panic(err)
@@ -275,7 +273,6 @@ func (p *PathSpec) RelURL(in string, addLanguage bool) string {
// For relative URL entries on sites with a base url with a context root set (i.e. http://example.com/mysite),
// relative URLs must not include the context root if canonifyURLs is enabled. But if it's disabled, it must be set.
func AddContextRoot(baseURL, relativePath string) string {
-
url, err := url.Parse(baseURL)
if err != nil {
panic(err)
diff --git a/helpers/url_test.go b/helpers/url_test.go
index 6f374f027..4c16208f1 100644
--- a/helpers/url_test.go
+++ b/helpers/url_test.go
@@ -23,7 +23,6 @@ import (
)
func TestURLize(t *testing.T) {
-
v := newTestCfg()
l := langs.NewDefaultLanguage(v)
p, _ := NewPathSpec(hugofs.NewMem(v), l, nil)
@@ -113,7 +112,6 @@ func doTestAbsURL(t *testing.T, defaultInSubDir, addLanguage, multilingual bool,
} else {
expected = strings.Replace(expected, "MULTI", lang+"/", 1)
}
-
} else {
expected = strings.Replace(expected, "MULTI", "", 1)
}
@@ -294,7 +292,6 @@ func TestURLPrep(t *testing.T) {
t.Errorf("Test #%d failed. Expected %q got %q", i, d.output, output)
}
}
-
}
func TestAddContextRoot(t *testing.T) {