hugolib: Some more GoLint fixes
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 24 Mar 2016 13:11:04 +0000 (14:11 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 24 Mar 2016 13:11:04 +0000 (14:11 +0100)
hugolib/pageCache_test.go
hugolib/shortcode.go
hugolib/siteinfo_test.go

index c760b03eda597f96e3421934f51741cfdbdd1e8c..12fa7ae9a09711a79621e389473b45546b898073 100644 (file)
@@ -27,8 +27,8 @@ func TestPageCache(t *testing.T) {
                p[0].Description = "changed"
        }
 
-       var o1 uint64 = 0
-       var o2 uint64 = 0
+       var o1 uint64
+       var o2 uint64
 
        var wg sync.WaitGroup
 
index b81c95394e3ae2c9d8c2b537be146f45402395c2..782f0e21a7b5f7fef63f19b27eb476ff2ea03356 100644 (file)
@@ -30,6 +30,7 @@ import (
        jww "github.com/spf13/jwalterweatherman"
 )
 
+// ShortcodeWithPage is the "." context in a shortcode template.
 type ShortcodeWithPage struct {
        Params        interface{}
        Inner         template.HTML
@@ -39,18 +40,23 @@ type ShortcodeWithPage struct {
        scratch       *Scratch
 }
 
+// Site returns information about the current site.
 func (scp *ShortcodeWithPage) Site() *SiteInfo {
        return scp.Page.Site
 }
 
+// Ref is a shortcut to the Ref method on Page.
 func (scp *ShortcodeWithPage) Ref(ref string) (string, error) {
        return scp.Page.Ref(ref)
 }
 
+// RelRef is a shortcut to the RelRef method on Page.
 func (scp *ShortcodeWithPage) RelRef(ref string) (string, error) {
        return scp.Page.RelRef(ref)
 }
 
+// Scratch returns a scratch-pad scoped for this shortcode. This can be used
+// as a temporary storage for variables, counters etc.
 func (scp *ShortcodeWithPage) Scratch() *Scratch {
        if scp.scratch == nil {
                scp.scratch = newScratch()
@@ -58,6 +64,7 @@ func (scp *ShortcodeWithPage) Scratch() *Scratch {
        return scp.scratch
 }
 
+// Get is a convenience method to look up shortcode parameters by its key.
 func (scp *ShortcodeWithPage) Get(key interface{}) interface{} {
        if reflect.ValueOf(scp.Params).Len() == 0 {
                return nil
@@ -154,9 +161,8 @@ func HandleShortcodes(stringToParse string, page *Page, t tpl.Template) (string,
 
                if err != nil {
                        return "", fmt.Errorf("Fail to replace short code tokens in %s:\n%s", page.BaseFileName(), err.Error())
-               } else {
-                       return string(tmpContentWithTokensReplaced), nil
                }
+               return string(tmpContentWithTokensReplaced), nil
        }
 
        return tmpContent, nil
@@ -303,7 +309,7 @@ func renderShortcodes(shortcodes map[string]shortcode, p *Page, t tpl.Template)
        return renderedShortcodes
 }
 
-var shortCodeIllegalState = errors.New("Illegal shortcode state")
+var errShortCodeIllegalState = errors.New("Illegal shortcode state")
 
 // pageTokens state:
 // - before: positioned just before the shortcode start
@@ -395,7 +401,7 @@ Loop:
                                        if params, ok := sc.params.(map[string]string); ok {
                                                params[currItem.val] = pt.next().val
                                        } else {
-                                               return sc, shortCodeIllegalState
+                                               return sc, errShortCodeIllegalState
                                        }
 
                                }
@@ -410,7 +416,7 @@ Loop:
                                                params = append(params, currItem.val)
                                                sc.params = params
                                        } else {
-                                               return sc, shortCodeIllegalState
+                                               return sc, errShortCodeIllegalState
                                        }
 
                                }
index 4e4c924e9acf55d24881b1b8067261d968be3e9f..ff2e6a91cea5bcf6b89978583c84c9ea8b936642 100644 (file)
@@ -20,7 +20,7 @@ import (
        "github.com/spf13/viper"
 )
 
-const SITE_INFO_PARAM_TEMPLATE = `{{ .Site.Params.MyGlobalParam }}`
+const siteInfoParamTemplate = `{{ .Site.Params.MyGlobalParam }}`
 
 func TestSiteInfoParams(t *testing.T) {
        viper.Reset()
@@ -34,7 +34,7 @@ func TestSiteInfoParams(t *testing.T) {
                t.Errorf("Unable to set site.Info.Param")
        }
 
-       s.prepTemplates("template", SITE_INFO_PARAM_TEMPLATE)
+       s.prepTemplates("template", siteInfoParamTemplate)
 
        buf := new(bytes.Buffer)