Skip to content

Commit

Permalink
golangci-lint: enable gocritic (#14995)
Browse files Browse the repository at this point in the history
* golangci-lint: enable gocritic

* auto-fix gocritic
  • Loading branch information
jmank88 authored Oct 30, 2024
1 parent 035893b commit 50c1b3d
Show file tree
Hide file tree
Showing 75 changed files with 133 additions and 132 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ linters:
- exportloopref
- fatcontext
- ginkgolinter
- gocritic
- goimports
- gosec
- loggercheck
Expand Down
8 changes: 4 additions & 4 deletions common/client/node_selector_highest_head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestHighestHeadNodeSelectorWithOrder(t *testing.T) {
nodes = append(nodes, node)
}
selector := newNodeSelector(NodeSelectionModeHighestHead, nodes)
//Should select the first node because all things are equal
// Should select the first node because all things are equal
assert.Same(t, nodes[0], selector.Select())
})

Expand All @@ -128,7 +128,7 @@ func TestHighestHeadNodeSelectorWithOrder(t *testing.T) {

nodes := []Node[types.ID, nodeClient]{node1, node2, node3}
selector := newNodeSelector(NodeSelectionModeHighestHead, nodes)
//Should select the second node as it has the highest priority
// Should select the second node as it has the highest priority
assert.Same(t, nodes[1], selector.Select())
})

Expand All @@ -147,7 +147,7 @@ func TestHighestHeadNodeSelectorWithOrder(t *testing.T) {

nodes := []Node[types.ID, nodeClient]{node1, node2, node3}
selector := newNodeSelector(NodeSelectionModeHighestHead, nodes)
//Should select the third node as it has the highest head
// Should select the third node as it has the highest head
assert.Same(t, nodes[2], selector.Select())
})

Expand All @@ -170,7 +170,7 @@ func TestHighestHeadNodeSelectorWithOrder(t *testing.T) {

nodes := []Node[types.ID, nodeClient]{node1, node2, node3, node4}
selector := newNodeSelector(NodeSelectionModeHighestHead, nodes)
//Should select the third node as it has the highest head and will win the priority tie-breaker
// Should select the third node as it has the highest head and will win the priority tie-breaker
assert.Same(t, nodes[2], selector.Select())
})
}
2 changes: 1 addition & 1 deletion common/client/node_selector_total_difficulty.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s totalDifficultyNodeSelector[CHAIN_ID, RPC]) Select() Node[CHAIN_ID, RPC]
}
}

//If all nodes have td == nil pick one from the nodes that are alive
// If all nodes have td == nil pick one from the nodes that are alive
if len(nodes) == 0 {
return firstOrHighestPriority(aliveNodes)
}
Expand Down
8 changes: 4 additions & 4 deletions common/client/node_selector_total_difficulty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestTotalDifficultyNodeSelectorWithOrder(t *testing.T) {
nodes = append(nodes, node)
}
selector := newNodeSelector(NodeSelectionModeTotalDifficulty, nodes)
//Should select the first node because all things are equal
// Should select the first node because all things are equal
assert.Same(t, nodes[0], selector.Select())
})

Expand All @@ -130,7 +130,7 @@ func TestTotalDifficultyNodeSelectorWithOrder(t *testing.T) {

nodes := []Node[types.ID, nodeClient]{node1, node2, node3}
selector := newNodeSelector(NodeSelectionModeTotalDifficulty, nodes)
//Should select the second node as it has the highest priority
// Should select the second node as it has the highest priority
assert.Same(t, nodes[1], selector.Select())
})

Expand All @@ -149,7 +149,7 @@ func TestTotalDifficultyNodeSelectorWithOrder(t *testing.T) {

nodes := []Node[types.ID, nodeClient]{node1, node2, node3}
selector := newNodeSelector(NodeSelectionModeTotalDifficulty, nodes)
//Should select the third node as it has the highest td
// Should select the third node as it has the highest td
assert.Same(t, nodes[2], selector.Select())
})

Expand All @@ -172,7 +172,7 @@ func TestTotalDifficultyNodeSelectorWithOrder(t *testing.T) {

nodes := []Node[types.ID, nodeClient]{node1, node2, node3, node4}
selector := newNodeSelector(NodeSelectionModeTotalDifficulty, nodes)
//Should select the third node as it has the highest td and will win the priority tie-breaker
// Should select the third node as it has the highest td and will win the priority tie-breaker
assert.Same(t, nodes[2], selector.Select())
})
}
2 changes: 1 addition & 1 deletion common/txmgr/confirmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Ens
"chainLength", head.ChainLength(),
}

//Here, we rely on the finalized block provided in the chain instead of the one
// Here, we rely on the finalized block provided in the chain instead of the one
//provided via a dedicated method to avoid the false warning of the chain being
//too short. When `FinalityTagBypass = true,` HeadTracker tracks `finality depth
//+ history depth` to prevent excessive CPU usage. Thus, the provided chain may
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestHomeChainReader_ChainConfigs(t *testing.T) {
p2pIDs := integrationhelpers.P2pIDsFromInts(arr)
uni.AddCapability(p2pIDs)

//==============================Apply configs to Capability Contract=================================
// ==============================Apply configs to Capability Contract=================================
encodedChainConfig, err := chainconfig.EncodeChainConfig(chainconfig.ChainConfig{
GasPriceDeviationPPB: cciptypes.NewBigIntFromInt64(1000),
DAGasPriceDeviationPPB: cciptypes.NewBigIntFromInt64(1_000_000),
Expand All @@ -62,7 +62,7 @@ func TestHomeChainReader_ChainConfigs(t *testing.T) {

t.Logf("homchain reader is ready")

//================================Test HomeChain Reader===============================
// ================================Test HomeChain Reader===============================
expectedChainConfigs := map[cciptypes.ChainSelector]ccipreader.ChainConfig{}
for _, c := range inputConfig {
expectedChainConfigs[cciptypes.ChainSelector(c.ChainSelector)] = ccipreader.ChainConfig{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestRMNHomeReader_GetRMNNodesInfo(t *testing.T) {
observerBitmap2 = 1
)

//================================Deploy and configure RMNHome===============================
// ================================Deploy and configure RMNHome===============================
rmnHomeAddress, _, rmnHome, err := rmn_home.DeployRMNHome(uni.Transactor, uni.Backend)
require.NoError(t, err)
uni.Backend.Commit()
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestRMNHomeReader_GetRMNNodesInfo(t *testing.T) {
require.NoError(t, err1)
})

//================================Test RMNHome Reader===============================
// ================================Test RMNHome Reader===============================
expectedNodesInfo := integrationhelpers.GenerateExpectedRMNHomeNodesInfo(staticConfig, chainID1)

require.Eventually(
Expand Down
18 changes: 9 additions & 9 deletions core/capabilities/ccip/types/mocks/home_chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,47 @@ type HomeChainReader struct {
}

func (_m *HomeChainReader) GetChainConfig(chainSelector cciptypes.ChainSelector) (ccipreaderpkg.ChainConfig, error) {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (_m *HomeChainReader) GetAllChainConfigs() (map[cciptypes.ChainSelector]ccipreaderpkg.ChainConfig, error) {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (_m *HomeChainReader) GetSupportedChainsForPeer(id types.PeerID) (mapset.Set[cciptypes.ChainSelector], error) {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (_m *HomeChainReader) GetKnownCCIPChains() (mapset.Set[cciptypes.ChainSelector], error) {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (_m *HomeChainReader) GetFChain() (map[cciptypes.ChainSelector]int, error) {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (_m *HomeChainReader) Start(ctx context.Context) error {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (_m *HomeChainReader) Close() error {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (_m *HomeChainReader) HealthReport() map[string]error {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (_m *HomeChainReader) Name() string {
//TODO implement me
// TODO implement me
panic("implement me")
}

Expand Down
2 changes: 1 addition & 1 deletion core/capabilities/integration_tests/framework/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func NewPeerID() string {

peerID := append(libp2pMagic(), privKey[:]...)

return base58.Encode(peerID[:])
return base58.Encode(peerID)
}

func libp2pMagic() []byte {
Expand Down
2 changes: 1 addition & 1 deletion core/capabilities/remote/target/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func NewPeerID() string {

peerID := append(libp2pMagic(), privKey[:]...)

return base58.Encode(peerID[:])
return base58.Encode(peerID)
}

func libp2pMagic() []byte {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func NewPeerID() string {

peerID := append(libp2pMagic(), privKey[:]...)

return base58.Encode(peerID[:])
return base58.Encode(peerID)
}

func libp2pMagic() []byte {
Expand Down
4 changes: 2 additions & 2 deletions core/chains/chain_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ func Test_ChainKV(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, cs, 1)

//List explicit chain
// List explicit chain
cs, err = kv.List(testChainID)
assert.NoError(t, err)
assert.Len(t, cs, 1)
assert.Equal(t, testChain, cs[0])

//List no such id
// List no such id
cs, err = kv.List("no such id")
assert.Error(t, err)
assert.Len(t, cs, 0)
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/abi/selector_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func parseCompositeType(unescapedSelector string) ([]abi.ArgumentMarshaling, str
// if we're at a delimiter the parameter is unnamed
if !(rest[0] == ',' || rest[0] == ')') {
// attempt to parse name
name, rest, err = parseIdentifier(rest[:])
name, rest, err = parseIdentifier(rest)
if err != nil {
return nil, "", fmt.Errorf("failed to parse name: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/client/chain_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func (c *chainClient) TransactionReceipt(ctx context.Context, txHash common.Hash
if err != nil {
return receipt, err
}
//return rpc.TransactionReceipt(ctx, txHash)
// return rpc.TransactionReceipt(ctx, txHash)
return r.TransactionReceiptGeth(ctx, txHash)
}

Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/client/simulated_backend_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func (c *SimulatedBackendClient) BatchCallContext(ctx context.Context, b []rpc.B
case <-ctx.Done():
return errors.New("context canceled")
default:
//do nothing
// do nothing
}

for i, elem := range b {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/config/chain_scoped_ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import (
)

func Test_ocr2Config(t *testing.T) {
cfg := testutils.NewTestChainScopedConfig(t, nil) //fallback.toml values
cfg := testutils.NewTestChainScopedConfig(t, nil) // fallback.toml values
require.Equal(t, uint32(5400000), cfg.EVM().OCR2().Automation().GasLimit())
}
2 changes: 1 addition & 1 deletion core/chains/evm/config/chain_scoped_ocr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func Test_ocrConfig(t *testing.T) {
cfg := testutils.NewTestChainScopedConfig(t, nil) //fallback.toml values
cfg := testutils.NewTestChainScopedConfig(t, nil) // fallback.toml values

require.Equal(t, uint16(4), cfg.EVM().OCR().ContractConfirmations())
require.Equal(t, mustParseDuration(t, "10s"), cfg.EVM().OCR().ContractTransmitterTransmitTimeout())
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/headtracker/head_saver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestHeadSaver_Load(t *testing.T) {
// verify latest head loaded from db
verifyLatestHead(latestHead)

//verify latest head loaded from memory store
// verify latest head loaded from memory store
latestHead = saver.LatestChain()
require.NotNil(t, latestHead)
verifyLatestHead(latestHead)
Expand Down
Loading

0 comments on commit 50c1b3d

Please sign in to comment.