From 4ef140f6ca41e7e3397e34a16d0877a51e286013 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Thu, 4 Nov 2021 13:08:55 +0100 Subject: [PATCH] lint: cleanup pending lint errors (#7237) --- .golangci.yml | 14 +++++++++++--- abci/types/result.go | 2 +- consensus/reactor.go | 2 +- consensus/wal_fuzz.go | 1 + crypto/secp256k1/secp256k1.go | 2 +- crypto/secp256k1/secp256k1_nocgo.go | 1 + crypto/secp256k1/secp256k1_test.go | 2 +- crypto/xchacha20poly1305/xchachapoly_test.go | 2 +- libs/bytes/bytes.go | 2 +- libs/events/event_cache_test.go | 3 ++- libs/json/helpers_test.go | 1 - libs/protoio/io_test.go | 2 +- libs/pubsub/subscription.go | 17 +++++++++-------- libs/sync/deadlock.go | 1 + libs/sync/sync.go | 1 + light/store/db/db.go | 2 +- node/node_test.go | 2 +- p2p/conn/conn_go110.go | 1 + p2p/conn/conn_notgo110.go | 1 + p2p/conn/secret_connection_test.go | 3 ++- p2p/netaddress.go | 8 ++++---- privval/socket_listeners.go | 6 +++--- rpc/client/helpers.go | 2 +- rpc/jsonrpc/client/integration_test.go | 1 + rpc/jsonrpc/types/types.go | 2 +- state/state.go | 4 ++-- state/state_test.go | 2 +- state/store.go | 2 +- state/txindex/indexer_service.go | 2 +- state/validation_test.go | 4 ++-- test/e2e/app/state.go | 2 +- types/event_bus.go | 2 +- types/genesis_test.go | 6 +++--- types/signable.go | 2 +- types/validator_set_test.go | 4 +++- 35 files changed, 65 insertions(+), 46 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index e0f3fe163e0..9d846393df1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -26,14 +26,14 @@ linters: # - interfacer - lll # - maligned - - misspell + # - misspell - nakedret - nolintlint - prealloc - staticcheck - structcheck - stylecheck - - typecheck + # - typecheck - unconvert # - unparam - unused @@ -54,9 +54,17 @@ issues: linters-settings: dogsled: max-blank-identifiers: 3 - golint: + maligned: + suggest-new: true + # govet: + # check-shadowing: true + revive: min-confidence: 0 maligned: suggest-new: true misspell: locale: US + ignore-words: + - behaviour + + diff --git a/abci/types/result.go b/abci/types/result.go index e8916960f40..53acdb90605 100644 --- a/abci/types/result.go +++ b/abci/types/result.go @@ -42,7 +42,7 @@ func (r ResponseQuery) IsErr() bool { } //--------------------------------------------------------------------------- -// override JSON marshalling so we emit defaults (ie. disable omitempty) +// override JSON marshaling so we emit defaults (ie. disable omitempty) var ( jsonpbMarshaller = jsonpb.Marshaler{ diff --git a/consensus/reactor.go b/consensus/reactor.go index d7d27400243..b6fb1faa5b6 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -1476,7 +1476,7 @@ func (m *NewRoundStepMessage) ValidateHeight(initialHeight int64) error { m.LastCommitRound, initialHeight) } if m.Height > initialHeight && m.LastCommitRound < 0 { - return fmt.Errorf("LastCommitRound can only be negative for initial height %v", // nolint + return fmt.Errorf("LastCommitRound can only be negative for initial height %v", initialHeight) } return nil diff --git a/consensus/wal_fuzz.go b/consensus/wal_fuzz.go index e15097c305c..06d894a812d 100644 --- a/consensus/wal_fuzz.go +++ b/consensus/wal_fuzz.go @@ -1,3 +1,4 @@ +//go:build gofuzz // +build gofuzz package consensus diff --git a/crypto/secp256k1/secp256k1.go b/crypto/secp256k1/secp256k1.go index 26926a96692..fa387e35502 100644 --- a/crypto/secp256k1/secp256k1.go +++ b/crypto/secp256k1/secp256k1.go @@ -152,7 +152,7 @@ func (pubKey PubKey) Address() crypto.Address { return crypto.Address(hasherRIPEMD160.Sum(nil)) } -// Bytes returns the pubkey marshalled with amino encoding. +// Bytes returns the pubkey marshaled with amino encoding. func (pubKey PubKey) Bytes() []byte { return []byte(pubKey) } diff --git a/crypto/secp256k1/secp256k1_nocgo.go b/crypto/secp256k1/secp256k1_nocgo.go index cba9bbe4c31..6b52dc5d28b 100644 --- a/crypto/secp256k1/secp256k1_nocgo.go +++ b/crypto/secp256k1/secp256k1_nocgo.go @@ -1,3 +1,4 @@ +//go:build !libsecp256k1 // +build !libsecp256k1 package secp256k1 diff --git a/crypto/secp256k1/secp256k1_test.go b/crypto/secp256k1/secp256k1_test.go index 83249ef6a03..bf62e4e2289 100644 --- a/crypto/secp256k1/secp256k1_test.go +++ b/crypto/secp256k1/secp256k1_test.go @@ -36,7 +36,7 @@ func TestPubKeySecp256k1Address(t *testing.T) { addrBbz, _, _ := base58.CheckDecode(d.addr) addrB := crypto.Address(addrBbz) - var priv secp256k1.PrivKey = secp256k1.PrivKey(privB) + priv := secp256k1.PrivKey(privB) pubKey := priv.PubKey() pubT, _ := pubKey.(secp256k1.PubKey) diff --git a/crypto/xchacha20poly1305/xchachapoly_test.go b/crypto/xchacha20poly1305/xchachapoly_test.go index d5e4b600337..b17b1c376b5 100644 --- a/crypto/xchacha20poly1305/xchachapoly_test.go +++ b/crypto/xchacha20poly1305/xchachapoly_test.go @@ -83,7 +83,7 @@ func TestRandom(t *testing.T) { } } -// AFOREMENTIONED LICENCE +// AFOREMENTIONED LICENSE // Copyright (c) 2009 The Go Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without diff --git a/libs/bytes/bytes.go b/libs/bytes/bytes.go index be294de4ee5..95b4cc35fca 100644 --- a/libs/bytes/bytes.go +++ b/libs/bytes/bytes.go @@ -43,7 +43,7 @@ func (bz *HexBytes) UnmarshalJSON(data []byte) error { return nil } -// Bytes fulfils various interfaces in light-client, etc... +// Bytes fulfills various interfaces in light-client, etc... func (bz HexBytes) Bytes() []byte { return bz } diff --git a/libs/events/event_cache_test.go b/libs/events/event_cache_test.go index 342fe8c651a..3f8641f93d8 100644 --- a/libs/events/event_cache_test.go +++ b/libs/events/event_cache_test.go @@ -13,7 +13,8 @@ func TestEventCache_Flush(t *testing.T) { require.NoError(t, err) err = evsw.AddListenerForEvent("nothingness", "", func(data EventData) { - // Check we are not initialising an empty buffer full of zeroed eventInfos in the EventCache + // Check we are not initializing an empty buffer full + // of zeroed eventInfos in the EventCache require.FailNow(t, "We should never receive a message on this switch since none are fired") }) require.NoError(t, err) diff --git a/libs/json/helpers_test.go b/libs/json/helpers_test.go index a87bc51f153..ccb3c003888 100644 --- a/libs/json/helpers_test.go +++ b/libs/json/helpers_test.go @@ -61,7 +61,6 @@ func (c CustomValue) MarshalJSON() ([]byte, error) { } func (c CustomValue) UnmarshalJSON(bz []byte) error { - c.Value = "custom" return nil } diff --git a/libs/protoio/io_test.go b/libs/protoio/io_test.go index e6e51d05126..201739d5293 100644 --- a/libs/protoio/io_test.go +++ b/libs/protoio/io_test.go @@ -71,7 +71,7 @@ func iotest(writer protoio.WriteCloser, reader protoio.ReadCloser) error { return err } if n != len(bz)+visize { - return fmt.Errorf("WriteMsg() wrote %v bytes, expected %v", n, len(bz)+visize) // nolint + return fmt.Errorf("WriteMsg() wrote %v bytes, expected %v", n, len(bz)+visize) } lens[i] = n } diff --git a/libs/pubsub/subscription.go b/libs/pubsub/subscription.go index 4d6f605c768..1c60c55d594 100644 --- a/libs/pubsub/subscription.go +++ b/libs/pubsub/subscription.go @@ -23,16 +23,16 @@ var ( type Subscription struct { out chan Message - cancelled chan struct{} - mtx tmsync.RWMutex - err error + canceled chan struct{} + mtx tmsync.RWMutex + err error } // NewSubscription returns a new subscription with the given outCapacity. func NewSubscription(outCapacity int) *Subscription { return &Subscription{ - out: make(chan Message, outCapacity), - cancelled: make(chan struct{}), + out: make(chan Message, outCapacity), + canceled: make(chan struct{}), } } @@ -43,13 +43,14 @@ func (s *Subscription) Out() <-chan Message { return s.out } +// nolint: misspell // Cancelled returns a channel that's closed when the subscription is // terminated and supposed to be used in a select statement. func (s *Subscription) Cancelled() <-chan struct{} { - return s.cancelled + return s.canceled } -// Err returns nil if the channel returned by Cancelled is not yet closed. +// Err returns nil if the channel returned is not yet closed. // If the channel is closed, Err returns a non-nil error explaining why: // - ErrUnsubscribed if the subscriber choose to unsubscribe, // - ErrOutOfCapacity if the subscriber is not pulling messages fast enough @@ -66,7 +67,7 @@ func (s *Subscription) cancel(err error) { s.mtx.Lock() s.err = err s.mtx.Unlock() - close(s.cancelled) + close(s.canceled) } // Message glues data and events together. diff --git a/libs/sync/deadlock.go b/libs/sync/deadlock.go index 637d6fbb17e..21b5130ba42 100644 --- a/libs/sync/deadlock.go +++ b/libs/sync/deadlock.go @@ -1,3 +1,4 @@ +//go:build deadlock // +build deadlock package sync diff --git a/libs/sync/sync.go b/libs/sync/sync.go index a0880e7de98..c6e7101c606 100644 --- a/libs/sync/sync.go +++ b/libs/sync/sync.go @@ -1,3 +1,4 @@ +//go:build !deadlock // +build !deadlock package sync diff --git a/light/store/db/db.go b/light/store/db/db.go index adbb3387100..8e24a630e5e 100644 --- a/light/store/db/db.go +++ b/light/store/db/db.go @@ -54,7 +54,7 @@ func (s *dbs) SaveLightBlock(lb *types.LightBlock) error { lbBz, err := lbpb.Marshal() if err != nil { - return fmt.Errorf("marshalling LightBlock: %w", err) + return fmt.Errorf("marshaling LightBlock: %w", err) } s.mtx.Lock() diff --git a/node/node_test.go b/node/node_test.go index d92edcc6d58..55e55534125 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -262,7 +262,7 @@ func TestCreateProposalBlock(t *testing.T) { // fill the evidence pool with more evidence // than can fit in a block - var currentBytes int64 = 0 + var currentBytes int64 for currentBytes <= maxEvidenceBytes { ev := types.NewMockDuplicateVoteEvidenceWithValidator(height, time.Now(), privVals[0], "test-chain") currentBytes += int64(len(ev.Bytes())) diff --git a/p2p/conn/conn_go110.go b/p2p/conn/conn_go110.go index 68218810154..459c3169b14 100644 --- a/p2p/conn/conn_go110.go +++ b/p2p/conn/conn_go110.go @@ -1,3 +1,4 @@ +//go:build go1.10 // +build go1.10 package conn diff --git a/p2p/conn/conn_notgo110.go b/p2p/conn/conn_notgo110.go index ed642eb549a..21dffad2c23 100644 --- a/p2p/conn/conn_notgo110.go +++ b/p2p/conn/conn_notgo110.go @@ -1,3 +1,4 @@ +//go:build !go1.10 // +build !go1.10 package conn diff --git a/p2p/conn/secret_connection_test.go b/p2p/conn/secret_connection_test.go index d4997d81c4e..7fa5abda009 100644 --- a/p2p/conn/secret_connection_test.go +++ b/p2p/conn/secret_connection_test.go @@ -194,7 +194,8 @@ func TestSecretConnectionReadWrite(t *testing.T) { compareWritesReads := func(writes []string, reads []string) { for { // Pop next write & corresponding reads - var read, write string = "", writes[0] + var read = "" + var write = writes[0] var readCount = 0 for _, readChunk := range reads { read += readChunk diff --git a/p2p/netaddress.go b/p2p/netaddress.go index 77209217b21..b42d325c8b9 100644 --- a/p2p/netaddress.go +++ b/p2p/netaddress.go @@ -316,10 +316,10 @@ func (na *NetAddress) ReachabilityTo(o *NetAddress) int { } return Default default: /* ipv6 */ - var tunnelled bool - // Is our v6 is tunnelled? + var tunneled bool + // Is our v6 is tunneled? if o.RFC3964() || o.RFC6052() || o.RFC6145() { - tunnelled = true + tunneled = true } switch { case !o.Routable(): @@ -328,7 +328,7 @@ func (na *NetAddress) ReachabilityTo(o *NetAddress) int { return Teredo case o.IP.To4() != nil: return Ipv4 - case tunnelled: + case tunneled: // only prioritise ipv6 if we aren't tunnelling it. return Ipv6Weak } diff --git a/privval/socket_listeners.go b/privval/socket_listeners.go index ad49adac43b..4e318390a7d 100644 --- a/privval/socket_listeners.go +++ b/privval/socket_listeners.go @@ -39,7 +39,7 @@ func TCPListenerTimeoutReadWrite(timeout time.Duration) TCPListenerOption { // tcpListener implements net.Listener. var _ net.Listener = (*TCPListener)(nil) -// TCPListener wraps a *net.TCPListener to standardise protocol timeouts +// TCPListener wraps a *net.TCPListener to standardize protocol timeouts // and potentially other tuning parameters. It also returns encrypted connections. type TCPListener struct { *net.TCPListener @@ -104,7 +104,7 @@ func UnixListenerTimeoutReadWrite(timeout time.Duration) UnixListenerOption { return func(ul *UnixListener) { ul.timeoutReadWrite = timeout } } -// UnixListener wraps a *net.UnixListener to standardise protocol timeouts +// UnixListener wraps a *net.UnixListener to standardize protocol timeouts // and potentially other tuning parameters. It returns unencrypted connections. type UnixListener struct { *net.UnixListener @@ -151,7 +151,7 @@ func (ln *UnixListener) Accept() (net.Conn, error) { // timeoutConn implements net.Conn. var _ net.Conn = (*timeoutConn)(nil) -// timeoutConn wraps a net.Conn to standardise protocol timeouts / deadline resets. +// timeoutConn wraps a net.Conn to standardize protocol timeouts / deadline resets. type timeoutConn struct { net.Conn timeout time.Duration diff --git a/rpc/client/helpers.go b/rpc/client/helpers.go index 78579b8a349..0878df6a802 100644 --- a/rpc/client/helpers.go +++ b/rpc/client/helpers.go @@ -76,7 +76,7 @@ func WaitForOneEvent(c EventsClient, evtTyp string, timeout time.Duration) (type select { case event := <-eventCh: - return event.Data.(types.TMEventData), nil + return event.Data, nil case <-ctx.Done(): return nil, errors.New("timed out waiting for event") } diff --git a/rpc/jsonrpc/client/integration_test.go b/rpc/jsonrpc/client/integration_test.go index 228bbb460d6..26f24d2555a 100644 --- a/rpc/jsonrpc/client/integration_test.go +++ b/rpc/jsonrpc/client/integration_test.go @@ -1,3 +1,4 @@ +//go:build release // +build release // The code in here is comprehensive as an integration diff --git a/rpc/jsonrpc/types/types.go b/rpc/jsonrpc/types/types.go index 4f05e14c23f..ca7dd3de94c 100644 --- a/rpc/jsonrpc/types/types.go +++ b/rpc/jsonrpc/types/types.go @@ -191,7 +191,7 @@ func NewRPCSuccessResponse(id jsonrpcid, res interface{}) RPCResponse { var js []byte js, err := tmjson.Marshal(res) if err != nil { - return RPCInternalError(id, fmt.Errorf("error marshalling response: %w", err)) + return RPCInternalError(id, fmt.Errorf("error marshaling response: %w", err)) } rawMsg = json.RawMessage(js) } diff --git a/state/state.go b/state/state.go index d9da840ca99..a1df48d45ff 100644 --- a/state/state.go +++ b/state/state.go @@ -175,8 +175,8 @@ func (state *State) ToProto() (*tmstate.State, error) { return sm, nil } -// StateFromProto takes a state proto message & returns the local state type -func StateFromProto(pb *tmstate.State) (*State, error) { //nolint:golint +// FromProto takes a state proto message & returns the local state type +func FromProto(pb *tmstate.State) (*State, error) { //nolint:golint if pb == nil { return nil, errors.New("nil State") } diff --git a/state/state_test.go b/state/state_test.go index 1632f4304b4..b4e33626ac4 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -1075,7 +1075,7 @@ func TestStateProto(t *testing.T) { assert.NoError(t, err, tt.testName) } - smt, err := sm.StateFromProto(pbs) + smt, err := sm.FromProto(pbs) if tt.expPass2 { require.NoError(t, err, tt.testName) require.Equal(t, tt.state, smt, tt.testName) diff --git a/state/store.go b/state/store.go index 550c2cbffa5..070c521028b 100644 --- a/state/store.go +++ b/state/store.go @@ -142,7 +142,7 @@ func (store dbStore) loadState(key []byte) (state State, err error) { %v\n`, err)) } - sm, err := StateFromProto(sp) + sm, err := FromProto(sp) if err != nil { return state, err } diff --git a/state/txindex/indexer_service.go b/state/txindex/indexer_service.go index f3d10ed756a..9f2541b8b0e 100644 --- a/state/txindex/indexer_service.go +++ b/state/txindex/indexer_service.go @@ -40,7 +40,7 @@ func NewIndexerService( // and indexing them by events. func (is *IndexerService) OnStart() error { // Use SubscribeUnbuffered here to ensure both subscriptions does not get - // cancelled due to not pulling messages fast enough. Cause this might + // canceled due to not pulling messages fast enough. Cause this might // sometimes happen when there are no other subscribers. blockHeadersSub, err := is.eventBus.SubscribeUnbuffered( context.Background(), diff --git a/state/validation_test.go b/state/validation_test.go index 2b556b2682b..afd47a6500b 100644 --- a/state/validation_test.go +++ b/state/validation_test.go @@ -240,7 +240,7 @@ func TestValidateBlockEvidence(t *testing.T) { A block with too much evidence fails */ evidence := make([]types.Evidence, 0) - var currentBytes int64 = 0 + var currentBytes int64 // more bytes than the maximum allowed for evidence for currentBytes <= maxBytesEvidence { newEv := types.NewMockDuplicateVoteEvidenceWithValidator(height, time.Now(), @@ -260,7 +260,7 @@ func TestValidateBlockEvidence(t *testing.T) { A good block with several pieces of good evidence passes */ evidence := make([]types.Evidence, 0) - var currentBytes int64 = 0 + var currentBytes int64 // precisely the amount of allowed evidence for { newEv := types.NewMockDuplicateVoteEvidenceWithValidator(height, defaultEvidenceTime, diff --git a/test/e2e/app/state.go b/test/e2e/app/state.go index 33a124caa93..44192645309 100644 --- a/test/e2e/app/state.go +++ b/test/e2e/app/state.go @@ -19,7 +19,7 @@ type State struct { Values map[string]string Hash []byte - // private fields aren't marshalled to disk. + // private fields aren't marshaled to disk. file string persistInterval uint64 initialHeight uint64 diff --git a/types/event_bus.go b/types/event_bus.go index 72ba5e3d67f..3cebcf680c4 100644 --- a/types/event_bus.go +++ b/types/event_bus.go @@ -23,7 +23,7 @@ type EventBusSubscriber interface { type Subscription interface { Out() <-chan tmpubsub.Message - Cancelled() <-chan struct{} + Cancelled() <-chan struct{} // nolint: misspell Err() error } diff --git a/types/genesis_test.go b/types/genesis_test.go index fa579a8d06a..bfb122e646a 100644 --- a/types/genesis_test.go +++ b/types/genesis_test.go @@ -84,7 +84,7 @@ func TestGenesisGood(t *testing.T) { Validators: []GenesisValidator{{pubkey.Address(), pubkey, 10, "myval"}}, } genDocBytes, err = tmjson.Marshal(baseGenDoc) - assert.NoError(t, err, "error marshalling genDoc") + assert.NoError(t, err, "error marshaling genDoc") // test base gendoc and check consensus params were filled genDoc, err := GenesisDocFromJSON(genDocBytes) @@ -96,14 +96,14 @@ func TestGenesisGood(t *testing.T) { // create json with consensus params filled genDocBytes, err = tmjson.Marshal(genDoc) - assert.NoError(t, err, "error marshalling genDoc") + assert.NoError(t, err, "error marshaling genDoc") genDoc, err = GenesisDocFromJSON(genDocBytes) assert.NoError(t, err, "expected no error for valid genDoc json") // test with invalid consensus params genDoc.ConsensusParams.Block.MaxBytes = 0 genDocBytes, err = tmjson.Marshal(genDoc) - assert.NoError(t, err, "error marshalling genDoc") + assert.NoError(t, err, "error marshaling genDoc") _, err = GenesisDocFromJSON(genDocBytes) assert.Error(t, err, "expected error for genDoc json with block size of 0") diff --git a/types/signable.go b/types/signable.go index 074654cc5f5..25e30731686 100644 --- a/types/signable.go +++ b/types/signable.go @@ -17,7 +17,7 @@ var ( // SignBytes returns the bytes to be signed // NOTE: chainIDs are part of the SignBytes but not // necessarily the object themselves. -// NOTE: Expected to panic if there is an error marshalling. +// NOTE: Expected to panic if there is an error marshaling. type Signable interface { SignBytes(chainID string) []byte } diff --git a/types/validator_set_test.go b/types/validator_set_test.go index 84fdcdf4893..67a9a96ea18 100644 --- a/types/validator_set_test.go +++ b/types/validator_set_test.go @@ -492,7 +492,9 @@ func TestAveragingInIncrementProposerPriority(t *testing.T) { {Address: []byte("c"), ProposerPriority: 1}}}, // this should average twice but the average should be 0 after the first iteration // (voting power is 0 -> no changes) - 11, 1 / 3}, + 11, + 0, // 1 / 3 + }, 2: {ValidatorSet{ Validators: []*Validator{ {Address: []byte("a"), ProposerPriority: 100},