From d90e37e0c6e812f9913bf256c9c81aa05b7a08aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 2 Dec 2020 13:23:25 +0100 Subject: all: Format code with gofumpt See https://github.com/mvdan/gofumpt --- codegen/methods.go | 16 ++-------------- codegen/methods_test.go | 4 ---- 2 files changed, 2 insertions(+), 18 deletions(-) (limited to 'codegen') diff --git a/codegen/methods.go b/codegen/methods.go index ed8dba923..38477e333 100644 --- a/codegen/methods.go +++ b/codegen/methods.go @@ -58,7 +58,7 @@ func (c *Inspector) MethodsFromTypes(include []reflect.Type, exclude []reflect.T var methods Methods - var excludes = make(map[string]bool) + excludes := make(map[string]bool) if len(exclude) > 0 { for _, m := range c.MethodsFromTypes(exclude, nil) { @@ -99,11 +99,9 @@ func (c *Inspector) MethodsFromTypes(include []reflect.Type, exclude []reflect.T name = pkgPrefix + name return name, pkg - } for _, t := range include { - for i := 0; i < t.NumMethod(); i++ { m := t.Method(i) @@ -153,7 +151,6 @@ func (c *Inspector) MethodsFromTypes(include []reflect.Type, exclude []reflect.T methods = append(methods, method) } - } sort.SliceStable(methods, func(i, j int) bool { @@ -167,16 +164,13 @@ func (c *Inspector) MethodsFromTypes(include []reflect.Type, exclude []reflect.T } return wi < wj - }) return methods - } func (c *Inspector) parseSource() { c.init.Do(func() { - if !strings.Contains(c.ProjectRootDir, "hugo") { panic("dir must be set to the Hugo root") } @@ -200,7 +194,6 @@ func (c *Inspector) parseSource() { filenames = append(filenames, path) return nil - }) for _, filename := range filenames { @@ -230,7 +223,6 @@ func (c *Inspector) parseSource() { c.methodWeight[iface] = weights } } - } return true }) @@ -247,7 +239,6 @@ func (c *Inspector) parseSource() { } } } - }) } @@ -385,7 +376,7 @@ func (m Methods) ToMarshalJSON(receiver, pkgPath string, excludes ...string) (st fmt.Fprintf(&sb, "func Marshal%sToJSON(%s %s) ([]byte, error) {\n", what, r, receiver) var methods Methods - var excludeRes = make([]*regexp.Regexp, len(excludes)) + excludeRes := make([]*regexp.Regexp, len(excludes)) for i, exclude := range excludes { excludeRes[i] = regexp.MustCompile(exclude) @@ -450,7 +441,6 @@ func (m Methods) ToMarshalJSON(receiver, pkgPath string, excludes ...string) (st } return sb.String(), pkgImports - } func collectMethodsRecursive(pkg string, f []*ast.Field) []string { @@ -481,7 +471,6 @@ func collectMethodsRecursive(pkg string, f []*ast.Field) []string { } return methodNames - } func firstToLower(name string) string { @@ -544,5 +533,4 @@ func varName(name string) string { } return name - } diff --git a/codegen/methods_test.go b/codegen/methods_test.go index 77399f4e4..66000f4e9 100644 --- a/codegen/methods_test.go +++ b/codegen/methods_test.go @@ -25,7 +25,6 @@ import ( ) func TestMethods(t *testing.T) { - var ( zeroIE = reflect.TypeOf((*IEmbed)(nil)).Elem() zeroIEOnly = reflect.TypeOf((*IEOnly)(nil)).Elem() @@ -58,7 +57,6 @@ func TestMethods(t *testing.T) { methodsStr := fmt.Sprint(methods) c.Assert(methodsStr, qt.Contains, "MethodEmbed3(arg0 string) string") - }) t.Run("ToMarshalJSON", func(t *testing.T) { @@ -76,9 +74,7 @@ func TestMethods(t *testing.T) { c.Assert(pkg, qt.Contains, "encoding/json") fmt.Println(pkg) - }) - } type I interface { -- cgit v1.2.3