shithub: hugo

Download patch

ref: 47fdfd5196cd24a23b30afe1d88969ffb413ab59
parent: d45e358a0543d987091ef54b56eadd9cebda2e0f
author: Cameron Moore <[email protected]>
date: Mon Sep 25 17:25:33 EDT 2017

Clean up lint in various packages

Changes fall into one of the following:

- gofmt -s
- receiver name is inconsistent
- omit unused 2nd value from range
- godoc comment formed incorrectly
- err assigned and not used
- if block ends with a return statement followed by else

--- a/helpers/pygments_test.go
+++ b/helpers/pygments_test.go
@@ -224,13 +224,13 @@
 		expected  interface{}
 	}{
 		{"", 1, zero},
-		{"1 4", 1, [][2]int{[2]int{1, 1}, [2]int{4, 4}}},
-		{"1 4", 2, [][2]int{[2]int{2, 2}, [2]int{5, 5}}},
-		{"1-4 5-8", 1, [][2]int{[2]int{1, 4}, [2]int{5, 8}}},
-		{" 1   4 ", 1, [][2]int{[2]int{1, 1}, [2]int{4, 4}}},
-		{"1-4    5-8 ", 1, [][2]int{[2]int{1, 4}, [2]int{5, 8}}},
-		{"1-4 5", 1, [][2]int{[2]int{1, 4}, [2]int{5, 5}}},
-		{"4 5-9", 1, [][2]int{[2]int{4, 4}, [2]int{5, 9}}},
+		{"1 4", 1, [][2]int{{1, 1}, {4, 4}}},
+		{"1 4", 2, [][2]int{{2, 2}, {5, 5}}},
+		{"1-4 5-8", 1, [][2]int{{1, 4}, {5, 8}}},
+		{" 1   4 ", 1, [][2]int{{1, 1}, {4, 4}}},
+		{"1-4    5-8 ", 1, [][2]int{{1, 4}, {5, 8}}},
+		{"1-4 5", 1, [][2]int{{1, 4}, {5, 5}}},
+		{"4 5-9", 1, [][2]int{{4, 4}, {5, 9}}},
 		{" 1 -4 5 - 8  ", 1, true},
 		{"a b", 1, true},
 	} {
--- a/hugolib/handler_meta.go
+++ b/hugolib/handler_meta.go
@@ -34,7 +34,7 @@
 	Handle() Handler
 }
 
-// HandledResults is a channel for HandledResult.
+// HandleResults is a channel for HandledResult.
 type HandleResults chan<- HandledResult
 
 // NewMetaHandler creates a MetaHandle for a given extensions.
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -65,6 +65,7 @@
 	KindPage = "page"
 
 	// The rest are node types; home page, sections etc.
+
 	KindHome         = "home"
 	KindSection      = "section"
 	KindTaxonomy     = "taxonomy"
@@ -484,10 +485,10 @@
 	if len(rest) == 0 {
 		// That was the last key.
 		return result
-	} else {
-		// That was not the last key.
-		return traverse(rest, cast.ToStringMap(result))
 	}
+
+	// That was not the last key.
+	return traverse(rest, cast.ToStringMap(result))
 }
 
 func (p *Page) Author() Author {
--- a/hugolib/pages_related_test.go
+++ b/hugolib/pages_related_test.go
@@ -68,8 +68,8 @@
 	assert.Equal("Page 3", result[1].Title)
 
 	result, err = s.RegularPages.RelatedTo(types.NewKeyValuesStrings("keywords", "bep", "rocks"))
+	assert.NoError(err)
 	assert.Len(result, 2)
 	assert.Equal("Page 2", result[0].Title)
 	assert.Equal("Page 3", result[1].Title)
-
 }
--- a/media/mediaType.go
+++ b/media/mediaType.go
@@ -189,7 +189,7 @@
 	return m, nil
 }
 
-func (t Type) MarshalJSON() ([]byte, error) {
+func (m Type) MarshalJSON() ([]byte, error) {
 	type Alias Type
 	return json.Marshal(&struct {
 		Type   string `json:"type"`
@@ -196,8 +196,8 @@
 		String string `json:"string"`
 		Alias
 	}{
-		Type:   t.Type(),
-		String: t.String(),
-		Alias:  (Alias)(t),
+		Type:   m.Type(),
+		String: m.String(),
+		Alias:  (Alias)(m),
 	})
 }
--- a/output/outputFormat.go
+++ b/output/outputFormat.go
@@ -150,9 +150,9 @@
 
 type Formats []Format
 
-func (f Formats) Len() int           { return len(f) }
-func (f Formats) Swap(i, j int)      { f[i], f[j] = f[j], f[i] }
-func (f Formats) Less(i, j int) bool { return f[i].Name < f[j].Name }
+func (formats Formats) Len() int           { return len(formats) }
+func (formats Formats) Swap(i, j int)      { formats[i], formats[j] = formats[j], formats[i] }
+func (formats Formats) Less(i, j int) bool { return formats[i].Name < formats[j].Name }
 
 // GetBySuffix gets a output format given as suffix, e.g. "html".
 // It will return false if no format could be found, or if the suffix given
@@ -312,17 +312,17 @@
 	return decoder.Decode(input)
 }
 
-func (f Format) BaseFilename() string {
-	return f.BaseName + "." + f.MediaType.Suffix
+func (formats Format) BaseFilename() string {
+	return formats.BaseName + "." + formats.MediaType.Suffix
 }
 
-func (f Format) MarshalJSON() ([]byte, error) {
+func (formats Format) MarshalJSON() ([]byte, error) {
 	type Alias Format
 	return json.Marshal(&struct {
 		MediaType string
 		Alias
 	}{
-		MediaType: f.MediaType.String(),
-		Alias:     (Alias)(f),
+		MediaType: formats.MediaType.String(),
+		Alias:     (Alias)(formats),
 	})
 }
--- a/related/inverted_index.go
+++ b/related/inverted_index.go
@@ -418,7 +418,7 @@
 	}
 
 	if c.ToLower {
-		for i, _ := range c.Indices {
+		for i := range c.Indices {
 			c.Indices[i].ToLower = true
 		}
 	}
--- a/related/inverted_index_test.go
+++ b/related/inverted_index_test.go
@@ -27,9 +27,9 @@
 	date     time.Time
 }
 
-func (k *testDoc) String() string {
+func (d *testDoc) String() string {
 	s := "\n"
-	for k, v := range k.keywords {
+	for k, v := range d.keywords {
 		s += k + ":\t\t"
 		for _, vv := range v {
 			s += "  " + vv.String()
@@ -49,7 +49,7 @@
 	return kw
 }
 
-func (t *testDoc) addKeywords(name string, keywords ...string) *testDoc {
+func (d *testDoc) addKeywords(name string, keywords ...string) *testDoc {
 	keywordm := createTestKeywords(name, keywords...)
 
 	for k, v := range keywordm {
@@ -57,9 +57,9 @@
 		for i := 0; i < len(v); i++ {
 			keywords[i] = StringKeyword(v[i])
 		}
-		t.keywords[k] = keywords
+		d.keywords[k] = keywords
 	}
-	return t
+	return d
 }
 
 func createTestKeywords(name string, keywords ...string) map[string][]string {
@@ -68,12 +68,12 @@
 	}
 }
 
-func (k *testDoc) SearchKeywords(cfg IndexConfig) ([]Keyword, error) {
-	return k.keywords[cfg.Name], nil
+func (d *testDoc) SearchKeywords(cfg IndexConfig) ([]Keyword, error) {
+	return d.keywords[cfg.Name], nil
 }
 
-func (k *testDoc) PubDate() time.Time {
-	return k.date
+func (d *testDoc) PubDate() time.Time {
+	return d.date
 }
 
 func TestSearch(t *testing.T) {
--- a/source/filesystem.go
+++ b/source/filesystem.go
@@ -158,7 +158,7 @@
 	return false
 }
 
-func (s SourceSpec) isNonProcessablePath(filePath string) bool {
+func (sp SourceSpec) isNonProcessablePath(filePath string) bool {
 	base := filepath.Base(filePath)
 	if strings.HasPrefix(base, ".") ||
 		strings.HasPrefix(base, "#") ||
@@ -165,7 +165,7 @@
 		strings.HasSuffix(base, "~") {
 		return true
 	}
-	ignoreFiles := cast.ToStringSlice(s.Cfg.Get("ignoreFiles"))
+	ignoreFiles := cast.ToStringSlice(sp.Cfg.Get("ignoreFiles"))
 	if len(ignoreFiles) > 0 {
 		for _, ignorePattern := range ignoreFiles {
 			match, err := regexp.MatchString(ignorePattern, filePath)
--- a/tpl/collections/collections.go
+++ b/tpl/collections/collections.go
@@ -503,25 +503,25 @@
 	}
 }
 
-func (ins *intersector) handleValuePair(l1vv, l2vv reflect.Value) {
+func (i *intersector) handleValuePair(l1vv, l2vv reflect.Value) {
 	switch kind := l1vv.Kind(); {
 	case kind == reflect.String:
 		l2t, err := toString(l2vv)
 		if err == nil && l1vv.String() == l2t {
-			ins.appendIfNotSeen(l1vv)
+			i.appendIfNotSeen(l1vv)
 		}
 	case isNumber(kind):
 		f1, err1 := numberToFloat(l1vv)
 		f2, err2 := numberToFloat(l2vv)
 		if err1 == nil && err2 == nil && f1 == f2 {
-			ins.appendIfNotSeen(l1vv)
+			i.appendIfNotSeen(l1vv)
 		}
 	case kind == reflect.Ptr, kind == reflect.Struct:
 		if l1vv.Interface() == l2vv.Interface() {
-			ins.appendIfNotSeen(l1vv)
+			i.appendIfNotSeen(l1vv)
 		}
 	case kind == reflect.Interface:
-		ins.handleValuePair(reflect.ValueOf(l1vv.Interface()), l2vv)
+		i.handleValuePair(reflect.ValueOf(l1vv.Interface()), l2vv)
 	}
 }
 
--- a/tpl/fmt/fmt.go
+++ b/tpl/fmt/fmt.go
@@ -37,7 +37,7 @@
 
 }
 
-// Print returns string representation of the passed arguments ending with a newline.
+// Println returns string representation of the passed arguments ending with a newline.
 func (ns *Namespace) Println(a ...interface{}) string {
 	return _fmt.Sprintln(a...)
 }
--- a/tpl/images/images.go
+++ b/tpl/images/images.go
@@ -23,6 +23,7 @@
 	_ "image/jpeg"
 	_ "image/png"
 
+	// Import webp codec
 	_ "golang.org/x/image/webp"
 
 	"github.com/gohugoio/hugo/deps"