New lint version upgrade (#4056)

* New lint version upgrade

- linter was upgraded

Signed-off-by: Marko Baricevic <marbar3778@yahoo.com>

* enable-a;; is deprecated

* minor change

* another try

* some more changes

* some more changes

* reenable prealloc

* add version till bot is fixed
This commit is contained in:
Marko
2019-10-14 17:40:15 +02:00
committed by GitHub
parent aaa060fda4
commit 7edc0601d5
17 changed files with 84 additions and 56 deletions

View File

@@ -1,24 +1,52 @@
run:
deadline: 1m
linters:
enable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
# - errcheck
# - funlen
# - gochecknoglobals
# - gochecknoinits
- goconst
- gocritic
# - gocyclo
# - godox
- gofmt
- goimports
# - golint
- gosec
- gosimple
- govet
- ineffassign
- interfacer
# - lll
- misspell
- maligned
- nakedret
- prealloc
- scopelint
- staticcheck
- structcheck
# - stylecheck
- typecheck
- unconvert
# - unparam
- unused
- varcheck
# - whitespace
# - wsl
# - gocognit
disable:
- gocyclo
- golint
- errcheck
- unparam
- lll
- gochecknoglobals
- gochecknoinits
- stylecheck
- funlen
- godox
- whitespace
linters-settings:
dogsled:
max-blank-identifiers: 3
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
# govet:
# check-shadowing: true
# golint:
@@ -49,3 +77,6 @@ linters-settings:
# disabled-checks:
# - wrapperFunc
# - commentFormatting # https://github.com/go-critic/go-critic/issues/755
service:
golangci-lint-version: 1.19.x

View File

@@ -36,7 +36,7 @@ func ensureABCIIsUp(typ string, n int) error {
}
for i := 0; i < n; i++ {
cmd := exec.Command("bash", "-c", cmdString) // nolint: gas
cmd := exec.Command("bash", "-c", cmdString)
_, err = cmd.CombinedOutput()
if err == nil {
break
@@ -53,7 +53,7 @@ func testCounter() {
}
fmt.Printf("Running %s test with abci=%s\n", abciApp, abciType)
cmd := exec.Command("bash", "-c", fmt.Sprintf("abci-cli %s", abciApp)) // nolint: gas
cmd := exec.Command("bash", "-c", fmt.Sprintf("abci-cli %s", abciApp))
cmd.Stdout = os.Stdout
if err := cmd.Start(); err != nil {
log.Fatalf("starting %q err: %v", abciApp, err)

View File

@@ -140,7 +140,7 @@ func (cfg *Config) ValidateBasic() error {
// BaseConfig
// BaseConfig defines the base configuration for a Tendermint node
type BaseConfig struct {
type BaseConfig struct { //nolint: maligned
// chainID is unexposed and immutable but here for convenience
chainID string
@@ -471,7 +471,7 @@ func (cfg RPCConfig) IsTLSEnabled() bool {
// P2PConfig
// P2PConfig defines the configuration options for the Tendermint peer-to-peer networking layer
type P2PConfig struct {
type P2PConfig struct { //nolint: maligned
RootDir string `mapstructure:"home"`
// Address to listen for incoming connections

View File

@@ -639,7 +639,7 @@ func capture() {
// Ensure basic validation of structs is functioning
func TestNewRoundStepMessageValidateBasic(t *testing.T) {
testCases := []struct {
testCases := []struct { // nolint: maligned
expectErr bool
messageRound int
messageLastCommitRound int
@@ -769,7 +769,7 @@ func TestHasVoteMessageValidateBasic(t *testing.T) {
invalidSignedMsgType types.SignedMsgType = 0x03
)
testCases := []struct {
testCases := []struct { // nolint: maligned
expectErr bool
messageRound int
messageIndex int
@@ -814,7 +814,7 @@ func TestVoteSetMaj23MessageValidateBasic(t *testing.T) {
},
}
testCases := []struct {
testCases := []struct { // nolint: maligned
expectErr bool
messageRound int
messageHeight int64
@@ -860,7 +860,7 @@ func TestVoteSetBitsMessageValidateBasic(t *testing.T) {
}
testBitArray := cmn.NewBitArray(1)
testCases := []struct {
testCases := []struct { // nolint: maligned
expectErr bool
messageRound int
messageHeight int64

View File

@@ -13,12 +13,10 @@ import (
// PeerRoundState contains the known state of a peer.
// NOTE: Read-only when returned by PeerState.GetRoundState().
type PeerRoundState struct {
ProposalBlockPartsHeader types.PartSetHeader `json:"proposal_block_parts_header"` //
StartTime time.Time `json:"start_time"` // Estimated start of round 0 at this height
Height int64 `json:"height"` // Height peer is at
Round int `json:"round"` // Round peer is at, -1 if unknown.
Step RoundStepType `json:"step"` // Step peer is at
StartTime time.Time `json:"start_time"` // Estimated start of round 0 at this height
Proposal bool `json:"proposal"` // True if peer has proposal for this round
ProposalBlockPartsHeader types.PartSetHeader `json:"proposal_block_parts_header"` //
ProposalBlockParts *cmn.BitArray `json:"proposal_block_parts"` //
ProposalPOLRound int `json:"proposal_pol_round"` // Proposal's POL round. -1 if none.
ProposalPOL *cmn.BitArray `json:"proposal_pol"` // nil until ProposalPOLMessage received.
@@ -28,6 +26,8 @@ type PeerRoundState struct {
LastCommit *cmn.BitArray `json:"last_commit"` // All commit precommits of commit for last height.
CatchupCommitRound int `json:"catchup_commit_round"` // Round that we have commit for. Not necessarily unique. -1 if none.
CatchupCommit *cmn.BitArray `json:"catchup_commit"` // All commit precommits peer has for this height & CatchupCommitRound
Step RoundStepType `json:"step"` // Step peer is at
Proposal bool `json:"proposal"` // True if peer has proposal for this round
}
// String returns a string representation of the PeerRoundState

View File

@@ -65,11 +65,10 @@ func (rs RoundStepType) String() string {
// NOTE: Not thread safe. Should only be manipulated by functions downstream
// of the cs.receiveRoutine
type RoundState struct {
Height int64 `json:"height"` // Height we are working on
Round int `json:"round"`
Step RoundStepType `json:"step"`
StartTime time.Time `json:"start_time"`
CommitTime time.Time `json:"commit_time"` // Subjective time when +2/3 precommits for Block at Round were found
Height int64 `json:"height"` // Height we are working on
Round int `json:"round"`
Validators *types.ValidatorSet `json:"validators"`
Proposal *types.Proposal `json:"proposal"`
ProposalBlock *types.Block `json:"proposal_block"`
@@ -84,6 +83,7 @@ type RoundState struct {
CommitRound int `json:"commit_round"` //
LastCommit *types.VoteSet `json:"last_commit"` // Last precommits at Height-1
LastValidators *types.ValidatorSet `json:"last_validators"`
Step RoundStepType `json:"step"`
TriggeredTimeoutPrecommit bool `json:"triggered_timeout_precommit"`
}

View File

@@ -107,7 +107,7 @@ const timeRemLimit = 999*time.Hour + 59*time.Minute + 59*time.Second
// Status represents the current Monitor status. All transfer rates are in bytes
// per second rounded to the nearest byte.
type Status struct {
Active bool // Flag indicating an active transfer
Start time.Time // Transfer start time
Bytes int64 // Total number of bytes transferred
Samples int64 // Total number of samples taken
InstRate int64 // Instantaneous transfer rate
@@ -115,11 +115,11 @@ type Status struct {
AvgRate int64 // Average transfer rate (Bytes / Duration)
PeakRate int64 // Maximum instantaneous transfer rate
BytesRem int64 // Number of bytes remaining in the transfer
Start time.Time // Transfer start time
Duration time.Duration // Time period covered by the statistics
Idle time.Duration // Time since the last transfer of at least 1 byte
TimeRem time.Duration // Estimated time to completion
Progress Percent // Overall transfer progress
Active bool // Flag indicating an active transfer
}
// Status returns current transfer status information. The returned value

View File

@@ -81,12 +81,12 @@ func TestReader(t *testing.T) {
// Active, Bytes, Samples, InstRate, CurRate, AvgRate, PeakRate, BytesRem, Start, Duration, Idle, TimeRem, Progress
want := []Status{
{true, 0, 0, 0, 0, 0, 0, 0, start, 0, 0, 0, 0},
{true, 10, 1, 100, 100, 100, 100, 0, start, _100ms, 0, 0, 0},
{true, 20, 2, 100, 100, 100, 100, 0, start, _200ms, _100ms, 0, 0},
{true, 20, 3, 0, 90, 67, 100, 0, start, _300ms, _200ms, 0, 0},
{false, 20, 3, 0, 0, 67, 100, 0, start, _300ms, 0, 0, 0},
{false, 20, 3, 0, 0, 67, 100, 0, start, _300ms, 0, 0, 0},
{start, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true},
{start, 10, 1, 100, 100, 100, 100, 0, _100ms, 0, 0, 0, true},
{start, 20, 2, 100, 100, 100, 100, 0, _200ms, _100ms, 0, 0, true},
{start, 20, 3, 0, 90, 67, 100, 0, _300ms, _200ms, 0, 0, true},
{start, 20, 3, 0, 0, 67, 100, 0, _300ms, 0, 0, 0, false},
{start, 20, 3, 0, 0, 67, 100, 0, _300ms, 0, 0, 0, false},
}
for i, s := range status {
s := s
@@ -140,9 +140,10 @@ func TestWriter(t *testing.T) {
// Active, Bytes, Samples, InstRate, CurRate, AvgRate, PeakRate, BytesRem, Start, Duration, Idle, TimeRem, Progress
want := []Status{
{true, 80, 4, 200, 200, 200, 200, 20, start, _400ms, 0, _100ms, 80000},
{true, 100, 5, 200, 200, 200, 200, 0, start, _500ms, _100ms, 0, 100000},
{start, 80, 4, 200, 200, 200, 200, 20, _400ms, 0, _100ms, 80000, true},
{start, 100, 5, 200, 200, 200, 200, 0, _500ms, _100ms, 0, 100000, true},
}
for i, s := range status {
s := s
if !statusesAreEqual(&s, &want[i]) {

View File

@@ -839,7 +839,6 @@ func (n *Node) ConfigureRPC() {
pubKey := n.privValidator.GetPubKey()
rpccore.SetPubKey(pubKey)
rpccore.SetGenesisDoc(n.genesisDoc)
rpccore.SetAddrBook(n.addrBook)
rpccore.SetProxyAppQuery(n.proxyApp.Query())
rpccore.SetTxIndexer(n.txIndexer)
rpccore.SetConsensusReactor(n.consensusReactor)

View File

@@ -819,9 +819,9 @@ func (a *addrBook) groupKey(na *p2p.NetAddress) string {
// doubleSha256 calculates sha256(sha256(b)) and returns the resulting bytes.
func doubleSha256(b []byte) []byte {
hasher := sha256.New()
hasher.Write(b) // nolint: errcheck, gas
hasher.Write(b) // nolint:errcheck
sum := hasher.Sum(nil)
hasher.Reset()
hasher.Write(sum) // nolint: errcheck, gas
hasher.Write(sum) // nolint:errcheck
return hasher.Sum(nil)
}

View File

@@ -490,7 +490,7 @@ func (r *PEXReactor) ensurePeers() {
peers := r.Switch.Peers().List()
peersCount := len(peers)
if peersCount > 0 {
peer := peers[cmn.RandInt()%peersCount] // nolint: gas
peer := peers[cmn.RandInt()%peersCount]
r.Logger.Info("We need more addresses. Sending pexRequest to random peer", "peer", peer)
r.RequestAddrs(peer)
}

View File

@@ -354,6 +354,7 @@ func TestSwitchStopPeerForError(t *testing.T) {
scrapeMetrics := func() string {
resp, _ := http.Get(s.URL)
buf, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
return string(buf)
}

View File

@@ -70,7 +70,6 @@ var (
// objects
pubKey crypto.PubKey
genDoc *types.GenesisDoc // cache the genesis structure
addrBook p2p.AddrBook
txIndexer txindex.TxIndexer
consensusReactor *consensus.ConsensusReactor
eventBus *types.EventBus // thread safe
@@ -117,10 +116,6 @@ func SetGenesisDoc(doc *types.GenesisDoc) {
genDoc = doc
}
func SetAddrBook(book p2p.AddrBook) {
addrBook = book
}
func SetProxyAppQuery(appConn proxy.AppConnQuery) {
proxyAppQuery = appConn
}

View File

@@ -27,7 +27,7 @@ const (
// WSClient is a WebSocket client. The methods of WSClient are safe for use by
// multiple goroutines.
type WSClient struct {
type WSClient struct { // nolint: maligned
conn *websocket.Conn
cdc *amino.Codec
@@ -252,7 +252,7 @@ func (c *WSClient) dial() error {
Proxy: http.ProxyFromEnvironment,
}
rHeader := http.Header{}
conn, _, err := dialer.Dial(c.protocol+"://"+c.Address+c.Endpoint, rHeader)
conn, _, err := dialer.Dial(c.protocol+"://"+c.Address+c.Endpoint, rHeader) // nolint:bodyclose
if err != nil {
return err
}

View File

@@ -77,6 +77,7 @@ func TestRPCParams(t *testing.T) {
t.Errorf("#%d: err reading body: %v", i, err)
continue
}
res.Body.Close()
recv := new(types.RPCResponse)
assert.Nil(t, json.Unmarshal(blob, recv), "#%d: expecting successful parsing of an RPCResponse:\nblob: %s", i, blob)
@@ -125,6 +126,7 @@ func TestJSONRPCID(t *testing.T) {
t.Errorf("#%d: err reading body: %v", i, err)
continue
}
res.Body.Close()
recv := new(types.RPCResponse)
err = json.Unmarshal(blob, recv)
@@ -150,6 +152,7 @@ func TestRPCNotification(t *testing.T) {
// Always expecting back a JSONRPCResponse
require.True(t, statusOK(res.StatusCode), "should always return 2XX")
blob, err := ioutil.ReadAll(res.Body)
res.Body.Close()
require.Nil(t, err, "reading from the body should not give back an error")
require.Equal(t, len(blob), 0, "a notification SHOULD NOT be responded to by the server")
}
@@ -189,6 +192,7 @@ func TestRPCNotificationInBatch(t *testing.T) {
t.Errorf("#%d: err reading body: %v", i, err)
continue
}
res.Body.Close()
var responses []types.RPCResponse
// try to unmarshal an array first
@@ -229,6 +233,7 @@ func TestUnknownRPCPath(t *testing.T) {
// Always expecting back a 404 error
require.Equal(t, http.StatusNotFound, res.StatusCode, "should always return 404")
res.Body.Close()
}
//////////////////////////////////////////////////////////////////////////////
@@ -257,6 +262,7 @@ func TestWebsocketManagerHandler(t *testing.T) {
err = c.ReadJSON(&resp)
require.NoError(t, err)
require.Nil(t, resp.Error)
dialResp.Body.Close()
}
func newWSServer() *httptest.Server {

View File

@@ -37,7 +37,6 @@ func setupTestCase(t *testing.T) (func(t *testing.T), dbm.DB, sm.State) {
func TestStateCopy(t *testing.T) {
tearDown, _, state := setupTestCase(t)
defer tearDown(t)
// nolint: vetshadow
assert := assert.New(t)
stateCopy := state.Copy()
@@ -68,7 +67,6 @@ func TestMakeGenesisStateNilValidators(t *testing.T) {
func TestStateSaveLoad(t *testing.T) {
tearDown, stateDB, state := setupTestCase(t)
defer tearDown(t)
// nolint: vetshadow
assert := assert.New(t)
state.LastBlockHeight++
@@ -84,7 +82,6 @@ func TestStateSaveLoad(t *testing.T) {
func TestABCIResponsesSaveLoad1(t *testing.T) {
tearDown, stateDB, state := setupTestCase(t)
defer tearDown(t)
// nolint: vetshadow
assert := assert.New(t)
state.LastBlockHeight++
@@ -110,7 +107,6 @@ func TestABCIResponsesSaveLoad1(t *testing.T) {
func TestABCIResponsesSaveLoad2(t *testing.T) {
tearDown, stateDB, _ := setupTestCase(t)
defer tearDown(t)
// nolint: vetshadow
assert := assert.New(t)
cases := [...]struct {
@@ -181,7 +177,6 @@ func TestABCIResponsesSaveLoad2(t *testing.T) {
func TestValidatorSimpleSaveLoad(t *testing.T) {
tearDown, stateDB, state := setupTestCase(t)
defer tearDown(t)
// nolint: vetshadow
assert := assert.New(t)
// Can't load anything for height 0.

View File

@@ -72,7 +72,7 @@ func (t *transacter) Start() error {
rand.Seed(time.Now().Unix())
for i := 0; i < t.Connections; i++ {
c, _, err := connect(t.Target)
c, _, err := connect(t.Target) // nolint:bodyclose
if err != nil {
return err
}