From 1f797fafc4aca13699f15b5a3b67e7a558900b0f Mon Sep 17 00:00:00 2001 From: MinerYang Date: Mon, 9 May 2022 11:19:02 +0800 Subject: [PATCH] add lint with golangci-lint, remove golint (#16821) Signed-off-by: yminer test ut_install.sh Signed-off-by: yminer test ut_install.sh001 Signed-off-by: yminer test ut_install002 Signed-off-by: yminer use curl binary to download golangcilint instead of go get Signed-off-by: yminer test ut-ci make lint Signed-off-by: yminer check ci GO111MODULE Signed-off-by: yminer test ci go env Signed-off-by: yminer test ci goenv 002 Signed-off-by: yminer test ci GO111MODULE=auto Signed-off-by: yminer ci test entire ut_install.sh Signed-off-by: yminer remove needless debug comment Signed-off-by: yminer Co-authored-by: yminer --- Makefile | 24 ++++++------------ src/.golangci.yaml | 56 ++++++++++++++++++++++++++++++++++++++++++ tests/ci/ut_install.sh | 6 ++++- 3 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 src/.golangci.yaml diff --git a/Makefile b/Makefile index 361cad260..cf7d98bdb 100644 --- a/Makefile +++ b/Makefile @@ -516,16 +516,7 @@ gosec: $(GOPATH)/bin/gosec -fmt=json -out=harbor_gas_output.json -quiet ./... | true ; \ fi -go_check: gen_apis mocks_check misspell gofmt commentfmt golint govet - -gofmt: - @echo checking gofmt... - @res=$$(gofmt -d -e -s $$(find . -type d \( -path ./src/vendor -o -path ./tests \) -prune -o -name '*.go' -print)); \ - if [ -n "$${res}" ]; then \ - echo checking gofmt fail... ; \ - echo "$${res}"; \ - exit 1; \ - fi +go_check: gen_apis mocks_check misspell commentfmt lint commentfmt: @echo checking comment format... @@ -541,13 +532,12 @@ misspell: @echo checking misspell... @find . -type d \( -path ./src/vendor -o -path ./tests \) -prune -o -name '*.go' -print | xargs misspell -error -golint: - @echo checking golint... - @go list ./... | grep -v -E 'vendor|test' | xargs fgt golint - -govet: - @echo checking govet... - @cd src;go list ./... | grep -v -E 'vendor|test' | xargs go vet +# go get -u github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2 +GOLANGCI_LINT := $(shell go env GOPATH)/bin/golangci-lint +lint: + @echo checking lint + @echo $(GOLANGCI_LINT) + @$(GOLANGCI_LINT) -v run ./src/... pushimage: @echo "pushing harbor images ..." diff --git a/src/.golangci.yaml b/src/.golangci.yaml new file mode 100644 index 000000000..51113646a --- /dev/null +++ b/src/.golangci.yaml @@ -0,0 +1,56 @@ +linters-settings: + gofmt: + # Simplify code: gofmt with `-s` option. + # Default: true + simplify: false + misspell: + locale: US,UK + +linters: + disable-all: true + enable: + - gofmt + - goheader + - misspell + # - typecheck + # - dogsled + # - dupl + # - depguard + # - funlen + # - goconst + # - gocritic + # - gocyclo + # - goimports + # - goprintffuncname + # - ineffassign + # - nakedret + # - nolintlint + # - revive + # - whitespace + # - bodyclose + # - deadcode + # - errcheck + # - gosec + # - gosimple + # - govet + # - noctx + # - rowserrcheck + # - staticcheck + # - structcheck + # - stylecheck + # - unconvert + # - unparam + # - unused + # - varcheck + +run: + skip-files: + - ".*_test.go" + - ".*test.go" + skip-dir: + - "./testing/" + timeout: 5m + +issue: + max-same-issues: 0 + max-per-linter: 0 diff --git a/tests/ci/ut_install.sh b/tests/ci/ut_install.sh index 5774ede63..1e27af72f 100755 --- a/tests/ci/ut_install.sh +++ b/tests/ci/ut_install.sh @@ -13,10 +13,14 @@ go get github.com/stretchr/testify go get golang.org/x/tools/cmd/cover go get github.com/mattn/goveralls go get -u github.com/client9/misspell/cmd/misspell +# binary will be $(go env GOPATH)/bin/golangci-lint +# go install/go get installation aren't guaranteed to work. We recommend using binary installation. +curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.45.2 sudo service postgresql stop || echo no postgresql need to be stopped sleep 2 -sudo rm -rf /data/* +sudo rm -rf /data/* +sudo go env -w GO111MODULE=auto sudo -E env "PATH=$PATH" make go_check sudo ./tests/hostcfg.sh sudo ./tests/generateCerts.sh