Enforce go lint check and fix several lint issues (#570)

This fix updates the Makefile to add the `go lint` check
for the build. This fix also fixes several go lint issues.

NOTE: This fix does not enforce `go lint` (suggestion only).
This fix also ignores the `go lint` error:
```
middleware/middleware.go:72:1: context.Context should be the first parameter of a function
```
as it requires too many changes in API.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang
2017-03-05 14:17:05 -08:00
committed by GitHub
parent 5eedb728df
commit 1e4ba588dc
3 changed files with 19 additions and 10 deletions

View File

@@ -7,23 +7,27 @@ all: coredns
# Phony this to ensure we always build the binary.
# TODO: Add .go file dependencies.
.PHONY: coredns
coredns: deps core/zmiddleware.go core/dnsserver/zdirectives.go
coredns: check core/zmiddleware.go core/dnsserver/zdirectives.go
go build $(BUILD_VERBOSE) -ldflags="-s -w"
.PHONY: deps
deps: fmt
deps:
go get ${BUILD_VERBOSE}
go get -u github.com/golang/lint/golint
.PHONY: check
check: fmt deps
.PHONY: test
test: deps
test: check
go test -race $(TEST_VERBOSE) ./test ./middleware/...
.PHONY: testk8s
testk8s: deps
testk8s: check
go test -race $(TEST_VERBOSE) -tags=k8s -run 'TestKubernetes' ./test ./middleware/kubernetes/...
.PHONY: coverage
coverage: deps
coverage: check
set -e -x
echo "" > coverage.txt
for d in `go list ./... | grep -v vendor`; do \
@@ -52,6 +56,11 @@ fmt:
@test -z "$$(gofmt -s -l . | grep -v vendor/ | tee /dev/stderr)" || \
(echo "please format Go code with 'gofmt -s -w'" && false)
.PHONY: lint
lint: deps
## run go lint, suggestion only (not enforced)
@test -z "$$(golint ./... | grep -v vendor/ | grep -v ".pb.go:" | grep -vE "context\.Context should be the first parameter of a function" | tee /dev/stderr)"
.PHONY: distclean
distclean: clean
# Clean all dependencies and build artifacts