Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
travis: enable gometalinter (decred#603)
Browse files Browse the repository at this point in the history
* Hook up gometalinter

* travis: enable unconvert

* travis: enable gosimple
  • Loading branch information
dajohi authored and jrick committed Mar 8, 2017
1 parent 72673d9 commit caa57df
Show file tree
Hide file tree
Showing 68 changed files with 283 additions and 677 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ install:
- go get -v github.com/Masterminds/glide
- glide install
- go install -v . ./cmd/...
- go get -v golang.org/x/tools/cmd/cover
- go get -v github.com/bradfitz/goimports
- go get -v github.com/golang/lint/golint
- go get -v github.com/davecgh/go-spew/spew
- go get -v github.com/alecthomas/gometalinter
- gometalinter --install
script:
- export PATH=$PATH:$HOME/gopath/bin
- ./goclean.sh
4 changes: 2 additions & 2 deletions addrmgr/addrmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func TestNeedMoreAddresses(t *testing.T) {
n := addrmgr.New("testneedmoreaddresses", lookupFunc)
addrsToAdd := 1500
b := n.NeedMoreAddresses()
if b == false {
if !b {
t.Errorf("Expected that we need more addresses")
}
addrs := make([]*wire.NetAddress, addrsToAdd)
Expand Down Expand Up @@ -288,7 +288,7 @@ func TestNeedMoreAddresses(t *testing.T) {
}

b = n.NeedMoreAddresses()
if b == true {
if b {
t.Errorf("Expected that we don't need more addresses")
}
}
Expand Down
4 changes: 2 additions & 2 deletions addrmgr/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ func GroupKey(na *wire.NetAddress) string {
}
if IsRFC6145(na) || IsRFC6052(na) {
// last four bytes are the ip address
ip := net.IP(na.IP[12:16])
ip := na.IP[12:16]
return ip.Mask(net.CIDRMask(16, 32)).String()
}

if IsRFC3964(na) {
ip := net.IP(na.IP[2:6])
ip := na.IP[2:6]
return ip.Mask(net.CIDRMask(16, 32)).String()

}
Expand Down
8 changes: 3 additions & 5 deletions blockchain/chaingen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func purchaseCommitmentScript(addr dcrutil.Address, amount, voteFeeLimit, revoca
copy(data[:], addr.ScriptAddress())
binary.LittleEndian.PutUint64(data[20:], uint64(amount))
data[27] |= 1 << 7
binary.LittleEndian.PutUint16(data[28:], uint16(limits))
binary.LittleEndian.PutUint16(data[28:], limits)
script, err := txscript.NewScriptBuilder().AddOp(txscript.OP_RETURN).
AddData(data[:]).Script()
if err != nil {
Expand Down Expand Up @@ -1066,7 +1066,7 @@ func (hp *hash256prng) uniformRandom(upperBound uint32) uint32 {
// (2^32 - (x*2)) % x == 2^32 % x when x <= 2^31
min := ((math.MaxUint32 - (upperBound * 2)) + 1) % upperBound
if upperBound > 0x80000000 {
min = uint32(1 + ^upperBound)
min = 1 + ^upperBound
}

r := hp.Hash256Rand()
Expand Down Expand Up @@ -1249,9 +1249,7 @@ func (g *Generator) ReplaceWithNVotes(numVotes uint16) func(*wire.MsgBlock) {

// Add back the original stake transactions other than the
// original stake votes that have been replaced.
for _, stakeTx := range b.STransactions[defaultNumVotes:] {
stakeTxns = append(stakeTxns, stakeTx)
}
stakeTxns = append(stakeTxns, b.STransactions[defaultNumVotes:]...)

// Update the block with the new stake transactions and the
// header with the new number of votes.
Expand Down
11 changes: 3 additions & 8 deletions blockchain/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// DoStxoTest does a test on a simulated blockchain to ensure that the data
// stored in the STXO buckets is not corrupt.
func (b *BlockChain) DoStxoTest() error {
err := b.db.View(func(dbTx database.Tx) error {
return b.db.View(func(dbTx database.Tx) error {
for i := int64(2); i <= b.bestNode.height; i++ {
block, err := dbFetchBlockByHeight(dbTx, i)
if err != nil {
Expand All @@ -39,20 +39,15 @@ func (b *BlockChain) DoStxoTest() error {
return err
}

if int(ntx) != len(stxos) {
if ntx != len(stxos) {
return fmt.Errorf("bad number of stxos calculated at "+
"height %v, got %v expected %v",
i, len(stxos), int(ntx))
i, len(stxos), ntx)
}
}

return nil
})
if err != nil {
return err
}

return nil
}

// DebugBlockHeaderString dumps a verbose message containing information about
Expand Down
4 changes: 2 additions & 2 deletions blockchain/difficulty.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ func (b *BlockChain) calcNextRequiredStakeDifficulty(curNode *blockNode) (int64,
alpha := b.chainParams.StakeDiffAlpha
stakeDiffStartHeight := int64(b.chainParams.CoinbaseMaturity) +
1
maxRetarget := int64(b.chainParams.RetargetAdjustmentFactor)
maxRetarget := b.chainParams.RetargetAdjustmentFactor
TicketPoolWeight := int64(b.chainParams.TicketPoolSizeWeight)

// Number of nodes to traverse while calculating difficulty.
Expand Down Expand Up @@ -759,7 +759,7 @@ func (b *BlockChain) estimateNextStakeDifficulty(curNode *blockNode,
alpha := b.chainParams.StakeDiffAlpha
stakeDiffStartHeight := int64(b.chainParams.CoinbaseMaturity) +
1
maxRetarget := int64(b.chainParams.RetargetAdjustmentFactor)
maxRetarget := b.chainParams.RetargetAdjustmentFactor
TicketPoolWeight := int64(b.chainParams.TicketPoolSizeWeight)

// Number of nodes to traverse while calculating difficulty.
Expand Down
5 changes: 1 addition & 4 deletions blockchain/indexers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,7 @@ func (m *Manager) Init(chain *blockchain.BlockChain) error {
err := m.db.View(func(dbTx database.Tx) error {
idxKey := indexer.Key()
hash, height, err = dbFetchIndexerTip(dbTx, idxKey)
if err != nil {
return err
}
return nil
return err
})
if err != nil {
return err
Expand Down
14 changes: 2 additions & 12 deletions blockchain/scriptval.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,7 @@ func ValidateTransactionScripts(tx *dcrutil.Tx, utxoView *UtxoViewpoint, flags t
}

// Validate all of the inputs.
validator := newTxValidator(utxoView, flags, sigCache)
if err := validator.Validate(txValItems); err != nil {
return err
}

return nil
return newTxValidator(utxoView, flags, sigCache).Validate(txValItems)

}

Expand Down Expand Up @@ -263,10 +258,5 @@ func checkBlockScripts(block *dcrutil.Block, utxoView *UtxoViewpoint, txTree boo
}

// Validate all of the inputs.
validator := newTxValidator(utxoView, scriptFlags, sigCache)
if err := validator.Validate(txValItems); err != nil {
return err
}

return nil
return newTxValidator(utxoView, scriptFlags, sigCache).Validate(txValItems)
}
6 changes: 1 addition & 5 deletions blockchain/stake/internal/ticketdb/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,5 @@ func DbCreate(dbTx database.Tx) error {
// Create the bucket that houses the tickets that were added with
// this block into the main chain.
_, err = meta.CreateBucket(dbnamespace.TicketsInBlockBucketName)
if err != nil {
return err
}

return nil
return err
}
12 changes: 2 additions & 10 deletions blockchain/stake/internal/ticketdb/chainio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,7 @@ func TestLiveDatabase(t *testing.T) {
var dbi *DatabaseInfo
err = testDb.View(func(dbTx database.Tx) error {
dbi, err = DbFetchDatabaseInfo(dbTx)
if err != nil {
return err
}

return nil
return err
})
if err != nil {
t.Fatalf("%v", err.Error())
Expand Down Expand Up @@ -495,11 +491,7 @@ func TestLiveDatabase(t *testing.T) {
ticketMap2 := make(map[tickettreap.Key]*tickettreap.Value)
err = testDb.View(func(dbTx database.Tx) error {
treap, err = DbLoadAllTickets(dbTx, dbnamespace.LiveTicketsBucketName)
if err != nil {
return err
}

return nil
return err
})
if err != nil {
t.Fatalf("%v", err.Error())
Expand Down
11 changes: 4 additions & 7 deletions blockchain/stake/internal/tickettreap/immutable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestImmutableEmpty(t *testing.T) {

// Ensure there are no errors with requesting keys from an empty treap.
key := uint32ToKey(0)
if gotVal := testTreap.Has(key); gotVal != false {
if gotVal := testTreap.Has(key); gotVal {
t.Fatalf("Has: unexpected result - got %v, want false", gotVal)
}
if gotVal := testTreap.Get(key); gotVal != nil {
Expand Down Expand Up @@ -357,7 +357,7 @@ func TestImmutableDuplicatePut(t *testing.T) {
testTreap = testTreap.Put(key, expectedVal)

// Ensure the key still exists and is the new value.
if gotVal := testTreap.Has(key); gotVal != true {
if gotVal := testTreap.Has(key); !gotVal {
t.Fatalf("Has: unexpected result - got %v, want false",
gotVal)
}
Expand Down Expand Up @@ -386,7 +386,7 @@ func TestImmutableNilValue(t *testing.T) {
testTreap = testTreap.Put(key, nil)

// Ensure the key does NOT exist.
if gotVal := testTreap.Has(key); gotVal == true {
if gotVal := testTreap.Has(key); gotVal {
t.Fatalf("Has: unexpected result - got %v, want false", gotVal)
}
if gotVal := testTreap.Get(key); gotVal != nil {
Expand All @@ -412,10 +412,7 @@ func TestImmutableForEachStopIterator(t *testing.T) {
var numIterated int
testTreap.ForEach(func(k Key, v *Value) bool {
numIterated++
if numIterated == numItems/2 {
return false
}
return true
return numIterated != numItems/2
})
if numIterated != numItems/2 {
t.Fatalf("ForEach: unexpected iterate count - got %d, want %d",
Expand Down
11 changes: 4 additions & 7 deletions blockchain/stake/internal/tickettreap/mutable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestMutableEmpty(t *testing.T) {

// Ensure there are no errors with requesting keys from an empty treap.
key := uint32ToKey(0)
if gotVal := testTreap.Has(key); gotVal != false {
if gotVal := testTreap.Has(key); gotVal {
t.Fatalf("Has: unexpected result - got %v, want false", gotVal)
}
if gotVal := testTreap.Get(key); gotVal != nil {
Expand Down Expand Up @@ -408,7 +408,7 @@ func TestMutableDuplicatePut(t *testing.T) {
testTreap.Put(key, expectedVal)

// Ensure the key still exists and is the new value.
if gotVal := testTreap.Has(key); gotVal != true {
if gotVal := testTreap.Has(key); !gotVal {
t.Fatalf("Has: unexpected result - got %v, want false",
gotVal)
}
Expand Down Expand Up @@ -437,7 +437,7 @@ func TestMutableNilValue(t *testing.T) {
testTreap.Put(key, nil)

// Ensure the key does NOT exist.
if gotVal := testTreap.Has(key); gotVal == true {
if gotVal := testTreap.Has(key); gotVal {
t.Fatalf("Has: unexpected result - got %v, want false", gotVal)
}
if gotVal := testTreap.Get(key); gotVal != nil {
Expand All @@ -463,10 +463,7 @@ func TestMutableForEachStopIterator(t *testing.T) {
var numIterated int
testTreap.ForEach(func(k Key, v *Value) bool {
numIterated++
if numIterated == numItems/2 {
return false
}
return true
return numIterated != numItems/2
})
if numIterated != numItems/2 {
t.Fatalf("ForEach: unexpected iterate count - got %d, want %d",
Expand Down
12 changes: 6 additions & 6 deletions blockchain/stake/staketx.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,10 +873,10 @@ func IsSStx(tx *wire.MsgTx) (bool, error) {
outputScriptBuffer := bytes.NewBuffer(rawScript)
outputScriptPrefix := outputScriptBuffer.Next(2)

minPush := uint8(validSStxAddressOutMinPrefix[1])
maxPush := uint8(validSStxAddressOutMinPrefix[1]) +
minPush := validSStxAddressOutMinPrefix[1]
maxPush := validSStxAddressOutMinPrefix[1] +
(MaxSingleBytePushLength - minPush)
pushLen := uint8(outputScriptPrefix[1])
pushLen := outputScriptPrefix[1]
pushLengthValid := (pushLen >= minPush) && (pushLen <= maxPush)
// The first byte should be OP_RETURN, while the second byte should be a
// valid push length.
Expand Down Expand Up @@ -1034,10 +1034,10 @@ func IsSSGen(tx *wire.MsgTx) (bool, error) {
firstOutputScriptBuffer := bytes.NewBuffer(firstOutputScript)
firstOutputScriptPrefix := firstOutputScriptBuffer.Next(2)

minPush := uint8(validSSGenVoteOutMinPrefix[1])
maxPush := uint8(validSSGenVoteOutMinPrefix[1]) +
minPush := validSSGenVoteOutMinPrefix[1]
maxPush := validSSGenVoteOutMinPrefix[1] +
(MaxSingleBytePushLength - minPush)
pushLen := uint8(firstOutputScriptPrefix[1])
pushLen := firstOutputScriptPrefix[1]
pushLengthValid := (pushLen >= minPush) && (pushLen <= maxPush)
// The first byte should be OP_RETURN, while the second byte should be a
// valid push length.
Expand Down
Loading

0 comments on commit caa57df

Please sign in to comment.