diff --git a/.circleci/config.yml b/.circleci/config.yml index 5bb49ffeb..760032cbf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -42,7 +42,7 @@ jobs: keys: - go-mod-v1-{{ checksum "go.sum" }} - - run: make check-formatting + - run: make lint - save_cache: key: go-mod-v1-{{ checksum "go.sum" }} paths: diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..9dff24409 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,14 @@ +linters: + auto-fix: false + enable: + - gofmt + - goimports + - golint + - misspell + disable: + # temporarily disabled until all errcheck warnings have been fixed + - errcheck +run: + skip-dirs: + # autogenerated clientset by client-gen + - pkg/client diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..58b629153 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: + - repo: git://github.com/golangci/golangci-lint + rev: v1.21.0 + hooks: + - id: golangci-lint diff --git a/Makefile b/Makefile index 78ed4d0f2..562e0837a 100644 --- a/Makefile +++ b/Makefile @@ -39,12 +39,8 @@ integration-test: cli-fast test-clean: rm -f cover.out cover-integration.out -.PHONY: check-formatting -check-formatting: vet lint staticcheck - ./hack/check_formatting.sh - -.PHONY: golint -golint: +.PHONY: lint +lint: go get -u github.com/golangci/golangci-lint/cmd/golangci-lint golangci-lint run @@ -53,7 +49,7 @@ download: go mod download .PHONY: prebuild -prebuild: generate check-formatting +prebuild: generate lint .PHONY: manager # Build manager binary @@ -80,34 +76,6 @@ deploy: deploy-clean: go run ./cmd/kubectl-kudo init --crd-only --dry-run --output yaml | kubectl delete -f - -.PHONY: fmt -# Run go fmt against code -fmt: - go fmt ./pkg/... ./cmd/... - -.PHONY: vet -# Run go vet against code -vet: - go vet ./pkg/... ./cmd/... - -.PHONY: lint -# Run go lint against code -lint: - go install golang.org/x/lint/golint - golint -set_exit_status ./pkg/... ./cmd/... - -.PHONY: staticcheck -# Runs static check -staticcheck: - go install honnef.co/go/tools/cmd/staticcheck - staticcheck ./... - -.PHONY: imports -# Run go imports against code -imports: - go install golang.org/x/tools/cmd/goimports - goimports -w ./pkg/ ./cmd/ - .PHONY: generate # Generate code generate: @@ -141,7 +109,7 @@ clean: cli-clean test-clean manager-clean deploy-clean .PHONY: docker-build # Build the docker image -docker-build: generate check-formatting +docker-build: generate lint docker build --build-arg git_version_arg=${GIT_VERSION_PATH}=v${GIT_VERSION} \ --build-arg git_commit_arg=${GIT_COMMIT_PATH}=${GIT_COMMIT} \ --build-arg build_date_arg=${BUILD_DATE_PATH}=${BUILD_DATE} . -t ${DOCKER_IMG}:${DOCKER_TAG} diff --git a/hack/check_formatting.sh b/hack/check_formatting.sh deleted file mode 100755 index 74898f376..000000000 --- a/hack/check_formatting.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -set -o nounset -set -o pipefail - -ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -PACKAGES="${ROOT}/pkg/ ${ROOT}/cmd/" - -# Make sure goimports doesn't find any errors -go install golang.org/x/tools/cmd/goimports - -echo "goimports -d ${PACKAGES}" -# shellcheck disable=SC2086 -differences=$(goimports -d ${PACKAGES}) -if [[ ! "$differences" == "" ]]; then - echo "goimports found the following differences" - echo "$differences" - exit 1 -fi diff --git a/keps/0004-add-testing-infrastructure.md b/keps/0004-add-testing-infrastructure.md index e09ddb608..65368f9a6 100644 --- a/keps/0004-add-testing-infrastructure.md +++ b/keps/0004-add-testing-infrastructure.md @@ -133,7 +133,7 @@ All Pull Requests into master need to have the following checks pass. These shou 0. Check author has signed CLA 1. If the user is not a contributor, a contributor must write `/ok-to-test` on the pull request before it will be triggered. 1. `go fmt` does not change anything -1. `make check-formatting passes. +1. `make lint` passes. 1. All unit tests pass (with `-race` flag) 1. Dockerfile builds (this requires all dependencies in the vendor folder) 1. All integration tests pass.