From 359cbbc5d9fa5f8ca9207d0d52c95add37af5b99 Mon Sep 17 00:00:00 2001 From: Julian Strobl Date: Fri, 14 Jul 2023 09:22:34 +0200 Subject: [PATCH] [lint] Switch to golangci-lint and fix errors Signed-off-by: Julian Strobl --- .github/workflows/audit.yaml | 9 ++++----- app/export.go | 2 ++ cmd/planetmint-god/cmd/root.go | 1 + docs/docs.go | 1 + tests/e2e/asset/rest.go | 2 +- tests/e2e/machine/rest.go | 2 +- testutil/rest.go | 5 ++++- x/asset/module.go | 1 + x/machine/keeper/machine.go | 16 ++++++++++++---- x/machine/module.go | 1 + 10 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.github/workflows/audit.yaml b/.github/workflows/audit.yaml index 8b6960e..30d77c9 100644 --- a/.github/workflows/audit.yaml +++ b/.github/workflows/audit.yaml @@ -33,12 +33,11 @@ jobs: - name: Run staticcheck run: staticcheck ./... - - name: Install golint - run: go install golang.org/x/lint/golint@latest + - name: Install golangci-lint + run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest - - name: Run golint - run: golint -set_exit_status ./... - continue-on-error: true + - name: Run golangci-lint + run: golangci-lint run --timeout 5m - name: Run tests run: go test -race -vet=off ./... diff --git a/app/export.go b/app/export.go index a2bbef7..647f93f 100644 --- a/app/export.go +++ b/app/export.go @@ -77,6 +77,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str // withdraw all delegator rewards dels := app.StakingKeeper.GetAllDelegations(ctx) + //nolint:errcheck app.withdrawAllDelegatorRewards(ctx, dels) // clear validator slash events @@ -93,6 +94,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str app.reinitializeAllValidators(ctx) // reinitialize all delegations + //nolint:errcheck app.reinitializeAllDelegations(ctx, dels) // reset context height diff --git a/cmd/planetmint-god/cmd/root.go b/cmd/planetmint-god/cmd/root.go index d8ca3e1..6a12df5 100644 --- a/cmd/planetmint-god/cmd/root.go +++ b/cmd/planetmint-god/cmd/root.go @@ -208,6 +208,7 @@ func overwriteFlagDefaults(c *cobra.Command, defaults map[string]string) { set := func(s *pflag.FlagSet, key, val string) { if f := s.Lookup(key); f != nil { f.DefValue = val + //nolint:errcheck f.Value.Set(val) } } diff --git a/docs/docs.go b/docs/docs.go index 1ba96c7..0641983 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -29,6 +29,7 @@ func handler(title string) http.HandlerFunc { t, _ := httptemplate.ParseFS(template, indexFile) return func(w http.ResponseWriter, req *http.Request) { + //nolint:errcheck t.Execute(w, struct { Title string URL string diff --git a/tests/e2e/asset/rest.go b/tests/e2e/asset/rest.go index b1f6231..2d236db 100644 --- a/tests/e2e/asset/rest.go +++ b/tests/e2e/asset/rest.go @@ -74,7 +74,7 @@ func (s *E2ETestSuite) TestNotarizeAssetREST() { broadcastTxResponse, err := testutil.BroadcastTx(val, txBytes) s.Require().NoError(err) - s.network.WaitForNextBlock() + s.Require().NoError(s.network.WaitForNextBlock()) tx, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", val.APIAddress, broadcastTxResponse.TxResponse.TxHash)) s.Require().NoError(err) diff --git a/tests/e2e/machine/rest.go b/tests/e2e/machine/rest.go index df6caad..f06b8fe 100644 --- a/tests/e2e/machine/rest.go +++ b/tests/e2e/machine/rest.go @@ -33,7 +33,7 @@ func (s *E2ETestSuite) TestAttestMachineREST() { broadcastTxResponse, err := testutil.BroadcastTx(val, txBytes) s.Require().NoError(err) - s.network.WaitForNextBlock() + s.Require().NoError(s.network.WaitForNextBlock()) tx, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", val.APIAddress, broadcastTxResponse.TxResponse.TxHash)) s.Require().NoError(err) diff --git a/testutil/rest.go b/testutil/rest.go index 31bdd65..ee26e8d 100644 --- a/testutil/rest.go +++ b/testutil/rest.go @@ -80,7 +80,10 @@ func PrepareTx(val *network.Validator, msg sdk.Msg, signer string) ([]byte, erro } txBuilder := val.ClientCtx.TxConfig.NewTxBuilder() - txBuilder.SetMsgs(msg) + err = txBuilder.SetMsgs(msg) + if err != nil { + return nil, err + } txBuilder.SetGasLimit(200000) txBuilder.SetFeeAmount(sdk.Coins{sdk.NewInt64Coin("stake", 2)}) txBuilder.SetTimeoutHeight(0) diff --git a/x/asset/module.go b/x/asset/module.go index 39485ce..6bbec2c 100644 --- a/x/asset/module.go +++ b/x/asset/module.go @@ -70,6 +70,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + //nolint:errcheck types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) } diff --git a/x/machine/keeper/machine.go b/x/machine/keeper/machine.go index 193f425..8626eb2 100644 --- a/x/machine/keeper/machine.go +++ b/x/machine/keeper/machine.go @@ -20,7 +20,9 @@ func (k Keeper) GetMachine(ctx sdk.Context, index types.MachineIndex) (val types if machine == nil { return val, false } - k.cdc.Unmarshal(machine, &val) + if err := k.cdc.Unmarshal(machine, &val); err != nil { + return val, false + } return val, true } @@ -53,19 +55,25 @@ func (k Keeper) GetMachineIndex(ctx sdk.Context, pubKey string) (val types.Machi taIndex := taIndexStore.Get(keyBytes) if taIndex != nil { - k.cdc.Unmarshal(taIndex, &val) + if err := k.cdc.Unmarshal(taIndex, &val); err != nil { + return val, false + } return val, true } ipIndex := issuerPlanetmintIndexStore.Get(keyBytes) if ipIndex != nil { - k.cdc.Unmarshal(ipIndex, &val) + if err := k.cdc.Unmarshal(ipIndex, &val); err != nil { + return val, false + } return val, true } ilIndex := issuerLiquidIndexStore.Get(keyBytes) if ilIndex != nil { - k.cdc.Unmarshal(ilIndex, &val) + if err := k.cdc.Unmarshal(ilIndex, &val); err != nil { + return val, false + } return val, true } diff --git a/x/machine/module.go b/x/machine/module.go index 8a2e9b9..5789e6f 100644 --- a/x/machine/module.go +++ b/x/machine/module.go @@ -70,6 +70,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + //nolint:errcheck types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) }