Skip to content

Commit

Permalink
[testing] Update golangci-lint to latest version (#3617)
Browse files Browse the repository at this point in the history
Signed-off-by: marun <[email protected]>
Co-authored-by: Stephen Buttolph <[email protected]>
  • Loading branch information
maru-ava and StephenButtolph authored Dec 30, 2024
1 parent 758eb7b commit 8fb6237
Show file tree
Hide file tree
Showing 41 changed files with 56 additions and 106 deletions.
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ linters:
enable:
- asciicheck
- bodyclose
- copyloopvar
- depguard
- dupword
- errcheck
- errorlint
- exportloopref
- forbidigo
- gci
- goconst
Expand Down Expand Up @@ -128,6 +128,7 @@ linters-settings:
gosec:
excludes:
- G107 # Url provided to HTTP request as taint input https://securego.io/docs/rules/g107
- G115 # TODO(marun) Enable this ruleset in a follow-up PR
importas:
# Do not allow unaliased imports of aliased packages.
no-unaliased: false
Expand Down
2 changes: 0 additions & 2 deletions chains/atomic/gsharedmemory/shared_memory_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ func (c *Client) Apply(requests map[ids.ID]*atomic.Requests, batches ...database
Batches: make([]*sharedmemorypb.Batch, len(batches)),
}
for key, value := range requests {
key := key

chainReq := &sharedmemorypb.AtomicRequest{
RemoveRequests: value.RemoveRequests,
PutRequests: make([]*sharedmemorypb.Element, len(value.PutRequests)),
Expand Down
2 changes: 1 addition & 1 deletion config/node/process_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestProcessContext(t *testing.T) {

contextJSON, err := json.MarshalIndent(test.context, "", "\t")
require.NoError(err)
require.Equal(test.expected, string(contextJSON))
require.JSONEq(test.expected, string(contextJSON))
})
}
}
1 change: 0 additions & 1 deletion genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ func splitAllocations(allocations []Allocation, numSplits int) [][]Allocation {
currentAllocation.UnlockSchedule = nil

for _, unlock := range allocation.UnlockSchedule {
unlock := unlock
for currentNodeAmount+unlock.Amount > nodeWeight && len(allNodeAllocations) < numSplits-1 {
amountToAdd := nodeWeight - currentNodeAmount
currentAllocation.UnlockSchedule = append(currentAllocation.UnlockSchedule, LockedAmount{
Expand Down
11 changes: 7 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
module github.com/ava-labs/avalanchego

// Changes to the minimum golang version must also be replicated in
// CONTRIBUTING.md
// README.md
// go.mod (here)
// - Changes to the minimum golang version must also be replicated in:
// - CONTRIBUTING.md
// - README.md
// - go.mod (here)
//
// - If updating between minor versions (e.g. 1.22.x -> 1.23.x):
// - Consider updating the version of golangci-lint (in scripts/lint.sh).
go 1.22.8

require (
Expand Down
1 change: 0 additions & 1 deletion message/inbound_msg_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ func InboundAppResponse(

func encodeIDs(ids []ids.ID, result [][]byte) {
for i, id := range ids {
id := id
result[i] = id[:]
}
}
2 changes: 0 additions & 2 deletions message/inbound_msg_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func TestInboundMsgBuilder(t *testing.T) {
require.Equal(requestID, innerMsg.RequestId)
summaryIDsBytes := make([][]byte, len(summaryIDs))
for i, id := range summaryIDs {
id := id
summaryIDsBytes[i] = id[:]
}
require.Equal(summaryIDsBytes, innerMsg.SummaryIds)
Expand Down Expand Up @@ -244,7 +243,6 @@ func TestInboundMsgBuilder(t *testing.T) {
require.Equal(requestID, innerMsg.RequestId)
containerIDsBytes := make([][]byte, len(containerIDs))
for i, id := range containerIDs {
id := id
containerIDsBytes[i] = id[:]
}
require.Equal(containerIDsBytes, innerMsg.ContainerIds)
Expand Down
8 changes: 0 additions & 8 deletions network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ func newFullyConnectedTestNetwork(t *testing.T, handlers []router.InboundHandler
require.NoError(vdrs.AddStaker(constants.PrimaryNetworkID, nodeID, nil, ids.GenerateTestID(), 1))
}

config := config

config.Beacons = beacons
config.Validators = vdrs

Expand Down Expand Up @@ -461,8 +459,6 @@ func TestTrackDoesNotDialPrivateIPs(t *testing.T) {
require.NoError(vdrs.AddStaker(constants.PrimaryNetworkID, nodeID, nil, ids.GenerateTestID(), 1))
}

config := config

config.Beacons = beacons
config.Validators = vdrs
config.AllowPrivateIPs = false
Expand Down Expand Up @@ -541,8 +537,6 @@ func TestDialDeletesNonValidators(t *testing.T) {
beacons := validators.NewManager()
require.NoError(beacons.AddStaker(constants.PrimaryNetworkID, nodeIDs[0], nil, ids.GenerateTestID(), 1))

config := config

config.Beacons = beacons
config.Validators = vdrs
config.AllowPrivateIPs = false
Expand Down Expand Up @@ -696,8 +690,6 @@ func TestAllowConnectionAsAValidator(t *testing.T) {
vdrs := validators.NewManager()
require.NoError(vdrs.AddStaker(constants.PrimaryNetworkID, nodeIDs[0], nil, ids.GenerateTestID(), 1))

config := config

config.Beacons = beacons
config.Validators = vdrs
config.RequireValidatorToConnect = true
Expand Down
1 change: 0 additions & 1 deletion node/beacon_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func TestBeaconManager_DataRace(t *testing.T) {
})

for _, nodeID := range validatorIDs {
nodeID := nodeID
go func() {
b.Connected(nodeID, version.CurrentApp, constants.PrimaryNetworkID)
b.Connected(nodeID, version.CurrentApp, ids.GenerateTestID())
Expand Down
2 changes: 1 addition & 1 deletion scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fi
TESTS=${TESTS:-"golangci_lint license_header require_error_is_no_funcs_as_params single_import interface_compliance_nil require_no_error_inline_func import_testing_only_in_tests"}

function test_golangci_lint {
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2
golangci-lint run --config .golangci.yml
}

Expand Down
2 changes: 0 additions & 2 deletions snow/engine/avalanche/bootstrap/queue/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ func (s *state) DisableCaching() {

func (s *state) AddMissingJobIDs(missingIDs set.Set[ids.ID]) error {
for missingID := range missingIDs {
missingID := missingID
if err := s.missingJobIDs.Put(missingID[:], nil); err != nil {
return err
}
Expand All @@ -293,7 +292,6 @@ func (s *state) AddMissingJobIDs(missingIDs set.Set[ids.ID]) error {

func (s *state) RemoveMissingJobIDs(missingIDs set.Set[ids.ID]) error {
for missingID := range missingIDs {
missingID := missingID
if err := s.missingJobIDs.Delete(missingID[:]); err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion snow/engine/snowman/voter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func (v *voter) Execute(ctx context.Context, _ []ids.ID, _ []ids.ID) error {
}

for _, result := range results {
result := result
v.e.Ctx.Log.Debug("finishing poll",
zap.Stringer("result", &result),
)
Expand Down
2 changes: 1 addition & 1 deletion tests/fixture/bootstrapmonitor/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func main() {
if len(version.GitCommit) > 0 {
msg += ", commit=" + version.GitCommit
}
fmt.Fprintf(os.Stdout, msg+"\n")
fmt.Fprintln(os.Stdout, msg)
return nil
},
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixture/tmpnet/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func main() {
if len(version.GitCommit) > 0 {
msg += ", commit=" + version.GitCommit
}
fmt.Fprintf(os.Stdout, msg+"\n")
fmt.Fprintln(os.Stdout, msg)
return nil
},
}
Expand Down
2 changes: 1 addition & 1 deletion utils/bimap/bimap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func TestBiMapJSON(t *testing.T) {
require.NoError(err)

expectedJSONBytes := []byte(`{"1":2,"2":3}`)
require.Equal(expectedJSONBytes, jsonBytes)
require.JSONEq(string(expectedJSONBytes), string(jsonBytes))

var unmarshalledMap BiMap[int, int]
require.NoError(json.Unmarshal(jsonBytes, &unmarshalledMap))
Expand Down
2 changes: 1 addition & 1 deletion utils/formatting/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestEncodingMarshalJSON(t *testing.T) {
enc := Hex
jsonBytes, err := enc.MarshalJSON()
require.NoError(err)
require.Equal(`"hex"`, string(jsonBytes))
require.JSONEq(`"hex"`, string(jsonBytes))
}

func TestEncodingUnmarshalJSON(t *testing.T) {
Expand Down
13 changes: 11 additions & 2 deletions utils/hashing/hashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import (
"fmt"
"io"

"golang.org/x/crypto/ripemd160"
// This file generates addresses from public keys with ripemd160. Though ripemd160 is not
// generally recommended for use, the small size of the public key input is considered harder to
// attack than larger payloads.
//
// Bitcoin similarly uses ripemd160 to generate addresses from public keys.
//
// Reference: https://online.tugraz.at/tug_online/voe_main2.getvolltext?pCurrPk=17675
"golang.org/x/crypto/ripemd160" //nolint:gosec
)

const (
Expand Down Expand Up @@ -51,7 +58,9 @@ func ComputeHash160Array(buf []byte) Hash160 {
// ComputeHash160 computes a cryptographically strong 160 bit hash of the input
// byte slice.
func ComputeHash160(buf []byte) []byte {
ripe := ripemd160.New()
// See the comment on the ripemd160 import as to why the risk of use is
// considered acceptable.
ripe := ripemd160.New() //nolint:gosec
_, err := io.Writer(ripe).Write(buf)
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion utils/json/float32_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestFloat32(t *testing.T) {
for _, tt := range tests {
jsonBytes, err := tt.f.MarshalJSON()
require.NoError(err)
require.Equal(fmt.Sprintf(`"%s"`, tt.expectedStr), string(jsonBytes))
require.JSONEq(fmt.Sprintf(`"%s"`, tt.expectedStr), string(jsonBytes))

var f Float32
require.NoError(f.UnmarshalJSON(jsonBytes))
Expand Down
6 changes: 3 additions & 3 deletions utils/set/sampleable_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestSampleableSetMarshalJSON(t *testing.T) {
{
asJSON, err := set.MarshalJSON()
require.NoError(err)
require.Equal("[]", string(asJSON))
require.JSONEq("[]", string(asJSON))
}
id1, id2 := 1, 2
id1JSON, err := json.Marshal(id1)
Expand All @@ -76,13 +76,13 @@ func TestSampleableSetMarshalJSON(t *testing.T) {
{
asJSON, err := set.MarshalJSON()
require.NoError(err)
require.Equal(fmt.Sprintf("[%s]", string(id1JSON)), string(asJSON))
require.JSONEq(fmt.Sprintf("[%s]", string(id1JSON)), string(asJSON))
}
set.Add(id2)
{
asJSON, err := set.MarshalJSON()
require.NoError(err)
require.Equal(fmt.Sprintf("[%s,%s]", string(id1JSON), string(id2JSON)), string(asJSON))
require.JSONEq(fmt.Sprintf("[%s,%s]", string(id1JSON), string(id2JSON)), string(asJSON))
}
}

Expand Down
12 changes: 6 additions & 6 deletions utils/set/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestSetMarshalJSON(t *testing.T) {
{
asJSON, err := set.MarshalJSON()
require.NoError(err)
require.Equal("[]", string(asJSON))
require.JSONEq("[]", string(asJSON))
}
id1, id2 := 1, 2
id1JSON, err := json.Marshal(id1)
Expand All @@ -145,13 +145,13 @@ func TestSetMarshalJSON(t *testing.T) {
{
asJSON, err := set.MarshalJSON()
require.NoError(err)
require.Equal(fmt.Sprintf("[%s]", string(id1JSON)), string(asJSON))
require.JSONEq(fmt.Sprintf("[%s]", string(id1JSON)), string(asJSON))
}
set.Add(id2)
{
asJSON, err := set.MarshalJSON()
require.NoError(err)
require.Equal(fmt.Sprintf("[%s,%s]", string(id1JSON), string(id2JSON)), string(asJSON))
require.JSONEq(fmt.Sprintf("[%s,%s]", string(id1JSON), string(id2JSON)), string(asJSON))
}
}

Expand Down Expand Up @@ -207,7 +207,7 @@ func TestSetReflectJSONMarshal(t *testing.T) {
{
asJSON, err := json.Marshal(set)
require.NoError(err)
require.Equal("[]", string(asJSON))
require.JSONEq("[]", string(asJSON))
}
id1JSON, err := json.Marshal(1)
require.NoError(err)
Expand All @@ -217,12 +217,12 @@ func TestSetReflectJSONMarshal(t *testing.T) {
{
asJSON, err := json.Marshal(set)
require.NoError(err)
require.Equal(fmt.Sprintf("[%s]", string(id1JSON)), string(asJSON))
require.JSONEq(fmt.Sprintf("[%s]", string(id1JSON)), string(asJSON))
}
set.Add(2)
{
asJSON, err := json.Marshal(set)
require.NoError(err)
require.Equal(fmt.Sprintf("[%s,%s]", string(id1JSON), string(id2JSON)), string(asJSON))
require.JSONEq(fmt.Sprintf("[%s,%s]", string(id1JSON), string(id2JSON)), string(asJSON))
}
}
1 change: 0 additions & 1 deletion vms/avm/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ func initTestTxIndex(t *testing.T, db *versiondb.Database, address ids.ShortID,

for i, txID := range testTxs {
idxBytes := database.PackUInt64(uint64(i))
txID := txID
require.NoError(assetPrefixDB.Put(idxBytes, txID[:]))
}
_, err := db.CommitBatch()
Expand Down
4 changes: 2 additions & 2 deletions vms/avm/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3029,7 +3029,7 @@ func TestServiceGetBlock(t *testing.T) {
expectedJSON, err := json.Marshal(expected)
require.NoError(err)

require.Equal(json.RawMessage(expectedJSON), reply.Block)
require.JSONEq(string(expectedJSON), string(reply.Block))
})
}
}
Expand Down Expand Up @@ -3235,7 +3235,7 @@ func TestServiceGetBlockByHeight(t *testing.T) {
expectedJSON, err := json.Marshal(expected)
require.NoError(err)

require.Equal(json.RawMessage(expectedJSON), reply.Block)
require.JSONEq(string(expectedJSON), string(reply.Block))
})
}
}
Expand Down
2 changes: 0 additions & 2 deletions vms/avm/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ func (s *state) writeUTXOs() error {

func (s *state) writeTxs() error {
for txID, tx := range s.addedTxs {
txID := txID
txBytes := tx.Bytes()

delete(s.addedTxs, txID)
Expand All @@ -474,7 +473,6 @@ func (s *state) writeBlockIDs() error {

func (s *state) writeBlocks() error {
for blkID, blk := range s.addedBlocks {
blkID := blkID
blkBytes := blk.Bytes()

delete(s.addedBlocks, blkID)
Expand Down
9 changes: 0 additions & 9 deletions vms/avm/utxo/spender.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ func (s *spender) SpendNFT(
keys := [][]*secp256k1.PrivateKey{}

for _, utxo := range utxos {
// makes sure that the variable isn't overwritten with the next iteration
utxo := utxo

if len(ops) > 0 {
// we have already been able to create the operation needed
break
Expand Down Expand Up @@ -311,9 +308,6 @@ func (s *spender) Mint(
keys := [][]*secp256k1.PrivateKey{}

for _, utxo := range utxos {
// makes sure that the variable isn't overwritten with the next iteration
utxo := utxo

assetID := utxo.AssetID()
amount := amounts[assetID]
if amount == 0 {
Expand Down Expand Up @@ -385,9 +379,6 @@ func (s *spender) MintNFT(
keys := [][]*secp256k1.PrivateKey{}

for _, utxo := range utxos {
// makes sure that the variable isn't overwritten with the next iteration
utxo := utxo

if len(ops) > 0 {
// we have already been able to create the operation needed
break
Expand Down
Loading

0 comments on commit 8fb6237

Please sign in to comment.