Skip to content

Commit

Permalink
lint add deadcode unused (#4606)
Browse files Browse the repository at this point in the history
Added deadcode and unused linters to the repo, it
helped find some unused code.

Ref #4589
  • Loading branch information
tac0turtle authored and Alessio Treglia committed Jun 21, 2019
1 parent 6672e70 commit 4ffabb6
Show file tree
Hide file tree
Showing 25 changed files with 17 additions and 138 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ linters:
- unconvert
- misspell
- govet
- unused
- deadcode
- goconst
linters-settings:
gocyclo:
Expand Down
31 changes: 0 additions & 31 deletions client/keys/errors.go

This file was deleted.

5 changes: 2 additions & 3 deletions client/lcd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ type RestServer struct {
CliCtx context.CLIContext
KeyBase keybase.Keybase

log log.Logger
listener net.Listener
fingerprint string
log log.Logger
listener net.Listener
}

// NewRestServer creates a new rest server instance
Expand Down
15 changes: 0 additions & 15 deletions store/cachekv/memiterator.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cachekv

import (
"bytes"
"container/list"

cmn "github.com/tendermint/tendermint/libs/common"
Expand Down Expand Up @@ -84,17 +83,3 @@ func (mi *memIterator) Close() {
mi.end = nil
mi.items = nil
}

//----------------------------------------
// Misc.

// bytes.Compare but bounded on both sides by nil.
// both (k1, nil) and (nil, k2) return -1
func keyCompare(k1, k2 []byte) int {
if k1 == nil && k2 == nil {
return 0
} else if k1 == nil || k2 == nil {
return -1
}
return bytes.Compare(k1, k2)
}
7 changes: 0 additions & 7 deletions store/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,3 @@ func (m List) Iterate(ptr interface{}, fn func(uint64) bool) {
}
}
}

func subspace(prefix []byte) (start, end []byte) {
end = make([]byte, len(prefix))
copy(end, prefix)
end[len(end)-1]++
return prefix, end
}
28 changes: 0 additions & 28 deletions store/prefix/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,31 +188,3 @@ func stripPrefix(key []byte, prefix []byte) []byte {
func cpIncr(bz []byte) []byte {
return types.PrefixEndBytes(bz)
}

// copied from github.com/tendermint/tendermint/libs/db/util.go
func cpDecr(bz []byte) (ret []byte) {
if len(bz) == 0 {
panic("cpDecr expects non-zero bz length")
}
ret = make([]byte, len(bz))
copy(ret, bz)
for i := len(bz) - 1; i >= 0; i-- {
if ret[i] > byte(0x00) {
ret[i]--
return
}
ret[i] = byte(0xFF)
if i == 0 {
return nil
}
}
return nil
}

func skipOne(iter types.Iterator, skipKey []byte) {
if iter.Valid() {
if bytes.Equal(iter.Key(), skipKey) {
iter.Next()
}
}
}
5 changes: 0 additions & 5 deletions store/types/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ const (
GasDeleteDesc = "Delete"
)

var (
cachedKVGasConfig = KVGasConfig()
cachedTransientGasConfig = TransientGasConfig()
)

// Gas measured by the SDK
type Gas = uint64

Expand Down
7 changes: 0 additions & 7 deletions store/wire.go

This file was deleted.

6 changes: 0 additions & 6 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,6 @@ func removeZeroCoins(coins Coins) Coins {
return coins[:i]
}

func copyCoins(coins Coins) Coins {
copyCoins := make(Coins, len(coins))
copy(copyCoins, coins)
return copyCoins
}

//-----------------------------------------------------------------------------
// Sort interface

Expand Down
1 change: 1 addition & 0 deletions types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ func AppendMsgToErr(msg string, err string) string {
}

// returns the index of the message in the ABCI Log
// nolint: deadcode unused
func mustGetMsgIndex(abciLog string) int {
msgIdx := strings.Index(abciLog, "message\":\"")
if msgIdx == -1 {
Expand Down
3 changes: 0 additions & 3 deletions types/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"math/big"
"math/rand"
)

const maxBitLen = 255
Expand Down Expand Up @@ -37,8 +36,6 @@ func mod(i *big.Int, i2 *big.Int) *big.Int { return new(big.Int).Mod(i, i2) }

func neg(i *big.Int) *big.Int { return new(big.Int).Neg(i) }

func random(i *big.Int) *big.Int { return new(big.Int).Rand(rand.New(rand.NewSource(rand.Int63())), i) }

func min(i *big.Int, i2 *big.Int) *big.Int {
if i.Cmp(i2) == 1 {
return new(big.Int).Set(i2)
Expand Down
3 changes: 0 additions & 3 deletions types/uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ func MaxUint(u1, u2 Uint) Uint { return NewUintFromBigInt(max(u1.i, u2.i)) }
// Human readable string
func (u Uint) String() string { return u.i.String() }

// Testing purpose random Uint generator
func randomUint(u Uint) Uint { return NewUintFromBigInt(random(u.i)) }

// MarshalAmino defines custom encoding scheme
func (u Uint) MarshalAmino() (string, error) {
if u.i == nil { // Necessary since default Uint initialization has i.i as nil
Expand Down
14 changes: 0 additions & 14 deletions x/auth/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,6 @@ func (ak AccountKeeper) GetSequence(ctx sdk.Context, addr sdk.AccAddress) (uint6
return acc.GetSequence(), nil
}

func (ak AccountKeeper) setSequence(ctx sdk.Context, addr sdk.AccAddress, newSequence uint64) sdk.Error {
acc := ak.GetAccount(ctx, addr)
if acc == nil {
return sdk.ErrUnknownAddress(fmt.Sprintf("account %s does not exist", addr))
}

if err := acc.SetSequence(newSequence); err != nil {
panic(err)
}

ak.SetAccount(ctx, acc)
return nil
}

// GetNextAccountNumber Returns and increments the global account number counter
func (ak AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64 {
var accNumber uint64
Expand Down
1 change: 1 addition & 0 deletions x/distribution/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)

//nolint: deadcode unused
var (
delPk1 = ed25519.GenPrivKey().PubKey()
delPk2 = ed25519.GenPrivKey().PubKey()
Expand Down
1 change: 1 addition & 0 deletions x/distribution/types/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// nolint: deadcode unused
var (
delPk1 = ed25519.GenPrivKey().PubKey()
delPk2 = ed25519.GenPrivKey().PubKey()
Expand Down
2 changes: 0 additions & 2 deletions x/genutil/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking"
)

const flagGenTxDir = "gentx-dir"

// common config options for init
type InitConfig struct {
ChainID string
Expand Down
9 changes: 0 additions & 9 deletions x/genutil/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking"
)

var (
defaultTokens = sdk.TokensFromConsensusPower(100)
defaultAmount = defaultTokens.String() + sdk.DefaultBondDenom
defaultCommissionRate = "0.1"
defaultCommissionMaxRate = "0.2"
defaultCommissionMaxChangeRate = "0.01"
defaultMinSelfDelegation = "1"
)

// ValidateAccountInGenesis checks that the provided key has sufficient
// coins in the genesis accounts
func ValidateAccountInGenesis(appGenesisState map[string]json.RawMessage,
Expand Down
1 change: 1 addition & 0 deletions x/gov/test_common.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint:deadcode unused
package gov

import (
Expand Down
1 change: 1 addition & 0 deletions x/mint/internal/keeper/test_common.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint:deadcode unused
package keeper

import (
Expand Down
1 change: 1 addition & 0 deletions x/params/test_common.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint: deadcode unused
package params

import (
Expand Down
1 change: 1 addition & 0 deletions x/slashing/test_common.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint:deadcode unused
package slashing

import (
Expand Down
1 change: 0 additions & 1 deletion x/staking/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ var (
FsMinSelfDelegation = flag.NewFlagSet("", flag.ContinueOnError)
fsDescriptionEdit = flag.NewFlagSet("", flag.ContinueOnError)
fsValidator = flag.NewFlagSet("", flag.ContinueOnError)
fsDelegator = flag.NewFlagSet("", flag.ContinueOnError)
fsRedelegation = flag.NewFlagSet("", flag.ContinueOnError)
)

Expand Down
8 changes: 4 additions & 4 deletions x/staking/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ import (
)

// dummy addresses used for testing
// nolint: unused deadcode
var (
Addrs = createTestAddrs(500)
PKs = createTestPubKeys(500)
emptyAddr sdk.AccAddress
emptyPubkey crypto.PubKey
Addrs = createTestAddrs(500)
PKs = createTestPubKeys(500)

addrDels = []sdk.AccAddress{
Addrs[0],
Expand Down Expand Up @@ -258,6 +257,7 @@ func TestingUpdateValidator(keeper Keeper, ctx sdk.Context, validator types.Vali
return validator
}

// nolint: deadcode unused
func validatorByPowerIndexExists(k Keeper, ctx sdk.Context, power []byte) bool {
store := ctx.KVStore(k.storeKey)
return store.Has(power)
Expand Down
1 change: 1 addition & 0 deletions x/staking/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

// nolint: deadcode unused
var (
priv1 = secp256k1.GenPrivKey()
addr1 = sdk.AccAddress(priv1.PubKey().Address())
Expand Down
1 change: 1 addition & 0 deletions x/staking/types/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// nolint: deadcode unused
var (
pk1 = ed25519.GenPrivKey().PubKey()
pk2 = ed25519.GenPrivKey().PubKey()
Expand Down

0 comments on commit 4ffabb6

Please sign in to comment.