Clean up lint in various packages
authorCameron Moore <moorereason@gmail.com>
Tue, 26 Sep 2017 02:25:33 +0000 (21:25 -0500)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 29 Sep 2017 14:23:16 +0000 (16:23 +0200)
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

12 files changed:
helpers/pygments_test.go
hugolib/handler_meta.go
hugolib/page.go
hugolib/pages_related_test.go
media/mediaType.go
output/outputFormat.go
related/inverted_index.go
related/inverted_index_test.go
source/filesystem.go
tpl/collections/collections.go
tpl/fmt/fmt.go
tpl/images/images.go

index d30f5fcc9418368c91c319b1c213c2bec6c63e59..830b31944284d7ae2fd4ab1fe4c879d9afea1e8f 100644 (file)
@@ -224,13 +224,13 @@ func TestHlLinesToRanges(t *testing.T) {
                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},
        } {
index ae68ed5c7b8e8c215f3ed20b5449f46f2d993157..c1aaf5f8c399dc7b3facde021dfc1ed9a7e81da0 100644 (file)
@@ -34,7 +34,7 @@ type MetaHandler interface {
        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.
index 12bdf312b922d956830fa80018a398427eace567..306d3373496b4e25a57bec1004739e2b608fe8f7 100644 (file)
@@ -65,6 +65,7 @@ const (
        KindPage = "page"
 
        // The rest are node types; home page, sections etc.
+
        KindHome         = "home"
        KindSection      = "section"
        KindTaxonomy     = "taxonomy"
@@ -484,10 +485,10 @@ func traverse(keys []string, m map[string]interface{}) interface{} {
        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 {
index cf5da09831659518984e93037356448172d19a38..8759d8f0fbd2ebeffd0f9a4743c42d7ca7599aab 100644 (file)
@@ -68,8 +68,8 @@ Content
        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)
-
 }
index bfeeeaa9f935a7b790d2faba0094fa1026605f72..33ccb281852ff7d2409de3ee2b793f0ba265a25d 100644 (file)
@@ -189,15 +189,15 @@ func DecodeTypes(maps ...map[string]interface{}) (Types, error) {
        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"`
                String string `json:"string"`
                Alias
        }{
-               Type:   t.Type(),
-               String: t.String(),
-               Alias:  (Alias)(t),
+               Type:   m.Type(),
+               String: m.String(),
+               Alias:  (Alias)(m),
        })
 }
index 4ccc288700763554e9aaa896311d59b3557a74df..fbc9f20cc58ba201367be35c2931097195e57777 100644 (file)
@@ -150,9 +150,9 @@ func init() {
 
 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 @@ func decode(mediaTypes media.Types, input, output interface{}) error {
        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),
        })
 }
index f0d598d33235d2886a66cad917a7ab69515cf8e6..4f0dba7d6804d9069ae81331306ab3a76d2d6962 100644 (file)
@@ -418,7 +418,7 @@ func DecodeConfig(in interface{}) (Config, error) {
        }
 
        if c.ToLower {
-               for i, _ := range c.Indices {
+               for i := range c.Indices {
                        c.Indices[i].ToLower = true
                }
        }
index 781a969fb7341eee70100d726a6d7e78b6e87d9f..2e6b90bbf0b937e7faef63ebd8e68103a9193d78 100644 (file)
@@ -27,9 +27,9 @@ type testDoc struct {
        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 @@ func newTestDoc(name string, keywords ...string) *testDoc {
        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 @@ func (t *testDoc) addKeywords(name string, keywords ...string) *testDoc {
                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 createTestKeywords(name string, keywords ...string) map[string][]string {
        }
 }
 
-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) {
index 446d8c06da43bf982757c7d62c3519dfa8d4e08e..e6e354e9971dcb2d569a70c506b49431a2820d00 100644 (file)
@@ -158,14 +158,14 @@ func (f *Filesystem) avoid(filePath string) bool {
        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, "#") ||
                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)
index 8f09097a75a12b90c695aed86df1d8aaa0290b4e..34b8e7f77fd64aeb857b3d5c3b4bfcabbac32396 100644 (file)
@@ -503,25 +503,25 @@ func (i *intersector) appendIfNotSeen(v reflect.Value) {
        }
 }
 
-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)
        }
 }
 
index e9d47dbd460c7d05de7ee26211921f6c8deb0286..96695442eb32e4b2826b685cca9fbc3f1d38c5f0 100644 (file)
@@ -37,7 +37,7 @@ func (ns *Namespace) Printf(format string, a ...interface{}) string {
 
 }
 
-// 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...)
 }
index ce29ac4d54b7c9a3163f1dcb8ba8b0688c57834f..66999aa37968d507cf9f6d9702af88e3ce29a707 100644 (file)
@@ -23,6 +23,7 @@ import (
        _ "image/jpeg"
        _ "image/png"
 
+       // Import webp codec
        _ "golang.org/x/image/webp"
 
        "github.com/gohugoio/hugo/deps"