Skip to content

Commit

Permalink
.golangci.yml: add intrange linter
Browse files Browse the repository at this point in the history
It checks that go 1.22's range-over-numbers feature is not skipped. Also,
fix some warnings it found.

Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Sep 3, 2024
1 parent d47fe39 commit b9b75f5
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ linters:
- decorder
- durationcheck
- errorlint
- intrange
- copyloopvar
- gofmt
- misspell
Expand Down
2 changes: 1 addition & 1 deletion internal/testchain/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func Sign(h hash.Hashable) []byte {
// SignCommittee signs data by a majority of committee members.
func SignCommittee(h hash.Hashable) []byte {
buf := io.NewBufBinWriter()
for i := 0; i < CommitteeSize()/2+1; i++ {
for i := range CommitteeSize()/2 + 1 {
pKey := PrivateKey(i)
sig := pKey.SignHashable(uint32(Network()), h)
if len(sig) != 64 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/blockchain_core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestRemoveOldTransfers(t *testing.T) {
require.NoError(t, err)
require.NotEqual(t, 0, len(log.Raw))

for i := uint32(0); i < 3; i++ {
for i := range uint32(3) {
log, err = bc.dao.GetTokenTransferLog(acc2, newer, i, false)
require.NoError(t, err)
require.NotEqual(t, 0, len(log.Raw))
Expand All @@ -130,7 +130,7 @@ func TestRemoveOldTransfers(t *testing.T) {
require.NoError(t, err)
require.NotEqual(t, 0, len(log.Raw))

for i := uint32(0); i < 2; i++ {
for i := range uint32(2) {
log, err = bc.dao.GetTokenTransferLog(acc3, newer, i, true)
require.NoError(t, err)
require.NotEqual(t, 0, len(log.Raw))
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/mpt/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func lcp(a, b []byte) []byte {
}

var i int
for i = 0; i < len(b); i++ {
for i = range len(b) {
if a[i] != b[i] {
break
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/native/native_test/neo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ func TestNEO_GetCandidates(t *testing.T) {
for i := range len(expected) + 1 {
w := io.NewBufBinWriter()
emit.AppCall(w.BinWriter, neoCommitteeInvoker.Hash, "getAllCandidates", callflag.All)
for j := 0; j < i+1; j++ {
for range i + 1 {
emit.Opcodes(w.BinWriter, opcode.DUP)
emit.Syscall(w.BinWriter, interopnames.SystemIteratorNext)
emit.Opcodes(w.BinWriter, opcode.DROP) // drop the value returned from Next.
Expand Down
2 changes: 1 addition & 1 deletion pkg/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1860,7 +1860,7 @@ func (v *VM) ContractHasTryBlock() bool {
if ictx.sc != topctx.sc {
return false // Different contract -> no one cares.
}
for j := 0; j < ictx.tryStack.Len(); j++ {
for j := range ictx.tryStack.Len() {
eCtx := ictx.tryStack.Peek(j).Value().(*exceptionHandlingContext)
if eCtx.State == eTry {
return true
Expand Down

0 comments on commit b9b75f5

Please sign in to comment.