Skip to content

Commit

Permalink
Switch to revive and fix findings (#171)
Browse files Browse the repository at this point in the history
* [ci] Switch from `nosnakecase` to `revive`

* [revive] Fix findings

Signed-off-by: Julian Strobl <[email protected]>
  • Loading branch information
jmastr authored Nov 13, 2023
1 parent c8bfb86 commit 1e1138d
Show file tree
Hide file tree
Showing 34 changed files with 62 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ linters:
- gosimple
- govet
- ineffassign
- nosnakecase
- revive
- staticcheck
- unused
issues:
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/machine/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testutil/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions util/validate_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion x/asset/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion x/asset/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
3 changes: 2 additions & 1 deletion x/asset/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"

// this line is used by starport scaffolding # 1

"github.com/grpc-ecosystem/grpc-gateway/runtime"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/asset/module_simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions x/asset/simulation/notarize_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions x/dao/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion x/dao/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions x/dao/client/cli/tx_reissue_rddl_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,7 +34,7 @@ func CmdReissueRDDLResult() *cobra.Command {
msg := types.NewMsgReissueRDDLResult(
clientCtx.GetFromAddress().String(),
argProposer,
argTxId,
argTxID,
argBlockHeight,
)
if err := msg.ValidateBasic(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/dao/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
3 changes: 1 addition & 2 deletions x/dao/keeper/query_get_reissuances.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
2 changes: 1 addition & 1 deletion x/dao/keeper/reissuance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/dao/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/dao/module_simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions x/dao/simulation/mint_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions x/dao/simulation/reissue_rddl_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions x/dao/simulation/reissue_rddl_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions x/dao/types/message_reissue_rddl_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
4 changes: 2 additions & 2 deletions x/dao/util.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion x/machine/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions x/machine/keeper/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions x/machine/keeper/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions x/machine/keeper/msg_server_attest_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion x/machine/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
3 changes: 1 addition & 2 deletions x/machine/keeper/trust_anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 1e1138d

Please sign in to comment.