Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[testing] Update golangci-lint to latest version #3617

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exportloopref was reported as deprecated, and this was the suggested replacement.

- depguard
- dupword
- errcheck
- errorlint
- exportloopref
- forbidigo
- gci
- goconst
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
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):
// - Maybe update the version of golangci-lint (in scripts/lint.sh) in case the new golang version requires an updated linter?
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 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))
})
}
}
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
5 changes: 3 additions & 2 deletions utils/hashing/hashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"fmt"
"io"

"golang.org/x/crypto/ripemd160"
// TODO(marun) Can this be replaced?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the story behind the usage of this algorithm? Can it be replaced? If not, any suggestions for what justification to document in a comment above the import?

"golang.org/x/crypto/ripemd160" //nolint:gosec
)

const (
Expand Down Expand Up @@ -51,7 +52,7 @@ 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()
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(json.RawMessage(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(json.RawMessage(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
4 changes: 2 additions & 2 deletions vms/platformvm/block/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestBanffProposalBlockJSON(t *testing.T) {
simpleBanffProposalBlockBytes, err := json.MarshalIndent(simpleBanffProposalBlock, "", "\t")
require.NoError(err)

require.Equal(`{
require.JSONEq(`{
"time": 123456,
"txs": null,
"parentID": "rVcYrvnGXdoJBeYQRm5ZNaCGHeVyqcHHJu8Yd89kJcef6V5Eg",
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestBanffProposalBlockJSON(t *testing.T) {
complexBanffProposalBlockBytes, err := json.MarshalIndent(complexBanffProposalBlock, "", "\t")
require.NoError(err)

require.Equal(`{
require.JSONEq(`{
"time": 123456,
"txs": [
{
Expand Down
Loading
Loading