From ad47305dc795e1bda66eed14a6bb29b0056a9c13 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Tue, 28 Dec 2021 15:53:22 +0100 Subject: [PATCH] Migrating to Golangci-Lint (#2075) * Migrating to Golangci-Lint Adding a GHA that is currently not running automatically until it's supporting Go 1.18 Adding the proper config files for Golangci-lint Removing codequality from CI in Makefile phasing out some of the codequality linters too since they are in golangci already RELEASE_NOTES=n/a Signed-off-by: Yolan Romailler * Finalizing all tests with Go 1.18 RELEASE_NOTES=n/a Signed-off-by: Yolan Romailler --- .github/workflows/golangci-lint.yml | 25 ++++++++++ .golangci.yml | 75 +++++++++++++++++++++++++++++ Makefile | 32 +++--------- 3 files changed, 108 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .golangci.yml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000000..e59f30c30b --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,25 @@ +name: golangci-lint +on: + workflow_dispatch: + # push: # Disabled until Golangci-lint GHA is compiled with Go 1.18 + # tags: + # - v* + # branches: + # - master + # - main + # pull_request: +permissions: + contents: read + pull-requests: read +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest # we have a linter whitelist in our .golangci.yml config file + only-new-issues: true diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000000..2caf6ce65a --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,75 @@ +linters-settings: + gocyclo: + min-complexity: 22 + staticcheck: + go: "1.18" + # https://staticcheck.io/docs/options#checks + checks: ["all","-SA1019"] + +linters: + disable-all: true + + enable: + - asciicheck + - forcetypeassert + - gci + - gocyclo + - gofmt + - goimports + - gomoddirectives + - gomodguard + - goprintffuncname + - ifshort + - ineffassign + - misspell + - nakedret + - nolintlint + - prealloc + - predeclared + ## These are working but disabled for now + ## - dogsled # two occurences we cannot really correct + ## - dupl # some dups in tests + ## - gochecknoinits # we use a lot of init + ## - goconst # annoying? + ## - godot # annoying? + ## - godox # we have a few todo... + ## - nestif # some work to refactor + ## - paralleltest # lots of work to pass + ## - revive # currently a bit buggy with Go 1.18 but works mostly + ## - tagliatelle # requires some refactoring + ## - testpackage # complains for a lot of packages + +## To enable once they work with Go 1.18: +### - deadcode +### - depguard +### - durationcheck +### - errcheck +### - errorlint +### - exhaustive +### - exportloopref +### - gocritic +### - goerr113 +### - gosec +### - gosimple +### - govet +### - importas +### - makezero +### - nilerr +### - rowserrcheck +### - staticcheck +### - structcheck +### - stylecheck +### - thelper +### - tparallel +### - typecheck +### - unconvert +### - unparam +### - unused +### - varcheck +### - wastedassign +### - wrapcheck + +issues: + exclude-use-default: false # disable filtering of defaults for better zero-issue policy + max-per-linter: 0 # disable limit; report all issues of a linter + max-same-issues: 0 # disable limit; report all issues of the same issue diff --git a/Makefile b/Makefile index 548fe8fbcd..34ca092457 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ OK := $(shell tput setaf 6; echo ' [OK]'; tput sgr0;) all: sysinfo build build: $(GOPASS_OUTPUT) completion: $(BASH_COMPLETION_OUTPUT) $(FISH_COMPLETION_OUTPUT) $(ZSH_COMPLETION_OUTPUT) -travis: sysinfo crosscompile build fulltest codequality completion +travis: sysinfo crosscompile build fulltest completion travis-osx: sysinfo build test completion travis-windows: sysinfo build test-win completion @@ -147,14 +147,6 @@ codequality: @$(GO) vet ./... @printf '%s\n' '$(OK)' - @echo -n " CYCLO " - @which gocyclo > /dev/null; if [ $$? -ne 0 ]; then \ - $(GO) install github.com/fzipp/gocyclo/cmd/gocyclo@latest; \ - fi - @$(foreach gofile, $(GOFILES_NOVENDOR),\ - gocyclo -over 22 $(gofile) || exit 0;) - @printf '%s\n' '$(OK)' - @echo -n " LINT " @which golint > /dev/null; if [ $$? -ne 0 ]; then \ $(GO) install golang.org/x/lint/golint@latest; \ @@ -163,21 +155,6 @@ codequality: golint -set_exit_status $(pkg) || exit 0;) @printf '%s\n' '$(OK)' - @echo -n " INEFF " - @which ineffassign > /dev/null; if [ $$? -ne 0 ]; then \ - $(GO) install github.com/gordonklaus/ineffassign@latest; \ - fi - @ineffassign . || exit 0 - @printf '%s\n' '$(OK)' - - @echo -n " SPELL " - @which misspell > /dev/null; if [ $$? -ne 0 ]; then \ - $(GO) install github.com/client9/misspell/cmd/misspell@latest; \ - fi - @$(foreach gofile, $(GOFILES_NOVENDOR),\ - misspell --error $(gofile) || exit 1;) - @printf '%s\n' '$(OK)' - @echo -n " STATICCHECK " @which staticcheck > /dev/null; if [ $$? -ne 0 ]; then \ $(GO) install honnef.co/go/tools/cmd/staticcheck@latest; \ @@ -192,6 +169,13 @@ codequality: @unparam -exported=false $(PKGS) || exit 0 @printf '%s\n' '$(OK)' + @echo -n " GOLANGCI-LINT " + @which golangci-lint > /dev/null; if [ $$? -ne 0 ]; then \ + $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \ + fi + @golangci-lint run || exit 0 + @printf '%s\n' '$(OK)' + gen: @$(GO) generate ./...