Commit 102cfbd7 authored by Yong Tang's avatar Yong Tang Committed by Miek Gieben

Use gometalinter and enforcing go fmt/lint/vet (#1108)

* Use gometalinter and enforcing go fmt/lint/vet

Before this PR go fmt is enabled, go lint is suggest only.
From time to time we have to manually check for go lint and go vet
for any issues.

This fix uses gometalinter and enforcing go fmt/lint/vet.
Several reasons:
- gometalinter could handle multiple linters concurrently
- gometalinter supports suppression with `// nolint[: <linter>]`

Previously one reason we didn't enable go lint was due to the
```
warning: context.Context should be the first parameter of a function (golint)
```
this is now possible with gometalinter and `// nolint: golint` (See changes).

This fix also discovered several go vet issues and fixes it.
Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>

* Fix several issues reported by gometalinter (go vet)

This commit fixes several issues reported by gometalinter (go vet).
Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>

* Increase deadline
Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>
parent 387ceb48
...@@ -11,7 +11,7 @@ coredns: check godeps ...@@ -11,7 +11,7 @@ coredns: check godeps
CGO_ENABLED=0 $(SYSTEM) go build -v -ldflags="-s -w -X github.com/coredns/coredns/coremain.gitCommit=$(GITCOMMIT)" -o $(BINARY) CGO_ENABLED=0 $(SYSTEM) go build -v -ldflags="-s -w -X github.com/coredns/coredns/coremain.gitCommit=$(GITCOMMIT)" -o $(BINARY)
.PHONY: check .PHONY: check
check: fmt core/zplugin.go core/dnsserver/zdirectives.go godeps check: linter core/zplugin.go core/dnsserver/zdirectives.go godeps
.PHONY: test .PHONY: test
test: check test: check
...@@ -62,17 +62,11 @@ core/zplugin.go core/dnsserver/zdirectives.go: plugin.cfg ...@@ -62,17 +62,11 @@ core/zplugin.go core/dnsserver/zdirectives.go: plugin.cfg
gen: gen:
go generate coredns.go go generate coredns.go
.PHONY: fmt .PHONY: linter
fmt: linter:
## run go fmt go get -u github.com/alecthomas/gometalinter
@test -z "$$(find . -type d | grep -vE '(/vendor|^\.$$|/.git|/.travis)' | xargs gofmt -s -l | tee /dev/stderr)" || \ gometalinter --install golint
(echo "please format Go code with 'gofmt -s -w'" && false) gometalinter --deadline=1m --disable-all --enable=gofmt --enable=golint --enable=vet --exclude=^vendor/ --exclude=^pb/ ./...
.PHONY: lint
lint:
go get -u github.com/golang/lint/golint
@test -z "$$(find . -type d | grep -vE '(/vendor|^\.$$|/.git|/.travis)' | grep -vE '(^\./pb)' | xargs golint \
| grep -vE "context\.Context should be the first parameter of a function" | tee /dev/stderr)"
.PHONY: clean .PHONY: clean
clean: clean:
......
...@@ -69,7 +69,7 @@ func Error(name string, err error) error { return fmt.Errorf("%s/%s: %s", "plugi ...@@ -69,7 +69,7 @@ func Error(name string, err error) error { return fmt.Errorf("%s/%s: %s", "plugi
// NextOrFailure calls next.ServeDNS when next is not nill, otherwise it will return, a ServerFailure // NextOrFailure calls next.ServeDNS when next is not nill, otherwise it will return, a ServerFailure
// and a nil error. // and a nil error.
func NextOrFailure(name string, next Handler, ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { func NextOrFailure(name string, next Handler, ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { // nolint: golint
if next != nil { if next != nil {
if span := ot.SpanFromContext(ctx); span != nil { if span := ot.SpanFromContext(ctx); span != nil {
child := span.Tracer().StartSpan(next.Name(), ot.ChildOf(span.Context())) child := span.Tracer().StartSpan(next.Name(), ot.ChildOf(span.Context()))
......
...@@ -68,7 +68,7 @@ func checkResponse(t *testing.T, resp *dns.Msg) { ...@@ -68,7 +68,7 @@ func checkResponse(t *testing.T, resp *dns.Msg) {
t.Errorf("Expected RR to A, got: %d", resp.Answer[0].Header().Rrtype) t.Errorf("Expected RR to A, got: %d", resp.Answer[0].Header().Rrtype)
} }
if resp.Answer[0].(*dns.A).A.String() != "127.0.0.1" { if resp.Answer[0].(*dns.A).A.String() != "127.0.0.1" {
t.Errorf("Expected 127.0.0.1, got: %d", resp.Answer[0].(*dns.A).A.String()) t.Errorf("Expected 127.0.0.1, got: %s", resp.Answer[0].(*dns.A).A.String())
} }
} }
......
...@@ -49,6 +49,6 @@ func send(t *testing.T, server string) { ...@@ -49,6 +49,6 @@ func send(t *testing.T, server string) {
t.Fatalf("Expected successful reply, got %s", dns.RcodeToString[r.Rcode]) t.Fatalf("Expected successful reply, got %s", dns.RcodeToString[r.Rcode])
} }
if len(r.Extra) != 2 { if len(r.Extra) != 2 {
t.Fatalf("Expected 2 RRs in additional, got %s", len(r.Extra)) t.Fatalf("Expected 2 RRs in additional, got %d", len(r.Extra))
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment