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
This commit is contained in:
Cameron Moore 2017-09-25 21:25:33 -05:00 committed by Bjørn Erik Pedersen
parent d45e358a05
commit 47fdfd5196
12 changed files with 44 additions and 42 deletions

View file

@ -224,13 +224,13 @@ func TestHlLinesToRanges(t *testing.T) {
expected interface{} expected interface{}
}{ }{
{"", 1, zero}, {"", 1, zero},
{"1 4", 1, [][2]int{[2]int{1, 1}, [2]int{4, 4}}}, {"1 4", 1, [][2]int{{1, 1}, {4, 4}}},
{"1 4", 2, [][2]int{[2]int{2, 2}, [2]int{5, 5}}}, {"1 4", 2, [][2]int{{2, 2}, {5, 5}}},
{"1-4 5-8", 1, [][2]int{[2]int{1, 4}, [2]int{5, 8}}}, {"1-4 5-8", 1, [][2]int{{1, 4}, {5, 8}}},
{" 1 4 ", 1, [][2]int{[2]int{1, 1}, [2]int{4, 4}}}, {" 1 4 ", 1, [][2]int{{1, 1}, {4, 4}}},
{"1-4 5-8 ", 1, [][2]int{[2]int{1, 4}, [2]int{5, 8}}}, {"1-4 5-8 ", 1, [][2]int{{1, 4}, {5, 8}}},
{"1-4 5", 1, [][2]int{[2]int{1, 4}, [2]int{5, 5}}}, {"1-4 5", 1, [][2]int{{1, 4}, {5, 5}}},
{"4 5-9", 1, [][2]int{[2]int{4, 4}, [2]int{5, 9}}}, {"4 5-9", 1, [][2]int{{4, 4}, {5, 9}}},
{" 1 -4 5 - 8 ", 1, true}, {" 1 -4 5 - 8 ", 1, true},
{"a b", 1, true}, {"a b", 1, true},
} { } {

View file

@ -34,7 +34,7 @@ type MetaHandler interface {
Handle() Handler Handle() Handler
} }
// HandledResults is a channel for HandledResult. // HandleResults is a channel for HandledResult.
type HandleResults chan<- HandledResult type HandleResults chan<- HandledResult
// NewMetaHandler creates a MetaHandle for a given extensions. // NewMetaHandler creates a MetaHandle for a given extensions.

View file

@ -65,6 +65,7 @@ const (
KindPage = "page" KindPage = "page"
// The rest are node types; home page, sections etc. // The rest are node types; home page, sections etc.
KindHome = "home" KindHome = "home"
KindSection = "section" KindSection = "section"
KindTaxonomy = "taxonomy" KindTaxonomy = "taxonomy"
@ -484,11 +485,11 @@ func traverse(keys []string, m map[string]interface{}) interface{} {
if len(rest) == 0 { if len(rest) == 0 {
// That was the last key. // That was the last key.
return result return result
} else { }
// That was not the last key. // That was not the last key.
return traverse(rest, cast.ToStringMap(result)) return traverse(rest, cast.ToStringMap(result))
} }
}
func (p *Page) Author() Author { func (p *Page) Author() Author {
authors := p.Authors() authors := p.Authors()

View file

@ -68,8 +68,8 @@ Content
assert.Equal("Page 3", result[1].Title) assert.Equal("Page 3", result[1].Title)
result, err = s.RegularPages.RelatedTo(types.NewKeyValuesStrings("keywords", "bep", "rocks")) result, err = s.RegularPages.RelatedTo(types.NewKeyValuesStrings("keywords", "bep", "rocks"))
assert.NoError(err)
assert.Len(result, 2) assert.Len(result, 2)
assert.Equal("Page 2", result[0].Title) assert.Equal("Page 2", result[0].Title)
assert.Equal("Page 3", result[1].Title) assert.Equal("Page 3", result[1].Title)
} }

View file

@ -189,15 +189,15 @@ func DecodeTypes(maps ...map[string]interface{}) (Types, error) {
return m, nil return m, nil
} }
func (t Type) MarshalJSON() ([]byte, error) { func (m Type) MarshalJSON() ([]byte, error) {
type Alias Type type Alias Type
return json.Marshal(&struct { return json.Marshal(&struct {
Type string `json:"type"` Type string `json:"type"`
String string `json:"string"` String string `json:"string"`
Alias Alias
}{ }{
Type: t.Type(), Type: m.Type(),
String: t.String(), String: m.String(),
Alias: (Alias)(t), Alias: (Alias)(m),
}) })
} }

View file

@ -150,9 +150,9 @@ func init() {
type Formats []Format type Formats []Format
func (f Formats) Len() int { return len(f) } func (formats Formats) Len() int { return len(formats) }
func (f Formats) Swap(i, j int) { f[i], f[j] = f[j], f[i] } func (formats Formats) Swap(i, j int) { formats[i], formats[j] = formats[j], formats[i] }
func (f Formats) Less(i, j int) bool { return f[i].Name < f[j].Name } 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". // 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 // 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) return decoder.Decode(input)
} }
func (f Format) BaseFilename() string { func (formats Format) BaseFilename() string {
return f.BaseName + "." + f.MediaType.Suffix return formats.BaseName + "." + formats.MediaType.Suffix
} }
func (f Format) MarshalJSON() ([]byte, error) { func (formats Format) MarshalJSON() ([]byte, error) {
type Alias Format type Alias Format
return json.Marshal(&struct { return json.Marshal(&struct {
MediaType string MediaType string
Alias Alias
}{ }{
MediaType: f.MediaType.String(), MediaType: formats.MediaType.String(),
Alias: (Alias)(f), Alias: (Alias)(formats),
}) })
} }

View file

@ -418,7 +418,7 @@ func DecodeConfig(in interface{}) (Config, error) {
} }
if c.ToLower { if c.ToLower {
for i, _ := range c.Indices { for i := range c.Indices {
c.Indices[i].ToLower = true c.Indices[i].ToLower = true
} }
} }

View file

@ -27,9 +27,9 @@ type testDoc struct {
date time.Time date time.Time
} }
func (k *testDoc) String() string { func (d *testDoc) String() string {
s := "\n" s := "\n"
for k, v := range k.keywords { for k, v := range d.keywords {
s += k + ":\t\t" s += k + ":\t\t"
for _, vv := range v { for _, vv := range v {
s += " " + vv.String() s += " " + vv.String()
@ -49,7 +49,7 @@ func newTestDoc(name string, keywords ...string) *testDoc {
return kw return kw
} }
func (t *testDoc) addKeywords(name string, keywords ...string) *testDoc { func (d *testDoc) addKeywords(name string, keywords ...string) *testDoc {
keywordm := createTestKeywords(name, keywords...) keywordm := createTestKeywords(name, keywords...)
for k, v := range keywordm { 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++ { for i := 0; i < len(v); i++ {
keywords[i] = StringKeyword(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 { 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) { func (d *testDoc) SearchKeywords(cfg IndexConfig) ([]Keyword, error) {
return k.keywords[cfg.Name], nil return d.keywords[cfg.Name], nil
} }
func (k *testDoc) PubDate() time.Time { func (d *testDoc) PubDate() time.Time {
return k.date return d.date
} }
func TestSearch(t *testing.T) { func TestSearch(t *testing.T) {

View file

@ -158,14 +158,14 @@ func (f *Filesystem) avoid(filePath string) bool {
return false return false
} }
func (s SourceSpec) isNonProcessablePath(filePath string) bool { func (sp SourceSpec) isNonProcessablePath(filePath string) bool {
base := filepath.Base(filePath) base := filepath.Base(filePath)
if strings.HasPrefix(base, ".") || if strings.HasPrefix(base, ".") ||
strings.HasPrefix(base, "#") || strings.HasPrefix(base, "#") ||
strings.HasSuffix(base, "~") { strings.HasSuffix(base, "~") {
return true return true
} }
ignoreFiles := cast.ToStringSlice(s.Cfg.Get("ignoreFiles")) ignoreFiles := cast.ToStringSlice(sp.Cfg.Get("ignoreFiles"))
if len(ignoreFiles) > 0 { if len(ignoreFiles) > 0 {
for _, ignorePattern := range ignoreFiles { for _, ignorePattern := range ignoreFiles {
match, err := regexp.MatchString(ignorePattern, filePath) match, err := regexp.MatchString(ignorePattern, filePath)

View 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(); { switch kind := l1vv.Kind(); {
case kind == reflect.String: case kind == reflect.String:
l2t, err := toString(l2vv) l2t, err := toString(l2vv)
if err == nil && l1vv.String() == l2t { if err == nil && l1vv.String() == l2t {
ins.appendIfNotSeen(l1vv) i.appendIfNotSeen(l1vv)
} }
case isNumber(kind): case isNumber(kind):
f1, err1 := numberToFloat(l1vv) f1, err1 := numberToFloat(l1vv)
f2, err2 := numberToFloat(l2vv) f2, err2 := numberToFloat(l2vv)
if err1 == nil && err2 == nil && f1 == f2 { if err1 == nil && err2 == nil && f1 == f2 {
ins.appendIfNotSeen(l1vv) i.appendIfNotSeen(l1vv)
} }
case kind == reflect.Ptr, kind == reflect.Struct: case kind == reflect.Ptr, kind == reflect.Struct:
if l1vv.Interface() == l2vv.Interface() { if l1vv.Interface() == l2vv.Interface() {
ins.appendIfNotSeen(l1vv) i.appendIfNotSeen(l1vv)
} }
case kind == reflect.Interface: case kind == reflect.Interface:
ins.handleValuePair(reflect.ValueOf(l1vv.Interface()), l2vv) i.handleValuePair(reflect.ValueOf(l1vv.Interface()), l2vv)
} }
} }

View 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 { func (ns *Namespace) Println(a ...interface{}) string {
return _fmt.Sprintln(a...) return _fmt.Sprintln(a...)
} }

View file

@ -23,6 +23,7 @@ import (
_ "image/jpeg" _ "image/jpeg"
_ "image/png" _ "image/png"
// Import webp codec
_ "golang.org/x/image/webp" _ "golang.org/x/image/webp"
"github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/deps"