Skip to content

Commit

Permalink
Merge pull request #591 from LandonTClipp/golangci_lint
Browse files Browse the repository at this point in the history
Add golangci-lint, cleanup code
  • Loading branch information
LandonTClipp committed Apr 6, 2023
2 parents 6f08a5d + 89f6865 commit ea28b63
Show file tree
Hide file tree
Showing 53 changed files with 3,371 additions and 44 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- master
- main
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.19'
cache: false
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.2
20 changes: 20 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,23 @@ linters:
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- contextcheck
- durationcheck
- exportloopref
- gocheckcompilerdirectives
- gosec
- loggercheck
- nilerr
- prealloc
- predeclared
- reassign
linters-settings:
staticcheck:
checks:
- all
- '-SA1024'
2 changes: 2 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ packages:
interfaces:
TypesPackage:
github.com/vektra/mockery/v2/pkg/fixtures:
config:
all: True
interfaces:
RequesterArgSameAsNamedImport:
RequesterVariadic:
Expand Down
8 changes: 6 additions & 2 deletions cmd/mockery.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func NewRootCmd() *cobra.Command {
pFlags.Bool("with-expecter", false, "Generate expecter utility around mock's On, Run and Return methods with explicit types. This option is NOT compatible with -unroll-variadic=false")
pFlags.StringArray("replace-type", nil, "Replace types")

viperCfg.BindPFlags(pFlags)
if err := viperCfg.BindPFlags(pFlags); err != nil {
panic(fmt.Sprintf("failed to bind PFlags: %v", err))
}

cmd.AddCommand(NewShowConfigCmd())
return cmd
Expand Down Expand Up @@ -322,7 +324,9 @@ func (r *RootApp) Run() error {
return errors.Wrapf(err, "Failed to create profile file")
}

pprof.StartCPUProfile(f)
if err := pprof.StartCPUProfile(f); err != nil {
return fmt.Errorf("failed to start CPU profile: %w", err)
}
defer pprof.StopCPUProfile()
}

Expand Down
16 changes: 8 additions & 8 deletions cmd/mockery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Test_initConfig(t *testing.T) {
configPath := pathlib.NewPath("")
if tt.configPath != "" {
configPath = tmpDir.Join(strings.Split(tt.configPath, "/")...)
configPath.WriteFile([]byte("all: True"))
require.NoError(t, configPath.WriteFile([]byte("all: True")))
}

viperObj := viper.New()
Expand Down Expand Up @@ -170,13 +170,13 @@ go 1.20`))

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

mockPath := pathlib.NewPath(tmpDir).Join(
"mocks",
Expand All @@ -187,7 +187,7 @@ type FooInterface interface {
"foopkg",
"mock_FooInterface.go")

os.Chdir(tmpDir)
require.NoError(t, os.Chdir(tmpDir))

v := viper.New()
initConfig(nil, v, configPath)
Expand All @@ -205,20 +205,20 @@ func TestRunLegacyNoConfig(t *testing.T) {

mockPath := tmpDir.Join("Foo.go")
codePath := tmpDir.Join("foo.go")
codePath.WriteFile([]byte(`
require.NoError(t, codePath.WriteFile([]byte(`
package test
type Foo interface {
Get(str string) string
}`))
}`)))

v := viper.New()
v.Set("log-level", "debug")
v.Set("outpkg", "foobar")
v.Set("name", "Foo")
v.Set("output", tmpDir.String())
v.Set("disable-config-search", true)
os.Chdir(tmpDir.String())
require.NoError(t, os.Chdir(tmpDir.String()))

initConfig(nil, v, nil)
app, err := GetRootAppFromViper(v)
Expand Down Expand Up @@ -255,7 +255,7 @@ type Foo interface {
v.Set("disable-config-search", true)
v.Set("dir", subdir.String())
v.Set("recursive", true)
os.Chdir(tmpDir.String())
require.NoError(t, os.Chdir(tmpDir.String()))

initConfig(nil, v, nil)
app, err := GetRootAppFromViper(v)
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.19

require (
github.com/chigopher/pathlib v0.12.0
github.com/iancoleman/strcase v0.2.0
github.com/jinzhu/copier v0.3.5
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.5.0
Expand All @@ -12,7 +13,7 @@ require (
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.1
golang.org/x/crypto v0.6.0
golang.org/x/term v0.5.0
golang.org/x/tools v0.6.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
Expand All @@ -22,7 +23,6 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -37,7 +37,6 @@ require (
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down
87 changes: 87 additions & 0 deletions mocks/github.com/vektra/mockery/v2/pkg/fixtures/A.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ea28b63

Please sign in to comment.