mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
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:
parent
d45e358a05
commit
47fdfd5196
12 changed files with 44 additions and 42 deletions
|
@ -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},
|
||||
} {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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...)
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
|
||||
// Import webp codec
|
||||
_ "golang.org/x/image/webp"
|
||||
|
||||
"github.com/gohugoio/hugo/deps"
|
||||
|
|
Loading…
Reference in a new issue