shithub: hugo

Download patch

ref: c2c73c2bd21090173135b9dbfdc89400450c4837
parent: 218fceac358ad3c76482ff009be7ccf4df6ce988
author: Bjørn Erik Pedersen <[email protected]>
date: Thu Mar 24 10:11:04 EDT 2016

hugolib: Some more GoLint fixes

--- a/hugolib/pageCache_test.go
+++ b/hugolib/pageCache_test.go
@@ -27,8 +27,8 @@
 		p[0].Description = "changed"
 	}
 
-	var o1 uint64 = 0
-	var o2 uint64 = 0
+	var o1 uint64
+	var o2 uint64
 
 	var wg sync.WaitGroup
 
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -30,6 +30,7 @@
 	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 @@
 	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 @@
 	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 @@
 
 		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 @@
 	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 @@
 					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 @@
 						params = append(params, currItem.val)
 						sc.params = params
 					} else {
-						return sc, shortCodeIllegalState
+						return sc, errShortCodeIllegalState
 					}
 
 				}
--- a/hugolib/siteinfo_test.go
+++ b/hugolib/siteinfo_test.go
@@ -20,7 +20,7 @@
 	"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 @@
 		t.Errorf("Unable to set site.Info.Param")
 	}
 
-	s.prepTemplates("template", SITE_INFO_PARAM_TEMPLATE)
+	s.prepTemplates("template", siteInfoParamTemplate)
 
 	buf := new(bytes.Buffer)