Skip to content

Commit

Permalink
Setup golangci-lint as default linter framework (#994)
Browse files Browse the repository at this point in the history
golanci-lint provides all linters that were previously used in a single binary. A default configuration has been provided that matches the existing linter configuration but also adds a few more linters. Furthermore a pre-commit configuration is provided.
  • Loading branch information
Jan Schlicht committed Oct 24, 2019
1 parent dbbb207 commit 509a40b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: git://github.com/golangci/golangci-lint
rev: v1.21.0
hooks:
- id: golangci-lint
40 changes: 4 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -53,7 +49,7 @@ download:
go mod download

.PHONY: prebuild
prebuild: generate check-formatting
prebuild: generate lint

.PHONY: manager
# Build manager binary
Expand All @@ -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:
Expand Down Expand Up @@ -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}
Expand Down
20 changes: 0 additions & 20 deletions hack/check_formatting.sh

This file was deleted.

2 changes: 1 addition & 1 deletion keps/0004-add-testing-infrastructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 509a40b

Please sign in to comment.