From ab707bd63b6f49b4987f68b3075f4338592f83b5 Mon Sep 17 00:00:00 2001 From: Jauhar Arifin Date: Sat, 20 Jun 2020 00:28:31 +0000 Subject: [PATCH] fix linter problems --- ast.go | 17 +++++++---------- func.go | 8 ++++---- interface.go | 2 +- util.go | 6 +++--- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/ast.go b/ast.go index a564446..9535efc 100644 --- a/ast.go +++ b/ast.go @@ -48,12 +48,7 @@ func (f *astTypeGenerator) groupTypeSpecByPackage(typeSpecs []TypeSpec) map[stri func (f *astTypeGenerator) generateTypesInSinglePackage(packagePath string, names ...string) []Type { packageDir := f.findGoPackageDir(packagePath) - types := f.generateTypesFromDir(packageDir, packagePath, names...) - results := make([]Type, 0, len(names)) - for _, typ := range types { - results = append(results, typ) - } - return results + return f.generateTypesFromDir(packageDir, packagePath, names...) } func (f *astTypeGenerator) findGoPackageDir(packagePath string) string { @@ -138,7 +133,7 @@ func (f *astTypeGenerator) findPackageDirByModulePath( } func (f *astTypeGenerator) findPackagePathByVersion(modVer module.Version) string { - lookupDir := make([]string, 0, 0) + lookupDir := make([]string, 0) if gohome, ok := os.LookupEnv("GOHOME"); ok { lookupDir = append(lookupDir, filepath.Join(gohome, "pkg", "mod", modVer.Path+"@"+modVer.Version)) @@ -242,8 +237,8 @@ func (f *astTypeGenerator) generateTypesFromDir(packageDir string, packagePath s } func (f *astTypeGenerator) getGoFilesInsideDir(dir string) []string { - goSources := make([]string, 0, 0) - filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + goSources := make([]string, 0) + if err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { if path == dir { return nil } @@ -261,7 +256,9 @@ func (f *astTypeGenerator) getGoFilesInsideDir(dir string) []string { } return nil - }) + }); err != nil { + panic(fmt.Errorf("error while traversing files: %w", err)) + } return goSources } diff --git a/func.go b/func.go index e770bd5..ee0ba9a 100644 --- a/func.go +++ b/func.go @@ -180,7 +180,7 @@ func (f *funcMockerGeneratorHelper) generateMockOutputsMethod() jen.Code { Params(jen.Id("m").Op("*").Id(f.getMockerStructName())). Id("MockOutputs"). Params( - append([]jen.Code{jen.Id("nTimes").Int()}, f.generateOutputParamSignature(true)...)... + append([]jen.Code{jen.Id("nTimes").Int()}, f.generateOutputParamSignature(true)...)..., ).Block( jen.Id("m").Dot("Mock").Call( jen.Id("nTimes"), @@ -239,7 +239,7 @@ func (f *funcMockerGeneratorHelper) generateMockOutputsOnceMethod() jen.Code { Params(f.generateOutputParamSignature(true)...). Block( jen.Id("m").Dot("MockOutputs").Call( - append([]jen.Code{jen.Lit(1)}, f.generateOutputList(true)...)... + append([]jen.Code{jen.Lit(1)}, f.generateOutputList(true)...)..., ), ) } @@ -251,7 +251,7 @@ func (f *funcMockerGeneratorHelper) generateMockOutputsForeverMethod() jen.Code Params(f.generateOutputParamSignature(true)...). Block( jen.Id("m").Dot("MockOutputs").Call( - append([]jen.Code{jen.Lit(0)}, f.generateOutputList(true)...)... + append([]jen.Code{jen.Lit(0)}, f.generateOutputList(true)...)..., ), ) } @@ -262,7 +262,7 @@ func (f *funcMockerGeneratorHelper) generateMockDefaultsMethod() jen.Code { Id("MockDefaults"). Params(jen.Id("nTimes").Int()) - body := make([]jen.Code, 0, 0) + body := make([]jen.Code, 0) for i, field := range f.funcType.Outputs { body = append( diff --git a/interface.go b/interface.go index dd3c002..16ce37f 100644 --- a/interface.go +++ b/interface.go @@ -117,7 +117,7 @@ func (s *interfaceMockerGeneratorHelper) generateMockedInterfaceImpl() jen.Code } func (s *interfaceMockerGeneratorHelper) generateInterfaceMockerConstructor() jen.Code { - values := make([]jen.Code, 0, 0) + values := make([]jen.Code, 0) for _, method := range s.interfaceType.Methods { name := method.Name values = append( diff --git a/util.go b/util.go index 3193652..70cf88f 100644 --- a/util.go +++ b/util.go @@ -59,9 +59,9 @@ func parseInt(s string) (int, bool) { n := 0 for i := 0; i < len(s); i++ { switch { - case base >= 10 && s[i] >= 'a' && s[i] < 'a' + base - 10: + case base >= 10 && s[i] >= 'a' && s[i] < 'a'+base-10: n = n*int(base) + int(s[i]) - 'a' + 10 - case base >= 10 && s[i] >= 'A' && s[i] < 'A' + base - 10: + case base >= 10 && s[i] >= 'A' && s[i] < 'A'+base-10: n = n*int(base) + int(s[i]) - 'A' + 10 case s[i] >= '0' && s[i] < '0'+maxUint8(base, 10): n = n*int(base) + int(s[i]) - '0' @@ -77,7 +77,7 @@ func maxUint8(a, b uint8) uint8 { return b } -type stepFunc func() (jen.Code, ) +type stepFunc func() jen.Code func concatSteps(steps ...stepFunc) jen.Code { j := jen.Empty()