From e007c9b25d076f5705afb63fda4f3abd3d05b7b8 Mon Sep 17 00:00:00 2001 From: bep Date: Sat, 7 Mar 2015 12:53:20 +0100 Subject: [PATCH] hugolib: apply some more Golint rules --- hugolib/media.go | 4 ++-- hugolib/pageSort.go | 10 ++++------ hugolib/pagination.go | 5 ++++- hugolib/shortcode.go | 5 ++--- hugolib/site.go | 23 +++++++++++------------ hugolib/taxonomy.go | 20 ++++++++++---------- 6 files changed, 33 insertions(+), 34 deletions(-) diff --git a/hugolib/media.go b/hugolib/media.go index 489c998d1..38344ebe3 100644 --- a/hugolib/media.go +++ b/hugolib/media.go @@ -13,7 +13,7 @@ package hugolib -// An image contains metadata for images + image sitemaps +// An Image contains metadata for images + image sitemaps // https://support.google.com/webmasters/answer/178636?hl=en type Image struct { @@ -37,7 +37,7 @@ type Image struct { License string } -// An video contains metadata for videos + video sitemaps +// A Video contains metadata for videos + video sitemaps // https://support.google.com/webmasters/answer/80471?hl=en type Video struct { ThumbnailLoc string diff --git a/hugolib/pageSort.go b/hugolib/pageSort.go index dbbdc4c20..da068a825 100644 --- a/hugolib/pageSort.go +++ b/hugolib/pageSort.go @@ -21,13 +21,13 @@ import ( * Implementation of a custom sorter for Pages */ -// A type to implement the sort interface for Pages +// A PageSorter implements the sort interface for Pages type PageSorter struct { pages Pages by PageBy } -// Closure used in the Sort.Less method. +// PageBy is a closure used in the Sort.Less method. type PageBy func(p1, p2 *Page) bool func (by PageBy) Sort(pages Pages) { @@ -41,9 +41,8 @@ func (by PageBy) Sort(pages Pages) { var DefaultPageSort = func(p1, p2 *Page) bool { if p1.Weight == p2.Weight { return p1.Date.Unix() > p2.Date.Unix() - } else { - return p1.Weight < p2.Weight } + return p1.Weight < p2.Weight } func (ps *PageSorter) Len() int { return len(ps.pages) } @@ -59,9 +58,8 @@ func (p Pages) Sort() { func (p Pages) Limit(n int) Pages { if len(p) < n { return p[0:n] - } else { - return p } + return p } func (p Pages) ByWeight() Pages { diff --git a/hugolib/pagination.go b/hugolib/pagination.go index 8fb4f4e4a..55d7104b6 100644 --- a/hugolib/pagination.go +++ b/hugolib/pagination.go @@ -131,7 +131,7 @@ func splitPages(pages Pages, size int) []Pages { return split } -// Paginate gets this Node's paginator if it's already created. +// Paginator gets this Node's paginator if it's already created. // If it's not, one will be created with all pages in Data["Pages"]. func (n *Node) Paginator() (*pager, error) { @@ -163,9 +163,12 @@ func (n *Node) Paginator() (*pager, error) { return n.paginator, nil } +// Paginator on Page isn't supported, calling this yields an error. func (p *Page) Paginator() (*pager, error) { return nil, errors.New("Paginators not supported for content pages.") } + +// Paginate on Page isn't supported, calling this yields an error. func (p *Page) Paginate(seq interface{}) (*pager, error) { return nil, errors.New("Paginators not supported for content pages.") } diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go index f1be54e2a..ca310d6b0 100644 --- a/hugolib/shortcode.go +++ b/hugolib/shortcode.go @@ -125,7 +125,7 @@ func (sc shortcode) String() string { return fmt.Sprintf("%s(%q, %t){%s}", sc.name, params, sc.doMarkup, sc.inner) } -// all in one go: extract, render and replace +// ShortcodesHandle does all in one go: extract, render and replace // only used for testing func ShortcodesHandle(stringToParse string, page *Page, t tpl.Template) string { tmpContent, tmpShortcodes := extractAndRenderShortcodes(stringToParse, page, t) @@ -467,9 +467,8 @@ func replaceShortcodeTokens(source []byte, prefix string, wrapped bool, replacem if val, ok := replacements[key]; ok { return []byte(val) - } else { - panic(fmt.Errorf("unknown shortcode token %q", key)) } + panic(fmt.Errorf("unknown shortcode token %q", key)) }) return b, err diff --git a/hugolib/site.go b/hugolib/site.go index 48df3041a..adef3d499 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -167,8 +167,8 @@ func (s *SiteInfo) refLink(ref string, page *Page, relative bool) (string, error return "", err } - var target *Page = nil - var link string = "" + var target *Page + var link string if refUrl.Path != "" { for _, page := range []*Page(*s.Pages) { @@ -179,7 +179,7 @@ func (s *SiteInfo) refLink(ref string, page *Page, relative bool) (string, error } if target == nil { - return "", errors.New(fmt.Sprintf("No page found with path or logical name \"%s\".\n", refUrl.Path)) + return "", fmt.Errorf("No page found with path or logical name \"%s\".\n", refUrl.Path) } if relative { @@ -649,11 +649,11 @@ func readCollator(s *Site, results <-chan HandledResult, errs chan<- error) { } if r.page.IsDraft() { - s.draftCount += 1 + s.draftCount++ } if r.page.IsFuture() { - s.futureCount += 1 + s.futureCount++ } } } @@ -851,7 +851,7 @@ func (s *Site) possibleTaxonomies() (taxonomies []string) { return } -// Render shell pages that simply have a redirect in the header +// RenderAliases renders shell pages that simply have a redirect in the header func (s *Site) RenderAliases() error { for _, p := range s.Pages { for _, a := range p.Aliases { @@ -867,7 +867,7 @@ func (s *Site) RenderAliases() error { return nil } -// Render pages each corresponding to a markdown file +// RenderPages renders pages each corresponding to a markdown file func (s *Site) RenderPages() error { results := make(chan error) @@ -967,9 +967,8 @@ func (s *Site) appendThemeTemplates(in []string) []string { } } return out - } else { - return in } + return in } type taxRenderInfo struct { @@ -979,7 +978,7 @@ type taxRenderInfo struct { plural string } -// Render the listing pages based on the meta data +// RenderTaxonomiesLists renders the listing pages based on the meta data // each unique term within a taxonomy will have a page created func (s *Site) RenderTaxonomiesLists() error { wg := &sync.WaitGroup{} @@ -1093,7 +1092,7 @@ func taxonomyRenderer(s *Site, taxes <-chan taxRenderInfo, results chan<- error, } } -// Render a page per taxonomy that lists the terms for that taxonomy +// RenderListsOfTaxonomyTerms renders a page per taxonomy that lists the terms for that taxonomy func (s *Site) RenderListsOfTaxonomyTerms() (err error) { taxonomies := viper.GetStringMapString("Taxonomies") for singular, plural := range taxonomies { @@ -1132,7 +1131,7 @@ func (s *Site) newSectionListNode(section string, data WeightedPages) *Node { return n } -// Render a page for each section +// RenderSectionLists renders a page for each section func (s *Site) RenderSectionLists() error { for section, data := range s.Sections { diff --git a/hugolib/taxonomy.go b/hugolib/taxonomy.go index fdba1e56e..1daddfc40 100644 --- a/hugolib/taxonomy.go +++ b/hugolib/taxonomy.go @@ -184,18 +184,18 @@ func (wp WeightedPages) Next(cur *Page) *Page { return nil } -func (p WeightedPages) Len() int { return len(p) } -func (p WeightedPages) Swap(i, j int) { p[i], p[j] = p[j], p[i] } -func (p WeightedPages) Sort() { sort.Stable(p) } -func (p WeightedPages) Count() int { return len(p) } -func (p WeightedPages) Less(i, j int) bool { - if p[i].Weight == p[j].Weight { - if p[i].Page.Date.Equal(p[j].Page.Date) { - return p[i].Page.Title < p[j].Page.Title +func (wp WeightedPages) Len() int { return len(wp) } +func (wp WeightedPages) Swap(i, j int) { wp[i], wp[j] = wp[j], wp[i] } +func (wp WeightedPages) Sort() { sort.Stable(wp) } +func (wp WeightedPages) Count() int { return len(wp) } +func (wp WeightedPages) Less(i, j int) bool { + if wp[i].Weight == wp[j].Weight { + if wp[i].Page.Date.Equal(wp[j].Page.Date) { + return wp[i].Page.Title < wp[j].Page.Title } - return p[i].Page.Date.After(p[i].Page.Date) + return wp[i].Page.Date.After(wp[i].Page.Date) } - return p[i].Weight < p[j].Weight + return wp[i].Weight < wp[j].Weight } // TODO mimic PagesSorter for WeightedPages