From d6e821ea4fb1d08ae1ff34202d30d4b0cf728f38 Mon Sep 17 00:00:00 2001 From: Zach Ramsay Date: Sun, 10 Dec 2017 22:11:24 +0000 Subject: [PATCH 1/4] linter: enable in CI & make deterministic --- Makefile | 10 +++++----- circle.yml | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index d5fe913b..7176ab10 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ GOTOOLS = \ github.com/mitchellh/gox \ github.com/Masterminds/glide \ - github.com/alecthomas/gometalinter \ + gopkg.in/alecthomas/gometalinter.v2 \ github.com/ckaznocha/protoc-gen-lint \ github.com/gogo/protobuf/protoc-gen-gogo \ github.com/gogo/protobuf/gogoproto @@ -62,7 +62,7 @@ get_deps: ensure_tools: go get -u -v $(GOTOOLS) - @gometalinter --install + @gometalinter.v2 --install get_vendor_deps: ensure_tools @rm -rf vendor/ @@ -71,11 +71,11 @@ get_vendor_deps: ensure_tools metalinter: protoc $(INCLUDE) --lint_out=. types/*.proto - gometalinter --vendor --deadline=600s --enable-all --disable=lll ./... + gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./... metalinter_test: - protoc $(INCLUDE) --lint_out=. types/*.proto - gometalinter --vendor --deadline=600s --disable-all \ + #protoc $(INCLUDE) --lint_out=. types/*.proto + gometalinter.v2 --vendor --deadline=600s --disable-all \ --enable=maligned \ --enable=deadcode \ --enable=goconst \ diff --git a/circle.yml b/circle.yml index 7d4545e5..95d1dea5 100644 --- a/circle.yml +++ b/circle.yml @@ -2,7 +2,6 @@ machine: environment: GOPATH: /home/ubuntu/.go_workspace REPO: $GOPATH/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME - GO15VENDOREXPERIMENT: 1 hosts: circlehost: 127.0.0.1 localhost: 127.0.0.1 @@ -16,7 +15,7 @@ checkout: test: override: - - cd $REPO && make get_vendor_deps && make test_integrations + - cd $REPO && make get_vendor_deps && make metalinter_test && make test_integrations post: - cd "$REPO" && bash <(curl -s https://codecov.io/bash) -f coverage.txt - cd "$REPO" && mv coverage.txt "${CIRCLE_ARTIFACTS}" From bbc3b807c6151474d10609e4bfca5ee66c84e04d Mon Sep 17 00:00:00 2001 From: Emmanuel Odeke Date: Tue, 12 Dec 2017 17:23:13 -0700 Subject: [PATCH 2/4] all: fix vet issues with build tags, formatting * Build tags need to come before the package name and have at least a blank line, between them and the package, please see https://golang.org/pkg/go/build/#hdr-Build_Constraints * fmt.Println doesn't take formatting verbs * Fix a missing formatting argument to fmt.Printf --- tests/server/client.go | 4 ++-- types/protoreplace/protoreplace.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/server/client.go b/tests/server/client.go index f1757fe1..8d6751a1 100644 --- a/tests/server/client.go +++ b/tests/server/client.go @@ -21,7 +21,7 @@ func InitChain(client abcicli.Client) error { } _, err := client.InitChainSync(types.RequestInitChain{Validators: vals}) if err != nil { - fmt.Println("Failed test: InitChain - %v", err) + fmt.Printf("Failed test: InitChain - %v\n", err) return err } fmt.Println("Passed test: InitChain") @@ -46,7 +46,7 @@ func Commit(client abcicli.Client, hashExp []byte) error { _, data := res.Code, res.Data if err != nil { fmt.Println("Failed test: Commit") - fmt.Printf("committing %v\nlog: %v", res.GetLog()) + fmt.Printf("committing %v\nlog: %v", data, res.GetLog()) return err } if !bytes.Equal(data, hashExp) { diff --git a/types/protoreplace/protoreplace.go b/types/protoreplace/protoreplace.go index c859098f..3ea0c73d 100644 --- a/types/protoreplace/protoreplace.go +++ b/types/protoreplace/protoreplace.go @@ -1,7 +1,7 @@ -package main - // +build ignore +package main + import ( "bytes" "fmt" From c532e8cabcfede2dcb640a7ae7404c53fbcd4f36 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 12 Dec 2017 22:44:55 -0600 Subject: [PATCH 3/4] add \n to Printf lines --- tests/server/client.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/server/client.go b/tests/server/client.go index 8d6751a1..9cc8131d 100644 --- a/tests/server/client.go +++ b/tests/server/client.go @@ -33,7 +33,7 @@ func SetOption(client abcicli.Client, key, value string) error { log := res.GetLog() if err != nil { fmt.Println("Failed test: SetOption") - fmt.Printf("setting %v=%v: \nlog: %v", key, value, log) + fmt.Printf("setting %v=%v: \nlog: %v\n", key, value, log) fmt.Println("Failed test: SetOption") return err } @@ -46,12 +46,12 @@ func Commit(client abcicli.Client, hashExp []byte) error { _, data := res.Code, res.Data if err != nil { fmt.Println("Failed test: Commit") - fmt.Printf("committing %v\nlog: %v", data, res.GetLog()) + fmt.Printf("committing %v\nlog: %v\n", data, res.GetLog()) return err } if !bytes.Equal(data, hashExp) { fmt.Println("Failed test: Commit") - fmt.Printf("Commit hash was unexpected. Got %X expected %X", + fmt.Printf("Commit hash was unexpected. Got %X expected %X\n", data.Bytes(), hashExp) return errors.New("CommitTx failed") } @@ -64,13 +64,13 @@ func DeliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp [] code, data, log := res.Code, res.Data, res.Log if code != codeExp { fmt.Println("Failed test: DeliverTx") - fmt.Printf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v", + fmt.Printf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v\n", code, codeExp, log) return errors.New("DeliverTx error") } if !bytes.Equal(data, dataExp) { fmt.Println("Failed test: DeliverTx") - fmt.Printf("DeliverTx response data was unexpected. Got %X expected %X", + fmt.Printf("DeliverTx response data was unexpected. Got %X expected %X\n", data, dataExp) return errors.New("DeliverTx error") } @@ -83,13 +83,13 @@ func CheckTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []by code, data, log := res.Code, res.Data, res.Log if code != codeExp { fmt.Println("Failed test: CheckTx") - fmt.Printf("CheckTx response code was unexpected. Got %v expected %v. Log: %v", + fmt.Printf("CheckTx response code was unexpected. Got %v expected %v. Log: %v\n", code, codeExp, log) return errors.New("CheckTx") } if !bytes.Equal(data, dataExp) { fmt.Println("Failed test: CheckTx") - fmt.Printf("CheckTx response data was unexpected. Got %X expected %X", + fmt.Printf("CheckTx response data was unexpected. Got %X expected %X\n", data, dataExp) return errors.New("CheckTx") } From 811dc071aae355775131d3e6f9325a076995aca2 Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Tue, 19 Dec 2017 11:29:59 -0700 Subject: [PATCH 4/4] protoc: "//nolint: gas" directive after pb generation (#164) * protoc: "//nolint: gas" directive after pb generation Fixes #138 Since we can't add package directives through the protoc compiler, yet we need to "//nolint: gas" the Go generated protobuf file, added a script whose purpose is to go find the "package (\w+)$" declaration after go fmt was run by protoc. The competing solutions were more complex and can be examined by visiting https://github.com/tendermint/abci/issues/138#issuecomment-352226217 * simplify script * rewrite script to work on Mac --- Makefile | 3 +++ types/types.pb.go | 1 + 2 files changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 7176ab10..9324570f 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,9 @@ protoc: ## ldconfig (may require sudo) ## https://stackoverflow.com/a/25518702 protoc $(INCLUDE) --gogo_out=plugins=grpc:. --lint_out=. types/*.proto + @echo "--> adding nolint declarations to protobuf generated files" + @awk '/package types/ { print "//nolint: gas"; print; next }1' types/types.pb.go > types/types.pb.go.new + @mv types/types.pb.go.new types/types.pb.go install: @ go install ./cmd/... diff --git a/types/types.pb.go b/types/types.pb.go index 69777d6d..e7549665 100644 --- a/types/types.pb.go +++ b/types/types.pb.go @@ -40,6 +40,7 @@ It has these top-level messages: Evidence KVPair */ +//nolint: gas package types import proto "github.com/gogo/protobuf/proto"