From 6d9f07dfee4651242785e049ec6d031f1d73bf14 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Wed, 27 Jun 2018 17:32:06 -0700 Subject: [PATCH] tools: Add go vet as a linter (#1421) * tools: add go vet * tools: Add go vet as a linter --- .circleci/config.yml | 3 +-- CHANGELOG.md | 9 ++++++--- Makefile | 3 ++- client/tx/broadcast.go | 2 +- client/tx/sign.go | 6 +++--- examples/basecoin/app/app_test.go | 8 ++++---- examples/democoin/x/oracle/oracle_test.go | 6 +++--- x/stake/types/delegation.go | 4 ++-- 8 files changed, 22 insertions(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bb1ad1671..149b5546d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -67,8 +67,7 @@ jobs: name: Lint source command: | export PATH="$GOBIN:$PATH" - gometalinter.v2 --disable-all --enable='golint' --enable='misspell' --vendor ./... - find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s + make test_lint test_unit: <<: *defaults parallelism: 1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 70d3c303a..cd11eff37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ BREAKING CHANGES * [stake] remove Tick and add EndBlocker * [stake] introduce concept of unbonding for delegations and validators * `gaiacli stake unbond` replaced with `gaiacli stake begin-unbonding` - * introduced: + * introduced: * `gaiacli stake complete-unbonding` * `gaiacli stake begin-redelegation` * `gaiacli stake complete-redelegation` @@ -34,14 +34,17 @@ FEATURES * Run with `cd x/bank && go test --bench=.` * [tools] make get_tools installs tendermint's linter, and gometalinter * [tools] Switch gometalinter to the stable version -* [tools] Add checking for misspellings and for incorrectly formatted files in circle CI +* [tools] Add the following linters + * misspell + * gofmt + * go vet -composites=false * [server] Default config now creates a profiler at port 6060, and increase p2p send/recv rates * [tests] Add WaitForNextNBlocksTM helper method * [types] Switches internal representation of Int/Uint/Rat to use pointers * [gaiad] unsafe_reset_all now resets addrbook.json * [democoin] add x/oracle, x/assoc -FIXES +FIXES * [gaia] Added self delegation for validators in the genesis creation * [lcd] tests now don't depend on raw json text * [stake] error strings lower case diff --git a/Makefile b/Makefile index 41883cfaf..f2fbdd2b8 100644 --- a/Makefile +++ b/Makefile @@ -108,7 +108,8 @@ test_cover: @bash tests/test_cover.sh test_lint: - gometalinter.v2 --disable-all --enable='golint' --enable='misspell' --vendor ./... + gometalinter.v2 --disable-all --enable='golint' --enable='misspell' --linter='vet:go vet -composites=false:PATH:LINE:MESSAGE' --enable='vet' --vendor ./... + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s benchmark: @go test -bench=. $(PACKAGES_NOCLITEST) diff --git a/client/tx/broadcast.go b/client/tx/broadcast.go index 7f55e97d7..21f576db4 100644 --- a/client/tx/broadcast.go +++ b/client/tx/broadcast.go @@ -9,7 +9,7 @@ import ( // Tx Broadcast Body type BroadcastTxBody struct { - TxBytes string `json="tx"` + TxBytes string `json:"tx"` } // BroadcastTx REST Handler diff --git a/client/tx/sign.go b/client/tx/sign.go index 2d885b049..36a765eed 100644 --- a/client/tx/sign.go +++ b/client/tx/sign.go @@ -11,9 +11,9 @@ import ( // REST request body // TODO does this need to be exposed? type SignTxBody struct { - Name string `json="name"` - Password string `json="password"` - TxBytes string `json="tx"` + Name string `json:"name"` + Password string `json:"password"` + TxBytes string `json:"tx"` } // sign transaction REST Handler diff --git a/examples/basecoin/app/app_test.go b/examples/basecoin/app/app_test.go index c3ba39b3d..81ed40f21 100644 --- a/examples/basecoin/app/app_test.go +++ b/examples/basecoin/app/app_test.go @@ -1,10 +1,10 @@ package app import ( - "os" - "fmt" - "testing" "encoding/json" + "fmt" + "os" + "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -83,7 +83,7 @@ func TestGenesis(t *testing.T) { // InitChain with default stake data. Initializes deliverState and checkState context bapp.InitChain(abci.RequestInitChain{AppStateBytes: []byte(fmt.Sprintf("{\"stake\": %s}", string(genState)))}) - + ctx = bapp.BaseApp.NewContext(true, abci.Header{}) res1 = bapp.accountMapper.GetAccount(ctx, baseAcc.Address) assert.Equal(t, acc, res1) diff --git a/examples/democoin/x/oracle/oracle_test.go b/examples/democoin/x/oracle/oracle_test.go index 27c5aa08b..1cd73b1c1 100644 --- a/examples/democoin/x/oracle/oracle_test.go +++ b/examples/democoin/x/oracle/oracle_test.go @@ -106,9 +106,9 @@ func TestOracle(t *testing.T) { addr3 := []byte("addr3") addr4 := []byte("addr4") valset := &mock.ValidatorSet{[]mock.Validator{ - mock.Validator{addr1, sdk.NewRat(7)}, - mock.Validator{addr2, sdk.NewRat(7)}, - mock.Validator{addr3, sdk.NewRat(1)}, + {addr1, sdk.NewRat(7)}, + {addr2, sdk.NewRat(7)}, + {addr3, sdk.NewRat(1)}, }} key := sdk.NewKVStoreKey("testkey") diff --git a/x/stake/types/delegation.go b/x/stake/types/delegation.go index 235e1e608..410cfbe1d 100644 --- a/x/stake/types/delegation.go +++ b/x/stake/types/delegation.go @@ -101,8 +101,8 @@ type Redelegation struct { ValidatorDstAddr sdk.Address `json:"validator_dst_addr"` // validator redelegation destination owner addr CreationHeight int64 `json:"creation_height"` // height which the redelegation took place MinTime int64 `json:"min_time"` // unix time for redelegation completion - SharesSrc sdk.Rat `json:"shares` // amount of source shares redelegating - SharesDst sdk.Rat `json:"shares` // amount of destination shares redelegating + SharesSrc sdk.Rat `json:"shares_src"` // amount of source shares redelegating + SharesDst sdk.Rat `json:"shares_dst"` // amount of destination shares redelegating } // nolint