Skip to content

Commit

Permalink
lint: cleanup pending lint errors (#7237)
Browse files Browse the repository at this point in the history
Co-authored-by: Sam Kleinman <garen@tychoish.com>
  • Loading branch information
tnasu and tychoish committed Feb 25, 2022
1 parent 2c69c06 commit 83d5134
Show file tree
Hide file tree
Showing 35 changed files with 67 additions and 46 deletions.
14 changes: 11 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ linters:
# - interfacer
- lll
# - maligned
- misspell
# - misspell
- nakedret
- nolintlint
- prealloc
- staticcheck
- structcheck
- stylecheck
- typecheck
# - typecheck
- unconvert
# - unparam
- unused
Expand All @@ -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


2 changes: 1 addition & 1 deletion abci/types/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion consensus/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,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
Expand Down
1 change: 1 addition & 0 deletions consensus/wal_fuzz.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build gofuzz
// +build gofuzz

package consensus
Expand Down
2 changes: 1 addition & 1 deletion crypto/secp256k1/secp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,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)
}
Expand Down
3 changes: 3 additions & 0 deletions crypto/secp256k1/secp256k1_nocgo.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !libsecp256k1
// +build !libsecp256k1

package secp256k1

import (
Expand Down
2 changes: 1 addition & 1 deletion crypto/secp256k1/secp256k1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion crypto/xchacha20poly1305/xchachapoly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libs/bytes/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion libs/events/event_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion libs/json/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (c CustomValue) MarshalJSON() ([]byte, error) {
}

func (c CustomValue) UnmarshalJSON(bz []byte) error {
c.Value = "custom"
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion libs/protoio/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 9 additions & 8 deletions libs/pubsub/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}),
}
}

Expand All @@ -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
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions libs/sync/deadlock.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build deadlock
// +build deadlock

package sync
Expand Down
1 change: 1 addition & 0 deletions libs/sync/sync.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !deadlock
// +build !deadlock

package sync
Expand Down
2 changes: 1 addition & 1 deletion light/store/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,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()))
Expand Down
1 change: 1 addition & 0 deletions p2p/conn/conn_go110.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.10
// +build go1.10

package conn
Expand Down
1 change: 1 addition & 0 deletions p2p/conn/conn_notgo110.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !go1.10
// +build !go1.10

package conn
Expand Down
3 changes: 2 additions & 1 deletion p2p/conn/secret_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,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
Expand Down
8 changes: 4 additions & 4 deletions p2p/netaddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions privval/socket_listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rpc/client/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func WaitForOneEvent(c EventsClient, evtTyp string, timeout time.Duration) (type

select {
case event := <-eventCh:
return event.Data.(types.OCEventData), nil
return event.Data, nil
case <-ctx.Done():
return nil, errors.New("timed out waiting for event")
}
Expand Down
1 change: 1 addition & 0 deletions rpc/jsonrpc/client/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build release
// +build release

// The code in here is comprehensive as an integration
Expand Down
2 changes: 1 addition & 1 deletion rpc/jsonrpc/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,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")
}
Expand Down
2 changes: 1 addition & 1 deletion state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,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)
Expand Down
2 changes: 1 addition & 1 deletion state/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,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
}
Expand Down
2 changes: 1 addition & 1 deletion state/txindex/indexer_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions state/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,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(),
Expand All @@ -267,7 +267,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,
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion types/event_bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type EventBusSubscriber interface {

type Subscription interface {
Out() <-chan tmpubsub.Message
Cancelled() <-chan struct{}
Cancelled() <-chan struct{} // nolint: misspell
Err() error
}

Expand Down
6 changes: 3 additions & 3 deletions types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,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)
Expand All @@ -106,14 +106,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")

Expand Down
Loading

0 comments on commit 83d5134

Please sign in to comment.