diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000000..8b0bb974ba --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,29 @@ +name: Lint +# Lint runs golangci-lint over the entire repository +# This workflow is run on every pull request and push to master +# The `golangci` will pass without running if no *.{go, mod, sum} files have been changed. +on: + pull_request: + push: + branches: + - master +jobs: + golangci: + name: golangci-lint + runs-on: ubuntu-latest + timeout-minutes: 6 + steps: + - uses: actions/checkout@v2 + - uses: technote-space/get-diff-action@v1 + with: + SUFFIX_FILTER: | + .go + .mod + .sum + - uses: golangci/golangci-lint-action@master + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.27 + args: --timeout 10m + github-token: ${{ secrets.github_token }} + if: "env.GIT_DIFF != ''" diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000000..102f85e51c --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,42 @@ +run: + tests: false +# # timeout for analysis, e.g. 30s, 5m, default is 1m +# timeout: 5m + +linters: + disable-all: true + enable: + - bodyclose + - deadcode + - depguard + - dogsled + # - errcheck + - goconst + - gocritic + - gofmt + - goimports + - golint + - gosec + - gosimple + - govet + - ineffassign + - interfacer + - maligned + - misspell + - nakedret + - prealloc + - scopelint + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unused + - unparam + - misspell + # - wsl + - nolintlint + +issues: + max-issues-per-linter: 10000 + max-same-issues: 10000 diff --git a/Makefile b/Makefile index 81d651008b..e4f38aa87b 100644 --- a/Makefile +++ b/Makefile @@ -19,5 +19,10 @@ install: build ui cli: build @go install -mod=readonly ./... + +lint: + golangci-lint run --out-format=tab --issues-exit-code=0 + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s +.PHONY: lint -.PHONY: all mod build ui install \ No newline at end of file +.PHONY: all mod build ui install diff --git a/cmd/serve.go b/cmd/serve.go index c2319a65e1..6677658787 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -41,7 +41,7 @@ func startServe(verbose bool) (*exec.Cmd, *exec.Cmd) { log.Fatal("Error in initializing the chain. Please, check ./init.sh") } fmt.Printf("🎨 Created a web front-end.\n") - cmdTendermint := exec.Command(fmt.Sprintf("%[1]vd", appName), "start") + cmdTendermint := exec.Command(fmt.Sprintf("%[1]vd", appName), "start") //nolint:gosec // Subprocess launched with function call as argument or cmd arguments if verbose { fmt.Printf("🌍 Running a server at http://localhost:26657 (Tendermint)\n") cmdTendermint.Stdout = os.Stdout @@ -51,7 +51,7 @@ func startServe(verbose bool) (*exec.Cmd, *exec.Cmd) { if err := cmdTendermint.Start(); err != nil { log.Fatal(fmt.Sprintf("Error in running %[1]vd start", appName), err) } - cmdREST := exec.Command(fmt.Sprintf("%[1]vcli", appName), "rest-server") + cmdREST := exec.Command(fmt.Sprintf("%[1]vcli", appName), "rest-server") //nolint:gosec // Subprocess launched with function call as argument or cmd arguments if verbose { fmt.Printf("🌍 Running a server at http://localhost:1317 (LCD)\n") cmdREST.Stdout = os.Stdout @@ -86,7 +86,7 @@ var serveCmd = &cobra.Command{ go func() { for { select { - case _ = <-w.Event: + case <-w.Event: cmdr.Process.Kill() cmdt.Process.Kill() cmdt, cmdr = startServe(verbose) diff --git a/templates/app/new.go b/templates/app/new.go index 81f4eb9807..871999dd60 100644 --- a/templates/app/new.go +++ b/templates/app/new.go @@ -1,7 +1,6 @@ package app import ( - "fmt" "strings" "github.com/gobuffalo/genny" @@ -20,10 +19,9 @@ func New(opts *Options) (*genny.Generator, error) { ctx.Set("ModulePath", opts.ModulePath) ctx.Set("AppName", opts.AppName) ctx.Set("Denom", opts.Denom) - ctx.Set("title", func(s string) string { - return strings.Title(s) - }) + ctx.Set("title", strings.Title) + g.Transformer(plushgen.Transformer(ctx)) - g.Transformer(genny.Replace("{{appName}}", fmt.Sprintf("%s", opts.AppName))) + g.Transformer(genny.Replace("{{appName}}", opts.AppName)) return g, nil } diff --git a/templates/typed/new.go b/templates/typed/new.go index 85ab3a41cc..57251949e9 100644 --- a/templates/typed/new.go +++ b/templates/typed/new.go @@ -32,9 +32,7 @@ func New(opts *Options) (*genny.Generator, error) { ctx.Set("TypeName", opts.TypeName) ctx.Set("ModulePath", opts.ModulePath) ctx.Set("Fields", opts.Fields) - ctx.Set("title", func(s string) string { - return strings.Title(s) - }) + ctx.Set("title", strings.Title) ctx.Set("strconv", func() bool { strconv := false for _, field := range opts.Fields { @@ -45,15 +43,14 @@ func New(opts *Options) (*genny.Generator, error) { return strconv }) g.Transformer(plushgen.Transformer(ctx)) - g.Transformer(genny.Replace("{{appName}}", fmt.Sprintf("%s", opts.AppName))) - g.Transformer(genny.Replace("{{typeName}}", fmt.Sprintf("%s", opts.TypeName))) - g.Transformer(genny.Replace("{{TypeName}}", fmt.Sprintf("%s", strings.Title(opts.TypeName)))) + g.Transformer(genny.Replace("{{appName}}", opts.AppName)) + g.Transformer(genny.Replace("{{typeName}}", opts.TypeName)) + g.Transformer(genny.Replace("{{TypeName}}", opts.TypeName)) return g, nil } const placeholder = "// this line is used by starport scaffolding" const placeholder2 = "// this line is used by starport scaffolding # 2" -const placeholder3 = "// this line is used by starport scaffolding # 3" const placeholder4 = "" func handlerModify(opts *Options) genny.RunFn { @@ -230,10 +227,10 @@ func uiIndexModify(opts *Options) genny.RunFn {