Switch to revive and fix findings (#171)

* [ci] Switch from `nosnakecase` to `revive`

* [revive] Fix findings

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
Julian Strobl 2023-11-13 12:42:52 +01:00 committed by GitHub
parent c8bfb861f1
commit 1e1138d026
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 62 additions and 63 deletions

View File

@ -8,7 +8,7 @@ linters:
- gosimple
- govet
- ineffassign
- nosnakecase
- revive
- staticcheck
- unused
issues:

View File

@ -909,7 +909,7 @@ func (app *App) GetSubspace(moduleName string) paramstypes.Subspace {
// RegisterAPIRoutes registers all application module routes with the provided
// API server.
func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
func (app *App) RegisterAPIRoutes(apiSvr *api.Server, _ config.APIConfig) {
clientCtx := apiSvr.ClientCtx
// Register new tx routes from grpc-gateway.
authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

View File

@ -39,7 +39,7 @@ import (
"github.com/planetmint/planetmint-go/app"
)
const SIMULATION_SETUP_FAILED = "simulation setup failed"
const SimulationSetupFailed = "simulation setup failed"
type storeKeysPrefixes struct {
A storetypes.StoreKey
@ -78,7 +78,7 @@ func BenchmarkSimulation(b *testing.B) {
simcli.FlagVerboseValue,
simcli.FlagEnabledValue,
)
require.NoError(b, err, SIMULATION_SETUP_FAILED)
require.NoError(b, err, SimulationSetupFailed)
b.Cleanup(func() {
require.NoError(b, db.Close())
@ -232,7 +232,7 @@ func TestAppImportExport(t *testing.T) {
if skip {
t.Skip("skipping application import/export simulation")
}
require.NoError(t, err, SIMULATION_SETUP_FAILED)
require.NoError(t, err, SimulationSetupFailed)
defer func() {
require.NoError(t, db.Close())
@ -297,7 +297,7 @@ func TestAppImportExport(t *testing.T) {
simcli.FlagVerboseValue,
simcli.FlagEnabledValue,
)
require.NoError(t, err, SIMULATION_SETUP_FAILED)
require.NoError(t, err, SimulationSetupFailed)
defer func() {
require.NoError(t, newDB.Close())
@ -386,7 +386,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
if skip {
t.Skip("skipping application simulation after import")
}
require.NoError(t, err, SIMULATION_SETUP_FAILED)
require.NoError(t, err, SimulationSetupFailed)
defer func() {
require.NoError(t, db.Close())
@ -457,7 +457,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
simcli.FlagVerboseValue,
simcli.FlagEnabledValue,
)
require.NoError(t, err, SIMULATION_SETUP_FAILED)
require.NoError(t, err, SimulationSetupFailed)
defer func() {
require.NoError(t, newDB.Close())

View File

@ -59,8 +59,8 @@ func (s *E2ETestSuite) TestAttestMachineREST() {
s.Require().NoError(err)
s.Require().Equal(uint32(0), txRes.TxResponse.Code)
queryMachineUrl := fmt.Sprintf("%s/planetmint/machine/get_machine_by_public_key/%s", baseURL, pubKey)
queryMachineRes, err := testutil.GetRequest(queryMachineUrl)
queryMachineURL := fmt.Sprintf("%s/planetmint/machine/get_machine_by_public_key/%s", baseURL, pubKey)
queryMachineRes, err := testutil.GetRequest(queryMachineURL)
s.Require().NoError(err)
var qmRes machinetypes.QueryGetMachineByPublicKeyResponse

View File

@ -142,7 +142,7 @@ func PrepareTx(val *network.Validator, msg sdk.Msg, signer string) ([]byte, erro
}
func BroadcastTx(val *network.Validator, txBytes []byte) (*txtypes.BroadcastTxResponse, error) {
broadcastTxUrl := fmt.Sprintf("%s/cosmos/tx/v1beta1/txs", val.APIAddress)
broadcastTxURL := fmt.Sprintf("%s/cosmos/tx/v1beta1/txs", val.APIAddress)
req := txtypes.BroadcastTxRequest{
TxBytes: txBytes,
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
@ -152,7 +152,7 @@ func BroadcastTx(val *network.Validator, txBytes []byte) (*txtypes.BroadcastTxRe
if err != nil {
return nil, err
}
broadCastTxResponse, err := PostRequest(broadcastTxUrl, "application/json", broadCastTxBody)
broadCastTxResponse, err := PostRequest(broadcastTxURL, "application/json", broadCastTxBody)
if err != nil {
return nil, err
}

View File

@ -35,9 +35,8 @@ func ValidateSignatureByteMsg(message []byte, signature string, publicKey string
isValid := pubKey.VerifySignature(message, signatureBytes)
if !isValid {
return false, errors.New("invalid signature")
} else {
return isValid, nil
}
return isValid, nil
}
func GetHexPubKey(extPubKey string) (string, error) {

View File

@ -14,7 +14,7 @@ import (
)
// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
func GetQueryCmd(_ string) *cobra.Command {
// Group asset queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,

View File

@ -6,7 +6,7 @@ import (
)
// GetParams get all parameters as types.Params
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
func (k Keeper) GetParams(_ sdk.Context) types.Params {
return types.NewParams()
}

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
// this line is used by starport scaffolding # 1
"github.com/grpc-ecosystem/grpc-gateway/runtime"
@ -60,7 +61,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
}
// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
var genState types.GenesisState
if err := cdc.UnmarshalJSON(bz, &genState); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)

View File

@ -74,7 +74,7 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
}
// ProposalMsgs returns msgs used for governance proposals for simulations.
func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg {
func (am AppModule) ProposalMsgs(_ module.SimulationState) []simtypes.WeightedProposalMsg {
return []simtypes.WeightedProposalMsg{
simulation.NewWeightedProposalMsg(
opWeightMsgNotarizeAsset,

View File

@ -11,9 +11,9 @@ import (
)
func SimulateMsgNotarizeAsset(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
_ types.AccountKeeper,
_ types.BankKeeper,
_ keeper.Keeper,
) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {

View File

@ -11,7 +11,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, _ keeper.Keeper) {
logger := ctx.Logger()
proposerAddress := req.Header.GetProposerAddress()
@ -36,6 +36,6 @@ func isPoPHeight(height int64) bool {
return height%int64(cfg.PoPEpochs) == 0
}
func EndBlocker(ctx sdk.Context, req abci.RequestEndBlock, k keeper.Keeper) {
func EndBlocker(ctx sdk.Context, _ abci.RequestEndBlock, k keeper.Keeper) {
k.DistributeCollectedFees(ctx)
}

View File

@ -11,7 +11,7 @@ import (
)
// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
func GetQueryCmd(_ string) *cobra.Command {
// Group dao queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,

View File

@ -20,7 +20,7 @@ func CmdReissueRDDLResult() *cobra.Command {
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argProposer := args[0]
argTxId := args[1]
argTxID := args[1]
argBlockHeight, err := cast.ToInt64E(args[2])
if err != nil {
return err
@ -34,7 +34,7 @@ func CmdReissueRDDLResult() *cobra.Command {
msg := types.NewMsgReissueRDDLResult(
clientCtx.GetFromAddress().String(),
argProposer,
argTxId,
argTxID,
argBlockHeight,
)
if err := msg.ValidateBasic(); err != nil {

View File

@ -6,7 +6,7 @@ import (
)
// GetParams get all parameters as types.Params
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
func (k Keeper) GetParams(_ sdk.Context) types.Params {
return types.NewParams()
}

View File

@ -22,8 +22,7 @@ func (k Keeper) GetReissuances(goCtx context.Context, req *types.QueryGetReissua
if reissuances != nil {
return &types.QueryGetReissuancesResponse{Reissuance: &reissuances[0]}, nil
} else {
return &types.QueryGetReissuancesResponse{}, nil
}
return &types.QueryGetReissuancesResponse{}, nil
}

View File

@ -24,7 +24,7 @@ func (k Keeper) LookupReissuance(ctx sdk.Context, height int64) (val types.Reiss
return val, true
}
func (k Keeper) getReissuancesPage(ctx sdk.Context, key []byte, offset uint64, pageSize uint64, all bool, reverse bool) (reissuances []types.Reissuance) {
func (k Keeper) getReissuancesPage(ctx sdk.Context, _ []byte, _ uint64, _ uint64, _ bool, reverse bool) (reissuances []types.Reissuance) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ReissuanceBlockHeightKey))
iterator := store.Iterator(nil, nil)

View File

@ -62,7 +62,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
}
// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
var genState types.GenesisState
if err := cdc.UnmarshalJSON(bz, &genState); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)

View File

@ -88,7 +88,7 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
}
// ProposalMsgs returns msgs used for governance proposals for simulations.
func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg {
func (am AppModule) ProposalMsgs(_ module.SimulationState) []simtypes.WeightedProposalMsg {
return []simtypes.WeightedProposalMsg{
simulation.NewWeightedProposalMsg(
opWeightMsgReissueRDDLProposal,

View File

@ -11,9 +11,9 @@ import (
)
func SimulateMsgMintToken(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
_ types.AccountKeeper,
_ types.BankKeeper,
_ keeper.Keeper,
) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {

View File

@ -11,9 +11,9 @@ import (
)
func SimulateMsgReissueRDDLProposal(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
_ types.AccountKeeper,
_ types.BankKeeper,
_ keeper.Keeper,
) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {

View File

@ -11,9 +11,9 @@ import (
)
func SimulateMsgReissueRDDLResult(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
_ types.AccountKeeper,
_ types.BankKeeper,
_ keeper.Keeper,
) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {

View File

@ -10,11 +10,11 @@ const TypeMsgReissueRDDLResult = "reissue_rddl_result"
var _ sdk.Msg = &MsgReissueRDDLResult{}
func NewMsgReissueRDDLResult(creator string, proposer string, txId string, blockHeight int64) *MsgReissueRDDLResult {
func NewMsgReissueRDDLResult(creator string, proposer string, txID string, blockHeight int64) *MsgReissueRDDLResult {
return &MsgReissueRDDLResult{
Creator: creator,
Proposer: proposer,
TxId: txId,
TxId: txID,
BlockHeight: blockHeight,
}
}

View File

@ -1,10 +1,10 @@
package dao
func GetReissuanceCommand(assetID string, BlockHeight int64) string {
func GetReissuanceCommand(assetID string, _ int64) string {
return "reissueasset " + assetID + " 99869000000"
}
func IsValidReissuanceCommand(reissuanceStr string, assetID string, BlockHeight int64) bool {
func IsValidReissuanceCommand(reissuanceStr string, assetID string, _ int64) bool {
expected := "reissueasset " + assetID + " 99869000000"
return reissuanceStr == expected
}

View File

@ -14,7 +14,7 @@ import (
)
// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
func GetQueryCmd(_ string) *cobra.Command {
// Group machine queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,

View File

@ -39,13 +39,13 @@ func (k Keeper) StoreMachineIndex(ctx sdk.Context, machine types.Machine) {
Address: machine.Address,
}
machineIdIndexKey := GetMachineBytes(machine.MachineId)
machineIDIndexKey := GetMachineBytes(machine.MachineId)
issuerPlanetmintIndexKey := GetMachineBytes(machine.IssuerPlanetmint)
issuerLiquidIndexKey := GetMachineBytes(machine.IssuerLiquid)
addressIndexKey := GetMachineBytes(machine.Address)
indexAppendValue := k.cdc.MustMarshal(&index)
taIndexStore.Set(machineIdIndexKey, indexAppendValue)
taIndexStore.Set(machineIDIndexKey, indexAppendValue)
issuerPlanetmintIndexStore.Set(issuerPlanetmintIndexKey, indexAppendValue)
issuerLiquidIndexStore.Set(issuerLiquidIndexKey, indexAppendValue)
addressIndexStore.Set(addressIndexKey, indexAppendValue)

View File

@ -35,9 +35,9 @@ func TestGetMachine(t *testing.T) {
IssuerLiquid: item.IssuerLiquid,
Address: item.Address,
}
machineById, found := keeper.GetMachine(ctx, index)
machineByID, found := keeper.GetMachine(ctx, index)
assert.True(t, found)
assert.Equal(t, item, machineById)
assert.Equal(t, item, machineByID)
}
}

View File

@ -30,8 +30,8 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
// and removed from here due to inconsistency or checking the same thing over and over again.
ta, _, _ := k.GetTrustAnchor(ctx, msg.Machine.MachineId)
isValidMachineId, err := util.ValidateSignature(msg.Machine.MachineId, msg.Machine.MachineIdSignature, msg.Machine.MachineId)
if !isValidMachineId {
isValidMachineID, err := util.ValidateSignature(msg.Machine.MachineId, msg.Machine.MachineIdSignature, msg.Machine.MachineId)
if !isValidMachineID {
return nil, err
}

View File

@ -6,7 +6,7 @@ import (
)
// GetParams get all parameters as types.Params
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
func (k Keeper) GetParams(_ sdk.Context) types.Params {
return types.NewParams()
}

View File

@ -43,9 +43,8 @@ func (k Keeper) GetTrustAnchor(ctx sdk.Context, pubKey string) (val types.TrustA
val.Pubkey = pubKey
if trustAnchorActivated[0] == 1 {
return val, true, true
} else {
return val, false, true
}
return val, false, true
}
func getTrustAnchorBytes(pubKey string) ([]byte, error) {

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
// this line is used by starport scaffolding # 1
"github.com/grpc-ecosystem/grpc-gateway/runtime"
@ -60,7 +61,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
}
// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
var genState types.GenesisState
if err := cdc.UnmarshalJSON(bz, &genState); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)

View File

@ -89,7 +89,7 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
}
// ProposalMsgs returns msgs used for governance proposals for simulations.
func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg {
func (am AppModule) ProposalMsgs(_ module.SimulationState) []simtypes.WeightedProposalMsg {
return []simtypes.WeightedProposalMsg{
simulation.NewWeightedProposalMsg(
opWeightMsgAttestMachine,

View File

@ -11,9 +11,9 @@ import (
)
func SimulateMsgAttestMachine(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
_ types.AccountKeeper,
_ types.BankKeeper,
_ keeper.Keeper,
) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {

View File

@ -11,9 +11,9 @@ import (
)
func SimulateMsgRegisterTrustAnchor(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
_ types.AccountKeeper,
_ types.BankKeeper,
_ keeper.Keeper,
) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {