Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable gofumpt linter and cleanup formatting #828

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ linters:
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
- errcheck
- gofumpt
- gosimple
- govet
- ineffassign
Expand Down
1 change: 0 additions & 1 deletion cmd/mockery.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func initConfig(
viperObj *viper.Viper,
configPath *pathlib.Path,
) *viper.Viper {

if baseSearchPath == nil {
currentWorkingDir, err := os.Getwd()
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions cmd/mockery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,21 @@ packages:
interfaces:
FooInterface:
`
//config := fmt.Sprintf(configFmt, tmpDir)
configPath := pathlib.NewPath(tmpDir).Join("config.yaml")
require.NoError(t, configPath.WriteFile([]byte(config)))

goModPath := pathlib.NewPath(tmpDir).Join("go.mod")
err := goModPath.WriteFile([]byte(`
module github.com/testuser/testpackage

go 1.20`))
require.NoError(t, err)

interfacePath := pathlib.NewPath(tmpDir).Join("internal", "foopkg", "interface.go")
require.NoError(t, interfacePath.Parent().MkdirAll())
require.NoError(t, interfacePath.WriteFile([]byte(`
package foopkg

type FooInterface interface {
Foo()
Bar()
Expand Down
6 changes: 0 additions & 6 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ func (c *Config) getPackageConfigMap(ctx context.Context, packageName string) (m
emptyMap := map[string]any{}
packageSection[packageName] = emptyMap
return emptyMap, nil

}

// GetPackageConfig returns a struct representation of the package's config
Expand Down Expand Up @@ -490,7 +489,6 @@ func (c *Config) addSubPkgConfig(ctx context.Context, subPkgPath string, parentP
// own `config` section and merge with the parent package
// if so.
subPkgConfig, err := c.getPackageConfigMap(ctx, subPkgPath)

if err != nil {
log.Err(err).Msg("could not get child package config")
return fmt.Errorf("failed to get sub-package config: %w", err)
Expand All @@ -505,7 +503,6 @@ func (c *Config) addSubPkgConfig(ctx context.Context, subPkgPath string, parentP
if _, keyInSubPkg := subPkgConfigSection[key]; !keyInSubPkg {
subPkgConfigSection[key] = val
}

}
}

Expand Down Expand Up @@ -737,7 +734,6 @@ func (c *Config) discoverRecursivePackages(ctx context.Context) error {
log.Trace().Msg("done discovering recursive packages")

return nil

}

func contains[T comparable](slice []T, elem T) bool {
Expand Down Expand Up @@ -870,7 +866,6 @@ func (c *Config) mergeInConfig(ctx context.Context) error {
}

return nil

}

func (c *Config) getInterfacesForPackage(ctx context.Context, pkgPath string) ([]string, error) {
Expand Down Expand Up @@ -928,5 +923,4 @@ func (c *Config) LogUnsupportedPackagesConfig(ctx context.Context) {
Str("url", logging.DocsURL("/configuration/#parameter-descriptions")).
Logger()
l.Error().Msg("use of unsupported options detected. mockery behavior is undefined.")

}
2 changes: 0 additions & 2 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,6 @@ packages:
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

ctx := context.Background()
tmpdir := pathlib.NewPath(t.TempDir())
cfg := tmpdir.Join("config.yaml")
Expand Down Expand Up @@ -1308,7 +1307,6 @@ want
------
%v`, string(cfgAsStr), tt.wantCfgMap)
}

})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,4 @@ func Test(t *testing.T) {

mockInterfaceA.AssertExpectations(t)
})

}
1 change: 0 additions & 1 deletion pkg/fixtures/panic_err_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ func TestPanicOnNoReturnValue(t *testing.T) {
}()

m.DoSomething()

}
1 change: 0 additions & 1 deletion pkg/fixtures/test/expecter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ func TestExpecter(t *testing.T) {
require.Equal(t, 5, runCalled)
expMock.AssertExpectations(t)
})

}

func intfSlice(slice interface{}) []interface{} {
Expand Down
3 changes: 2 additions & 1 deletion pkg/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ type namer interface {
func (g *Generator) renderNamedType(ctx context.Context, t interface {
Obj() *types.TypeName
TypeArgs() *types.TypeList
}) string {
},
) string {
name := g.getPackageScopedType(ctx, t.Obj())
if t.TypeArgs() == nil || t.TypeArgs().Len() == 0 {
return name
Expand Down
1 change: 1 addition & 0 deletions pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (

// SemVer is the version of mockery at build time.
var SemVer = ""

var ErrPkgNotExist = errors.New("package does not exist")

func GetSemverInfo() string {
Expand Down
4 changes: 3 additions & 1 deletion pkg/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func ParserDisableFuncMocks(disable bool) func(*Parser) {
p.disableFuncMocks = disable
}
}

func NewParser(buildTags []string, opts ...func(*Parser)) *Parser {
var conf packages.Config
conf.Mode = packages.NeedTypes |
Expand Down Expand Up @@ -234,7 +235,8 @@ func (p *Parser) packageInterfaces(
pkg *types.Package,
fileName string,
declaredInterfaces []string,
ifaces []*Interface) []*Interface {
ifaces []*Interface,
) []*Interface {
scope := pkg.Scope()
for _, name := range declaredInterfaces {
obj := scope.Lookup(name)
Expand Down
3 changes: 2 additions & 1 deletion pkg/walker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ func TestWalkerExclude(t *testing.T) {
Config: config.Config{
Exclude: []string{
getFixturePath("requester"),
getFixturePath("generic.go")},
getFixturePath("generic.go"),
},
},
Filter: regexp.MustCompile(".*"),
}
Expand Down
Loading