diff options
author | Bjørn Erik Pedersen <[email protected]> | 2020-12-02 13:23:25 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2020-12-03 13:12:58 +0100 |
commit | d90e37e0c6e812f9913bf256c9c81aa05b7a08aa (patch) | |
tree | 7b1b14464eefec1188ca2eed53c64e4823453cc9 /common | |
parent | 32471b57bde51c55a15dbf1db75d6e5f7232c347 (diff) | |
download | hugo-d90e37e0c6e812f9913bf256c9c81aa05b7a08aa.tar.gz hugo-d90e37e0c6e812f9913bf256c9c81aa05b7a08aa.zip |
all: Format code with gofumpt
See https://github.com/mvdan/gofumpt
Diffstat (limited to 'common')
-rw-r--r-- | common/collections/append.go | 1 | ||||
-rw-r--r-- | common/collections/append_test.go | 43 | ||||
-rw-r--r-- | common/collections/slice_test.go | 14 | ||||
-rw-r--r-- | common/herrors/error_locator_test.go | 1 | ||||
-rw-r--r-- | common/herrors/file_error.go | 4 | ||||
-rw-r--r-- | common/herrors/file_error_test.go | 1 | ||||
-rw-r--r-- | common/hreflect/helpers.go | 1 | ||||
-rw-r--r-- | common/hugo/hugo_test.go | 1 | ||||
-rw-r--r-- | common/hugo/version.go | 2 | ||||
-rw-r--r-- | common/loggers/ignorableLogger.go | 1 | ||||
-rw-r--r-- | common/loggers/loggers.go | 9 | ||||
-rw-r--r-- | common/loggers/loggers_test.go | 1 | ||||
-rw-r--r-- | common/maps/maps_test.go | 1 | ||||
-rw-r--r-- | common/maps/params.go | 1 | ||||
-rw-r--r-- | common/maps/params_test.go | 4 | ||||
-rw-r--r-- | common/maps/scratch.go | 1 | ||||
-rw-r--r-- | common/maps/scratch_test.go | 3 | ||||
-rw-r--r-- | common/para/para_test.go | 4 | ||||
-rw-r--r-- | common/text/position.go | 3 | ||||
-rw-r--r-- | common/text/position_test.go | 1 | ||||
-rw-r--r-- | common/text/transform_test.go | 1 | ||||
-rw-r--r-- | common/types/convert_test.go | 2 |
22 files changed, 40 insertions, 60 deletions
diff --git a/common/collections/append.go b/common/collections/append.go index b56455bc9..d6fb89241 100644 --- a/common/collections/append.go +++ b/common/collections/append.go @@ -51,7 +51,6 @@ func Append(to interface{}, from ...interface{}) (interface{}, error) { } else if !fromt.AssignableTo(tot) { // Fall back to a []interface{} slice. return appendToInterfaceSliceFromValues(tov, fromv) - } } } diff --git a/common/collections/append_test.go b/common/collections/append_test.go index 4086570b8..7d6117de8 100644 --- a/common/collections/append_test.go +++ b/common/collections/append_test.go @@ -36,28 +36,44 @@ func TestAppend(t *testing.T) { {nil, []interface{}{"a", "b"}, []string{"a", "b"}}, {nil, []interface{}{nil}, []interface{}{nil}}, {[]interface{}{}, []interface{}{[]string{"c", "d", "e"}}, []string{"c", "d", "e"}}, - {tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}}, + { + tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}}, []interface{}{&tstSlicer{"c"}}, - tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}, &tstSlicer{"c"}}}, - {&tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}}, + tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}, &tstSlicer{"c"}}, + }, + { + &tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}}, []interface{}{&tstSlicer{"c"}}, - tstSlicers{&tstSlicer{"a"}, + tstSlicers{ + &tstSlicer{"a"}, &tstSlicer{"b"}, - &tstSlicer{"c"}}}, - {testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn1{"b"}}, + &tstSlicer{"c"}, + }, + }, + { + testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn1{"b"}}, []interface{}{&tstSlicerIn1{"c"}}, - testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn1{"b"}, &tstSlicerIn1{"c"}}}, + testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn1{"b"}, &tstSlicerIn1{"c"}}, + }, //https://github.com/gohugoio/hugo/issues/5361 - {[]string{"a", "b"}, []interface{}{tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}}}, - []interface{}{"a", "b", &tstSlicer{"a"}, &tstSlicer{"b"}}}, - {[]string{"a", "b"}, []interface{}{&tstSlicer{"a"}}, - []interface{}{"a", "b", &tstSlicer{"a"}}}, + { + []string{"a", "b"}, + []interface{}{tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}}}, + []interface{}{"a", "b", &tstSlicer{"a"}, &tstSlicer{"b"}}, + }, + { + []string{"a", "b"}, + []interface{}{&tstSlicer{"a"}}, + []interface{}{"a", "b", &tstSlicer{"a"}}, + }, // Errors {"", []interface{}{[]string{"a", "b"}}, false}, // No string concatenation. - {"ab", + { + "ab", []interface{}{"c"}, - false}, + false, + }, } { result, err := Append(test.start, test.addend...) @@ -71,5 +87,4 @@ func TestAppend(t *testing.T) { c.Assert(err, qt.IsNil) c.Assert(result, qt.DeepEquals, test.expected) } - } diff --git a/common/collections/slice_test.go b/common/collections/slice_test.go index 3ebfe6d11..93bad84da 100644 --- a/common/collections/slice_test.go +++ b/common/collections/slice_test.go @@ -20,11 +20,13 @@ import ( qt "github.com/frankban/quicktest" ) -var _ Slicer = (*tstSlicer)(nil) -var _ Slicer = (*tstSlicerIn1)(nil) -var _ Slicer = (*tstSlicerIn2)(nil) -var _ testSlicerInterface = (*tstSlicerIn1)(nil) -var _ testSlicerInterface = (*tstSlicerIn1)(nil) +var ( + _ Slicer = (*tstSlicer)(nil) + _ Slicer = (*tstSlicerIn1)(nil) + _ Slicer = (*tstSlicerIn2)(nil) + _ testSlicerInterface = (*tstSlicerIn1)(nil) + _ testSlicerInterface = (*tstSlicerIn1)(nil) +) type testSlicerInterface interface { Name() string @@ -54,7 +56,6 @@ func (p *tstSlicerIn1) Slice(in interface{}) (interface{}, error) { default: return nil, errors.New("invalid type") } - } return result, nil } @@ -120,5 +121,4 @@ func TestSlice(t *testing.T) { c.Assert(test.expected, qt.DeepEquals, result, errMsg) } - } diff --git a/common/herrors/error_locator_test.go b/common/herrors/error_locator_test.go index bc34a2cdf..0cd5fb2d7 100644 --- a/common/herrors/error_locator_test.go +++ b/common/herrors/error_locator_test.go @@ -125,5 +125,4 @@ E`, offsetMatcher) c.Assert(location.Lines, qt.DeepEquals, []string{"A", "B", "C", "D"}) c.Assert(location.Position().LineNumber, qt.Equals, 2) c.Assert(location.LinesPos, qt.Equals, 1) - } diff --git a/common/herrors/file_error.go b/common/herrors/file_error.go index 039c25dc8..1cb31ff9f 100644 --- a/common/herrors/file_error.go +++ b/common/herrors/file_error.go @@ -21,9 +21,7 @@ import ( "github.com/pkg/errors" ) -var ( - _ causer = (*fileError)(nil) -) +var _ causer = (*fileError)(nil) // FileError represents an error when handling a file: Parsing a config file, // execute a template etc. diff --git a/common/herrors/file_error_test.go b/common/herrors/file_error_test.go index b1b5c5a02..4b42f8f39 100644 --- a/common/herrors/file_error_test.go +++ b/common/herrors/file_error_test.go @@ -52,5 +52,4 @@ func TestToLineNumberError(t *testing.T) { c.Assert(pos.ColumnNumber, qt.Equals, test.columnNumber, errMsg) c.Assert(errors.Cause(got), qt.Not(qt.IsNil)) } - } diff --git a/common/hreflect/helpers.go b/common/hreflect/helpers.go index d936da19c..cd5714d2f 100644 --- a/common/hreflect/helpers.go +++ b/common/hreflect/helpers.go @@ -67,7 +67,6 @@ func IsTruthful(in interface{}) bool { default: return IsTruthfulValue(reflect.ValueOf(in)) } - } var zeroType = reflect.TypeOf((*types.Zeroer)(nil)).Elem() diff --git a/common/hugo/hugo_test.go b/common/hugo/hugo_test.go index 8840a9e9e..0862f36e7 100644 --- a/common/hugo/hugo_test.go +++ b/common/hugo/hugo_test.go @@ -35,5 +35,4 @@ func TestHugoInfo(t *testing.T) { devHugoInfo := NewInfo("development") c.Assert(devHugoInfo.IsProduction(), qt.Equals, false) - } diff --git a/common/hugo/version.go b/common/hugo/version.go index 038537fc0..b87dab547 100644 --- a/common/hugo/version.go +++ b/common/hugo/version.go @@ -16,7 +16,6 @@ package hugo import ( "fmt" "io" - "runtime" "strings" @@ -146,7 +145,6 @@ func BuildVersionString() string { } return fmt.Sprintf("%s %s %s BuildDate: %s", program, version, osArch, date) - } func version(version float32, patchVersion int, suffix string) string { diff --git a/common/loggers/ignorableLogger.go b/common/loggers/ignorableLogger.go index 1bd4d99b8..766aae07c 100644 --- a/common/loggers/ignorableLogger.go +++ b/common/loggers/ignorableLogger.go @@ -34,7 +34,6 @@ func NewIgnorableLogger(logger Logger, statements ...string) IgnorableLogger { statementsSet := make(map[string]bool) for _, s := range statements { statementsSet[strings.ToLower(s)] = true - } return ignorableLogger{ Logger: logger, diff --git a/common/loggers/loggers.go b/common/loggers/loggers.go index 5c04b9eab..c9b5d21be 100644 --- a/common/loggers/loggers.go +++ b/common/loggers/loggers.go @@ -29,10 +29,8 @@ import ( jww "github.com/spf13/jwalterweatherman" ) -var ( - // Counts ERROR logs to the global jww logger. - GlobalErrorCounter *jww.Counter -) +// Counts ERROR logs to the global jww logger. +var GlobalErrorCounter *jww.Counter func init() { GlobalErrorCounter = &jww.Counter{} @@ -253,7 +251,6 @@ func (a labelColorizer) Write(p []byte) (n int, err error) { // bytes, so we lie a little. _, err = a.w.Write([]byte(replaced)) return len(p), err - } // InitGlobalLogger initializes the global logger, used in some rare cases. @@ -264,7 +261,6 @@ func InitGlobalLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, lo jww.SetLogOutput(logHandle) jww.SetLogThreshold(logThreshold) jww.SetStdoutThreshold(stdoutThreshold) - } func getLogWriters(outHandle, logHandle io.Writer) (io.Writer, io.Writer) { @@ -279,7 +275,6 @@ func getLogWriters(outHandle, logHandle io.Writer) (io.Writer, io.Writer) { } return outHandle, logHandle - } type fatalLogWriter int diff --git a/common/loggers/loggers_test.go b/common/loggers/loggers_test.go index 7af3ca9da..0c0cc859b 100644 --- a/common/loggers/loggers_test.go +++ b/common/loggers/loggers_test.go @@ -31,7 +31,6 @@ func TestLogger(t *testing.T) { l.Warnln("A warning") c.Assert(l.LogCounters().ErrorCounter.Count(), qt.Equals, uint64(2)) - } func TestLoggerToWriterWithPrefix(t *testing.T) { diff --git a/common/maps/maps_test.go b/common/maps/maps_test.go index bde77071d..7e527aac5 100644 --- a/common/maps/maps_test.go +++ b/common/maps/maps_test.go @@ -154,5 +154,4 @@ func TestRenameKeys(t *testing.T) { if !reflect.DeepEqual(expected, m) { t.Errorf("Expected\n%#v, got\n%#v\n", expected, m) } - } diff --git a/common/maps/params.go b/common/maps/params.go index 5e973051b..4c881093c 100644 --- a/common/maps/params.go +++ b/common/maps/params.go @@ -80,7 +80,6 @@ func GetNestedParam(keyStr, separator string, candidates ...Params) (interface{} } return nil, nil - } func GetNestedParamFn(keyStr, separator string, lookupFn func(key string) interface{}) (interface{}, string, map[string]interface{}, error) { diff --git a/common/maps/params_test.go b/common/maps/params_test.go index 46d672d87..df8cbf8d6 100644 --- a/common/maps/params_test.go +++ b/common/maps/params_test.go @@ -20,7 +20,6 @@ import ( ) func TestGetNestedParam(t *testing.T) { - m := map[string]interface{}{ "string": "value", "first": 1, @@ -48,12 +47,10 @@ func TestGetNestedParam(t *testing.T) { c.Assert(must("nested.nestednested.color", ".", m), qt.Equals, "green") c.Assert(must("string.name", ".", m), qt.IsNil) c.Assert(must("nested.foo", ".", m), qt.IsNil) - } // https://github.com/gohugoio/hugo/issues/7903 func TestGetNestedParamFnNestedNewKey(t *testing.T) { - c := qt.New(t) nested := map[string]interface{}{ @@ -71,5 +68,4 @@ func TestGetNestedParamFnNestedNewKey(t *testing.T) { c.Assert(existing, qt.IsNil) c.Assert(nestedKey, qt.Equals, "new") c.Assert(owner, qt.DeepEquals, nested) - } diff --git a/common/maps/scratch.go b/common/maps/scratch.go index 7a3cd3748..ccd03ef32 100644 --- a/common/maps/scratch.go +++ b/common/maps/scratch.go @@ -51,7 +51,6 @@ func NewScratcher() Scratcher { // // If the first add for a key is an array or slice, then the next value(s) will be appended. func (c *Scratch) Add(key string, newAddend interface{}) (string, error) { - var newVal interface{} c.mu.RLock() existingAddend, found := c.values[key] diff --git a/common/maps/scratch_test.go b/common/maps/scratch_test.go index 40df3bb6b..d893ccb03 100644 --- a/common/maps/scratch_test.go +++ b/common/maps/scratch_test.go @@ -53,7 +53,6 @@ func TestScratchAdd(t *testing.T) { if err == nil { t.Errorf("Expected error from invalid arithmetic") } - } func TestScratchAddSlice(t *testing.T) { @@ -96,7 +95,6 @@ func TestScratchAddTypedSliceToInterfaceSlice(t *testing.T) { _, err := scratch.Add("slice", []int{1, 2}) c.Assert(err, qt.IsNil) c.Assert(scratch.Get("slice"), qt.DeepEquals, []int{1, 2}) - } // https://github.com/gohugoio/hugo/issues/5361 @@ -110,7 +108,6 @@ func TestScratchAddDifferentTypedSliceToInterfaceSlice(t *testing.T) { _, err := scratch.Add("slice", []int{1, 2}) c.Assert(err, qt.IsNil) c.Assert(scratch.Get("slice"), qt.DeepEquals, []interface{}{"foo", 1, 2}) - } func TestScratchSet(t *testing.T) { diff --git a/common/para/para_test.go b/common/para/para_test.go index 9b268b0c0..e89f9360b 100644 --- a/common/para/para_test.go +++ b/common/para/para_test.go @@ -16,7 +16,6 @@ package para import ( "context" "runtime" - "sort" "sync" "sync/atomic" @@ -60,7 +59,6 @@ func TestPara(t *testing.T) { c.Assert(sort.IntsAreSorted(result), qt.Equals, false, qt.Commentf("Para does not seem to be parallel")) sort.Ints(result) c.Assert(result, qt.DeepEquals, ints) - }) c.Run("Time", func(c *qt.C) { @@ -84,7 +82,5 @@ func TestPara(t *testing.T) { c.Assert(r.Wait(), qt.IsNil) c.Assert(counter, qt.Equals, int64(n)) c.Assert(time.Since(start) < n/2*time.Millisecond, qt.Equals, true) - }) - } diff --git a/common/text/position.go b/common/text/position.go index 0c43c5ae7..5dd64526a 100644 --- a/common/text/position.go +++ b/common/text/position.go @@ -50,12 +50,11 @@ func (pos Position) IsValid() bool { var positionStringFormatfunc func(p Position) string func createPositionStringFormatter(formatStr string) func(p Position) string { - if formatStr == "" { formatStr = "\":file::line::col\"" } - var identifiers = []string{":file", ":line", ":col"} + identifiers := []string{":file", ":line", ":col"} var identifiersFound []string for i := range formatStr { diff --git a/common/text/position_test.go b/common/text/position_test.go index ba4824344..a1f43c5d4 100644 --- a/common/text/position_test.go +++ b/common/text/position_test.go @@ -29,5 +29,4 @@ func TestPositionStringFormatter(t *testing.T) { c.Assert(createPositionStringFormatter("好::col")(pos), qt.Equals, "好:13") c.Assert(createPositionStringFormatter("")(pos), qt.Equals, "\"/my/file.txt:12:13\"") c.Assert(pos.String(), qt.Equals, "\"/my/file.txt:12:13\"") - } diff --git a/common/text/transform_test.go b/common/text/transform_test.go index 70b10d149..08265f976 100644 --- a/common/text/transform_test.go +++ b/common/text/transform_test.go @@ -25,5 +25,4 @@ func TestRemoveAccents(t *testing.T) { c.Assert(string(RemoveAccents([]byte("Resumé"))), qt.Equals, "Resume") c.Assert(string(RemoveAccents([]byte("Hugo Rocks!"))), qt.Equals, "Hugo Rocks!") c.Assert(string(RemoveAccentsString("Resumé")), qt.Equals, "Resume") - } diff --git a/common/types/convert_test.go b/common/types/convert_test.go index 8a4f04db2..d053ede60 100644 --- a/common/types/convert_test.go +++ b/common/types/convert_test.go @@ -26,7 +26,6 @@ func TestToStringSlicePreserveString(t *testing.T) { c.Assert(ToStringSlicePreserveString("Hugo"), qt.DeepEquals, []string{"Hugo"}) c.Assert(ToStringSlicePreserveString([]interface{}{"A", "B"}), qt.DeepEquals, []string{"A", "B"}) c.Assert(ToStringSlicePreserveString(nil), qt.IsNil) - } func TestToString(t *testing.T) { @@ -34,5 +33,4 @@ func TestToString(t *testing.T) { c.Assert(ToString([]byte("Hugo")), qt.Equals, "Hugo") c.Assert(ToString(json.RawMessage("Hugo")), qt.Equals, "Hugo") - } |