From d36df15878f0734efb8b242f47eedc984f0a1915 Mon Sep 17 00:00:00 2001 From: ZhangTao1596 Date: Wed, 29 Mar 2023 11:19:23 +0800 Subject: [PATCH] ci: fix lint issues (fix #2948) --- .golangci.yml | 4 ++++ internal/contracts/oracle_contract/go.mod | 2 +- pkg/core/dao/dao.go | 3 ++- pkg/core/interop/storage/find.go | 2 +- pkg/core/native/management.go | 2 +- pkg/core/native/native_neo.go | 2 +- pkg/network/tcp_peer_test.go | 3 ++- pkg/rpcclient/actor/doc_test.go | 2 +- pkg/rpcclient/invoker/doc_test.go | 12 +++++++----- pkg/smartcontract/doc_test.go | 6 +++--- 10 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index b79417f01..8c7a48623 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -69,3 +69,7 @@ issues: - EXC0003 # test/Test ... consider calling this - EXC0004 # govet - EXC0005 # C-style breaks + exclude-rules: + - linters: + - revive + text: "unused-parameter" diff --git a/internal/contracts/oracle_contract/go.mod b/internal/contracts/oracle_contract/go.mod index fea68d385..4bc15dd05 100644 --- a/internal/contracts/oracle_contract/go.mod +++ b/internal/contracts/oracle_contract/go.mod @@ -1,4 +1,4 @@ -module github.com/nspcc-dev/neo-go/examples/oracle +module github.com/nspcc-dev/neo-go/internal/examples/oracle go 1.17 diff --git a/pkg/core/dao/dao.go b/pkg/core/dao/dao.go index 54a9cd85a..ae3862eee 100644 --- a/pkg/core/dao/dao.go +++ b/pkg/core/dao/dao.go @@ -457,7 +457,8 @@ func (v *Version) FromBytes(data []byte) error { return errors.New("missing version") } i := 0 - for ; i < len(data) && data[i] != '\x00'; i++ { + for i < len(data) && data[i] != '\x00' { + i++ } if i == len(data) { diff --git a/pkg/core/interop/storage/find.go b/pkg/core/interop/storage/find.go index 62a59b688..9d2f96668 100644 --- a/pkg/core/interop/storage/find.go +++ b/pkg/core/interop/storage/find.go @@ -120,7 +120,7 @@ func Find(ic *interop.Context) error { // Underlying persistent store is likely to be a private MemCachedStore. Thus, // to avoid concurrent map iteration and map write we need to wait until internal // seek goroutine is finished, because it can access underlying persistent store. - for range seekres { + for range seekres { //nolint:revive //empty-block } }) diff --git a/pkg/core/native/management.go b/pkg/core/native/management.go index c56159398..a5bc83d6c 100644 --- a/pkg/core/native/management.go +++ b/pkg/core/native/management.go @@ -282,7 +282,7 @@ func (m *Management) getContractHashes(ic *interop.Context, _ []stackitem.Item) item := istorage.NewIterator(filteredRes, prefix, int64(opts)) ic.RegisterCancelFunc(func() { cancel() - for range seekres { + for range seekres { //nolint:revive //empty-block } }) return stackitem.NewInterop(item) diff --git a/pkg/core/native/native_neo.go b/pkg/core/native/native_neo.go index 756f308ef..b0b8b1f1e 100644 --- a/pkg/core/native/native_neo.go +++ b/pkg/core/native/native_neo.go @@ -1022,7 +1022,7 @@ func (n *NEO) getAllCandidatesCall(ic *interop.Context, _ []stackitem.Item) stac item := istorage.NewIterator(filteredRes, prefix, int64(opts)) ic.RegisterCancelFunc(func() { cancel() - for range seekres { + for range seekres { //nolint:revive //empty-block } }) return stackitem.NewInterop(item) diff --git a/pkg/network/tcp_peer_test.go b/pkg/network/tcp_peer_test.go index 7e03f84bb..993459177 100644 --- a/pkg/network/tcp_peer_test.go +++ b/pkg/network/tcp_peer_test.go @@ -11,7 +11,8 @@ import ( func connReadStub(conn net.Conn) { b := make([]byte, 1024) var err error - for ; err == nil; _, err = conn.Read(b) { + for err == nil { + _, err = conn.Read(b) } } diff --git a/pkg/rpcclient/actor/doc_test.go b/pkg/rpcclient/actor/doc_test.go index a1297b2bc..71035603f 100644 --- a/pkg/rpcclient/actor/doc_test.go +++ b/pkg/rpcclient/actor/doc_test.go @@ -33,7 +33,7 @@ func ExampleActor() { // have a signer with the first wallet account and CalledByEntry scope. res, _ := a.Call(customContract, "method", 1, 2, 3) if res.State != vmstate.Halt.String() { - // The call failed. + panic("failed") } // All of the side-effects in res can be analyzed. diff --git a/pkg/rpcclient/invoker/doc_test.go b/pkg/rpcclient/invoker/doc_test.go index fe01b9490..882f35a65 100644 --- a/pkg/rpcclient/invoker/doc_test.go +++ b/pkg/rpcclient/invoker/doc_test.go @@ -33,9 +33,9 @@ func ExampleInvoker() { // Test-invoke transfer call. res, _ := inv.Call(neo.Hash, "transfer", acc, util.Uint160{1, 2, 3}, 1, nil) if res.State == vmstate.Halt.String() { - // NEO is broken! inv has no signers and transfer requires a witness to be performed. + panic("NEO is broken!") // inv has no signers and transfer requires a witness to be performed. } else { - // OK, this actually should fail. + println("ok") // this actually should fail } // A historic invoker with no signers at block 1000000. @@ -57,9 +57,11 @@ func ExampleInvoker() { // transfer actually returns a value, so check it too. ok, _ := unwrap.Bool(res, nil) if ok { - // OK, as expected. res.Script contains the corresponding - // script and res.GasConsumed has an appropriate system fee - // required for a transaction. + // OK, as expected. + // res.Script contains the corresponding script. + _ = res.Script + // res.GasConsumed has an appropriate system fee required for a transaction. + _ = res.GasConsumed } } diff --git a/pkg/smartcontract/doc_test.go b/pkg/smartcontract/doc_test.go index 39c76dbfb..fe54126be 100644 --- a/pkg/smartcontract/doc_test.go +++ b/pkg/smartcontract/doc_test.go @@ -34,17 +34,17 @@ func ExampleBuilder() { // Actor has an Invoker inside, so we can perform test invocation using the script. res, _ := a.Run(script) if res.State != "HALT" || len(res.Stack) != 2 { - // The script failed completely or didn't return proper number of return values. + panic("failed") // The script failed completely or didn't return proper number of return values. } transferResult, _ := res.Stack[0].TryBool() voteResult, _ := res.Stack[1].TryBool() if !transferResult { - // Transfer failed. + panic("transfer failed") } if !voteResult { - // Vote failed. + panic("vote failed") } b.Reset() // Copy the old script above if you need it!