From 2d2adb3a2504f42bb56e08ef2b8bacba52c54c86 Mon Sep 17 00:00:00 2001 From: Vlad <13818348+walldiss@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:31:25 +0400 Subject: [PATCH] chore(linter): add 6 more linteres (#3333) Adds linters : - whitespace - protogetter - wastedassign - gocheckcompilerdirectives - loggercheck - bidichk - exportloopref Also fixes found issues by each linter --- .golangci.yml | 7 +++++++ api/docgen/examples.go | 1 - api/docgen/openrpc.go | 10 ++++------ blob/blob.go | 1 - cmd/cel-shed/p2p.go | 4 ++-- das/coordinator_test.go | 1 - nodebuilder/fraud/lifecycle.go | 2 +- share/eds/retriever_no_race_test.go | 2 +- share/getters/shrex_test.go | 2 +- share/p2p/discovery/discovery_test.go | 2 +- share/p2p/peers/timedqueue_test.go | 1 - state/core_access.go | 6 +++--- 12 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 7ebd04f913..ba784a3585 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,6 +3,7 @@ run: linters: enable: + - bidichk - bodyclose # - depguard as of v1.54.2, the default config throws errors on our repo - dogsled @@ -12,6 +13,8 @@ linters: # - funlen # - gochecknoglobals # - gochecknoinits + - exportloopref + - gocheckcompilerdirectives - goconst - gocritic # - gocyclo @@ -27,6 +30,7 @@ linters: - ineffassign # - interfacer - lll + - loggercheck - misspell # - maligned - nakedret @@ -34,6 +38,7 @@ linters: - nilnil - nolintlint - prealloc + - protogetter # - scopelint - deprecated since v1.39. exportloopref will be used instead - exportloopref - staticcheck @@ -45,6 +50,8 @@ linters: # - whitespace # - wsl # - gocognit + - wastedassign + - whitespace - nolintlint - asciicheck diff --git a/api/docgen/examples.go b/api/docgen/examples.go index 83d25da6df..6608df9b94 100644 --- a/api/docgen/examples.go +++ b/api/docgen/examples.go @@ -203,7 +203,6 @@ func ExampleValue(t, parent reflect.Type) (interface{}, error) { case reflect.Interface: return struct{}{}, nil } - return nil, fmt.Errorf("failed to retrieve example value for type: %s on parent '%s')", t, parent) } diff --git a/api/docgen/openrpc.go b/api/docgen/openrpc.go index 4af6b787b1..a5e52e7ee1 100644 --- a/api/docgen/openrpc.go +++ b/api/docgen/openrpc.go @@ -1,7 +1,5 @@ // Package docgen generates an OpenRPC spec for the Celestia Node. It has been inspired by and // adapted from Filecoin's Lotus API implementation. - -//nolint:revive package docgen import ( @@ -163,7 +161,7 @@ func NewOpenRPCDocument(comments, permissions Comments) *go_openrpc_reflect.Docu } // remove the default implementation from the method descriptions - appReflector.FnGetMethodDescription = func(r reflect.Value, m reflect.Method, funcDecl *ast.FuncDecl) (string, error) { + appReflector.FnGetMethodDescription = func(_ reflect.Value, m reflect.Method, _ *ast.FuncDecl) (string, error) { if v, ok := permissions[m.Name]; ok { return "Auth level: " + v, nil } @@ -172,14 +170,14 @@ func NewOpenRPCDocument(comments, permissions Comments) *go_openrpc_reflect.Docu appReflector.FnGetMethodName = func( moduleName string, - r reflect.Value, + _ reflect.Value, m reflect.Method, - funcDecl *ast.FuncDecl, + _ *ast.FuncDecl, ) (string, error) { return moduleName + "." + m.Name, nil } - appReflector.FnGetMethodSummary = func(r reflect.Value, m reflect.Method, funcDecl *ast.FuncDecl) (string, error) { + appReflector.FnGetMethodSummary = func(_ reflect.Value, m reflect.Method, _ *ast.FuncDecl) (string, error) { if v, ok := comments[extractPackageNameFromAPIMethod(m)+m.Name]; ok { return v, nil } diff --git a/blob/blob.go b/blob/blob.go index c81d83070e..8ff7c39eec 100644 --- a/blob/blob.go +++ b/blob/blob.go @@ -62,7 +62,6 @@ func (p Proof) equal(input Proof) error { if !bytes.Equal(proof.LeafHash(), input[i].LeafHash()) { return ErrInvalidProof } - } return nil } diff --git a/cmd/cel-shed/p2p.go b/cmd/cel-shed/p2p.go index d4a6c4b596..957582c8bc 100644 --- a/cmd/cel-shed/p2p.go +++ b/cmd/cel-shed/p2p.go @@ -22,7 +22,7 @@ var p2pCmd = &cobra.Command{ var p2pNewKeyCmd = &cobra.Command{ Use: "new-key", Short: "Generate and print new Ed25519 private key for p2p networking", - RunE: func(cmd *cobra.Command, _ []string) error { //nolint:revive + RunE: func(_ *cobra.Command, _ []string) error { privkey, _, err := crypto.GenerateEd25519Key(rand.Reader) if err != nil { return err @@ -42,7 +42,7 @@ var p2pNewKeyCmd = &cobra.Command{ var p2pPeerIDCmd = &cobra.Command{ Use: "peer-id", Short: "Get peer-id out of public or private Ed25519 key", - RunE: func(cmd *cobra.Command, args []string) error { //nolint:revive + RunE: func(_ *cobra.Command, args []string) error { decKey, err := hex.DecodeString(args[0]) if err != nil { return err diff --git a/das/coordinator_test.go b/das/coordinator_test.go index 1ae54c470f..18e707ba0d 100644 --- a/das/coordinator_test.go +++ b/das/coordinator_test.go @@ -470,7 +470,6 @@ func (o *checkOrder) addInterval(start, end uint64) *checkOrder { return o } start-- - } return o } diff --git a/nodebuilder/fraud/lifecycle.go b/nodebuilder/fraud/lifecycle.go index 43118784da..13fcddbd9d 100644 --- a/nodebuilder/fraud/lifecycle.go +++ b/nodebuilder/fraud/lifecycle.go @@ -84,6 +84,6 @@ func (breaker *ServiceBreaker[S, H]) awaitProof() { } if err := breaker.Stop(breaker.ctx); err != nil && !errors.Is(err, context.Canceled) { - log.Errorw("stopping service: %s", err.Error()) + log.Errorw("stopping service", "err", err.Error()) } } diff --git a/share/eds/retriever_no_race_test.go b/share/eds/retriever_no_race_test.go index 15c6aa2fc4..6b2667ee6f 100644 --- a/share/eds/retriever_no_race_test.go +++ b/share/eds/retriever_no_race_test.go @@ -1,4 +1,4 @@ -// go:build !race +//go:build !race package eds diff --git a/share/getters/shrex_test.go b/share/getters/shrex_test.go index 075735579b..74896e6c15 100644 --- a/share/getters/shrex_test.go +++ b/share/getters/shrex_test.go @@ -285,7 +285,7 @@ func addToNamespace(namespace share.Namespace, val int) (share.Namespace, error) // Perform addition byte by byte var carry int for i := len(namespace) - 1; i >= 0; i-- { - sum := 0 + var sum int if val > 0 { sum = int(namespace[i]) + int(result[i]) + carry } else { diff --git a/share/p2p/discovery/discovery_test.go b/share/p2p/discovery/discovery_test.go index 1d0078196f..8214a2bbe0 100644 --- a/share/p2p/discovery/discovery_test.go +++ b/share/p2p/discovery/discovery_test.go @@ -1,4 +1,4 @@ -// go:build !race +//go:build !race package discovery diff --git a/share/p2p/peers/timedqueue_test.go b/share/p2p/peers/timedqueue_test.go index fb5ef9629f..9cfae0e6b2 100644 --- a/share/p2p/peers/timedqueue_test.go +++ b/share/p2p/peers/timedqueue_test.go @@ -45,7 +45,6 @@ func TestTimedQueue(t *testing.T) { case <-popCh: case <-time.After(ttl): t.Fatal("first item is not released") - } require.Equal(t, queue.len(), 1) diff --git a/state/core_access.go b/state/core_access.go index 9493a0501a..cc5baab740 100644 --- a/state/core_access.go +++ b/state/core_access.go @@ -342,10 +342,10 @@ func (ca *CoreAccessor) BalanceForAddress(ctx context.Context, addr Address) (*B Prove: true, } opts := rpcclient.ABCIQueryOptions{ - Height: abciReq.Height, - Prove: abciReq.Prove, + Height: abciReq.GetHeight(), + Prove: abciReq.GetProve(), } - result, err := ca.rpcCli.ABCIQueryWithOptions(ctx, abciReq.Path, abciReq.Data, opts) + result, err := ca.rpcCli.ABCIQueryWithOptions(ctx, abciReq.GetPath(), abciReq.GetData(), opts) if err != nil { return nil, err }