From 12c5a57415f5e8dcc7b09422d66ba86a70668efa Mon Sep 17 00:00:00 2001 From: Zach Date: Sun, 10 Dec 2017 17:44:22 +0000 Subject: [PATCH] determinisitic linter (#902) * linter: address gosimple lints * linter: make deterministic & a rebase fix * lint/rpc: fix a gosimple lint * run linter in CI * fix rebase mistake * fix makefile * ugh * revert Makefile * add metalinter to CI * try this * linter: last little fix * need glide * better * okayy circle, have it your way * lints: gosimple * pr comments --- Makefile | 14 +++++++------- circle.yml | 1 + node/node.go | 7 +------ p2p/trust/store.go | 4 ++-- rpc/lib/client/ws_client.go | 13 +++++++------ state/txindex/kv/kv.go | 2 +- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 4c835a8f5..b94cfd04c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ GOTOOLS = \ github.com/mitchellh/gox \ github.com/tcnksm/ghr \ - github.com/alecthomas/gometalinter + gopkg.in/alecthomas/gometalinter.v2 PACKAGES=$(shell go list ./... | grep -v '/vendor/') BUILD_TAGS?=tendermint @@ -74,7 +74,7 @@ get_vendor_deps: @hash glide 2>/dev/null || go get github.com/Masterminds/glide @rm -rf vendor/ @echo "--> Running glide install" - @glide install + $(GOPATH)/bin/glide install update_tools: @echo "--> Updating tools" @@ -83,21 +83,22 @@ update_tools: tools: @echo "--> Installing tools" @go get $(GOTOOLS) - @gometalinter --install + $(GOPATH)/bin/gometalinter.v2 --install ### Formatting, linting, and vetting metalinter: - @gometalinter --vendor --deadline=600s --enable-all --disable=lll ./... + $(GOPATH)/bin/gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./... metalinter_test: - @gometalinter --vendor --deadline=600s --disable-all \ + $(GOPATH)/bin/gometalinter.v2 --vendor --deadline=600s --disable-all \ --enable=deadcode \ + --enable=gosimple \ --enable=misspell \ --enable=safesql \ ./... - # --enable=gas \ + #--enable=gas \ #--enable=maligned \ #--enable=dupl \ #--enable=errcheck \ @@ -105,7 +106,6 @@ metalinter_test: #--enable=gocyclo \ #--enable=goimports \ #--enable=golint \ <== comments on anything exported - #--enable=gosimple \ #--enable=gotype \ #--enable=ineffassign \ #--enable=interfacer \ diff --git a/circle.yml b/circle.yml index 50ffbd01b..e606097cf 100644 --- a/circle.yml +++ b/circle.yml @@ -24,6 +24,7 @@ dependencies: test: override: + - cd "$PROJECT_PATH" && make tools && make get_vendor_deps && make metalinter_test - cd "$PROJECT_PATH" && set -o pipefail && make test_integrations 2>&1 | tee test_integrations.log: timeout: 1800 post: diff --git a/node/node.go b/node/node.go index eb5509717..2f200abc5 100644 --- a/node/node.go +++ b/node/node.go @@ -373,12 +373,7 @@ func (n *Node) OnStart() error { } // start tx indexer - err = n.indexerService.Start() - if err != nil { - return err - } - - return nil + return n.indexerService.Start() } // OnStop stops the Node. It implements cmn.Service. diff --git a/p2p/trust/store.go b/p2p/trust/store.go index e86aecd2c..fd84ac963 100644 --- a/p2p/trust/store.go +++ b/p2p/trust/store.go @@ -138,7 +138,7 @@ func (tms *TrustMetricStore) loadFromDB() bool { return false } - peers := make(map[string]MetricHistoryJSON, 0) + peers := make(map[string]MetricHistoryJSON) err := json.Unmarshal(bytes, &peers) if err != nil { cmn.PanicCrisis(cmn.Fmt("Could not unmarshal Trust Metric Store DB data: %v", err)) @@ -160,7 +160,7 @@ func (tms *TrustMetricStore) loadFromDB() bool { func (tms *TrustMetricStore) saveToDB() { tms.Logger.Debug("Saving TrustHistory to DB", "size", tms.size()) - peers := make(map[string]MetricHistoryJSON, 0) + peers := make(map[string]MetricHistoryJSON) for key, tm := range tms.peerMetrics { // Add an entry for the peer identified by key diff --git a/rpc/lib/client/ws_client.go b/rpc/lib/client/ws_client.go index e4ed442e4..79e3f63f4 100644 --- a/rpc/lib/client/ws_client.go +++ b/rpc/lib/client/ws_client.go @@ -169,13 +169,14 @@ func (c *WSClient) OnStop() {} // Stop overrides cmn.Service#Stop. There is no other way to wait until Quit // channel is closed. func (c *WSClient) Stop() error { - err := c.BaseService.Stop() - if err == nil { - // only close user-facing channels when we can't write to them - c.wg.Wait() - close(c.ResponsesCh) + if err := c.BaseService.Stop(); err != nil { + return err } - return err + // only close user-facing channels when we can't write to them + c.wg.Wait() + close(c.ResponsesCh) + + return nil } // IsReconnecting returns true if the client is reconnecting right now. diff --git a/state/txindex/kv/kv.go b/state/txindex/kv/kv.go index d40fe80fe..b70f3699f 100644 --- a/state/txindex/kv/kv.go +++ b/state/txindex/kv/kv.go @@ -342,7 +342,7 @@ func startKey(c query.Condition, height int64) []byte { func startKeyForRange(r queryRange, height int64) []byte { if r.lowerBound == nil { - return []byte(fmt.Sprintf("%s", r.key)) + return []byte(r.key) } var lowerBound interface{}