Skip to content

Commit

Permalink
chore: fix lint errors (#1649)
Browse files Browse the repository at this point in the history
* ++

* ++

* more unused params

* ++

* ++

* ++

* ++

* ++

* clean up remaining, minus one found bug

* ++

* add unused param linter - which caught a bug
  • Loading branch information
toteki authored Dec 8, 2022
1 parent 36f103f commit 514380a
Show file tree
Hide file tree
Showing 43 changed files with 93 additions and 126 deletions.
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ linters-settings:
- name: error-naming
- name: errorf
- name: exported
# - name: if-return
- name: if-return
- name: increment-decrement
- name: indent-error-flow
- name: range
# - name: receiver-naming
- name: receiver-naming
# - name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: unreachable-code
# - name: unused-parameter
- name: unused-parameter
- name: var-declaration
# - name: var-naming
- name: var-naming
4 changes: 2 additions & 2 deletions .revive.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ confidence = 0

# https://github.com/mgechev/revive#configuration

# Recommended configuration, minus [rule.exported] and [rule.package-comments]
# Recommended configuration, minus what's commented out
[rule.blank-imports]
[rule.context-as-argument]
[rule.context-keys-type]
Expand All @@ -24,7 +24,7 @@ confidence = 0
#[rule.package-comments]
[rule.range]
[rule.receiver-naming]
[rule.redefines-builtin-id]
#[rule.redefines-builtin-id]
[rule.superfluous-else]
[rule.time-naming]
[rule.unexported-return]
Expand Down
2 changes: 1 addition & 1 deletion ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type IntegrationTestSuite struct {
}

func (s *IntegrationTestSuite) SetupTest() {
app := umeeapp.Setup(s.T(), false, 1)
app := umeeapp.Setup(s.T())
ctx := app.BaseApp.NewContext(false, tmproto.Header{
ChainID: fmt.Sprintf("test-chain-%s", tmrand.Str(4)),
Height: 1,
Expand Down
4 changes: 2 additions & 2 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ var DefaultConsensusParams = &abci.ConsensusParams{

type EmptyAppOptions struct{}

func (EmptyAppOptions) Get(o string) interface{} { return nil }
func (EmptyAppOptions) Get(string) interface{} { return nil }

func Setup(t *testing.T, isCheckTx bool, invCheckPeriod uint) *UmeeApp {
func Setup(t *testing.T) *UmeeApp {
t.Helper()

privVal := mock.NewPV()
Expand Down
7 changes: 5 additions & 2 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import (
oracletypes "github.com/umee-network/umee/v3/x/oracle/types"
)

func (app UmeeApp) RegisterUpgradeHandlers(experimental bool) {
// RegisterUpgradeHandlersregisters upgrade handlers.
// It takes a boolean parameter to enable or disable experimental features.
func (app UmeeApp) RegisterUpgradeHandlers(bool) {
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
Expand Down Expand Up @@ -125,7 +127,8 @@ func (app *UmeeApp) registerUpgrade3_0(upgradeInfo upgradetypes.Plan) {

oracletypes.ModuleName,
leveragetypes.ModuleName,
}})
},
})
}

func onlyModuleMigrations(app *UmeeApp, planName string) upgradetypes.UpgradeHandler {
Expand Down
12 changes: 6 additions & 6 deletions app/upgradev3/staking_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type MockStakingKeeper struct {
}

// GetValidator implements StakingKeeper
func (m *MockStakingKeeper) GetValidator(ctx sdk.Context, addr sdk.ValAddress) (types.Validator, bool) {
func (m *MockStakingKeeper) GetValidator(_ sdk.Context, addr sdk.ValAddress) (types.Validator, bool) {
var (
validator types.Validator
found bool
Expand All @@ -36,27 +36,27 @@ func (m *MockStakingKeeper) GetValidator(ctx sdk.Context, addr sdk.ValAddress) (
}

// BeforeValidatorModified implements StakingKeeper
func (*MockStakingKeeper) BeforeValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress) error {
func (*MockStakingKeeper) BeforeValidatorModified(sdk.Context, sdk.ValAddress) error {
return nil
}

// GetAllValidators implements StakingKeeper
func (m *MockStakingKeeper) GetAllValidators(ctx sdk.Context) (validators []types.Validator) {
func (m *MockStakingKeeper) GetAllValidators(sdk.Context) (validators []types.Validator) {
return m.validators
}

// GetParams implements StakingKeeper
func (m *MockStakingKeeper) GetParams(ctx sdk.Context) types.Params {
func (m *MockStakingKeeper) GetParams(sdk.Context) types.Params {
return m.params
}

// SetParams implements StakingKeeper
func (m *MockStakingKeeper) SetParams(ctx sdk.Context, params types.Params) {
func (m *MockStakingKeeper) SetParams(_ sdk.Context, params types.Params) {
m.params = params
}

// SetValidator implements StakingKeeper
func (m *MockStakingKeeper) SetValidator(ctx sdk.Context, validator types.Validator) {
func (m *MockStakingKeeper) SetValidator(_ sdk.Context, validator types.Validator) {
for index, v := range m.validators {
if v.GetOperator().Equals(validator.GetOperator()) {
m.validators[index] = validator
Expand Down
2 changes: 1 addition & 1 deletion price-feeder/oracle/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
)

func dialerFunc(ctx context.Context, addr string) (net.Conn, error) {
func dialerFunc(_ context.Context, addr string) (net.Conn, error) {
return Connect(addr)
}

Expand Down
2 changes: 1 addition & 1 deletion price-feeder/oracle/provider/binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (p *BinanceProvider) getCandlePrices(key string) ([]types.CandlePrice, erro
return candleList, nil
}

func (p *BinanceProvider) messageReceived(messageType int, bz []byte) {
func (p *BinanceProvider) messageReceived(_ int, bz []byte) {
var (
tickerResp BinanceTicker
tickerErr error
Expand Down
2 changes: 1 addition & 1 deletion price-feeder/oracle/provider/bitget.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (p *BitgetProvider) GetCandlePrices(pairs ...types.CurrencyPair) (map[strin
}

// messageReceived handles the received data from the Bitget websocket.
func (p *BitgetProvider) messageReceived(messageType int, bz []byte) {
func (p *BitgetProvider) messageReceived(_ int, bz []byte) {
var (
tickerResp BitgetTicker
tickerErr error
Expand Down
8 changes: 4 additions & 4 deletions price-feeder/oracle/provider/bitget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ func TestBitgetProvider_GetTickerPrices(t *testing.T) {
t.Run("valid_request_single_ticker", func(t *testing.T) {
lastPrice := "34.69000000"
volume := "2396974.02000000"
instId := "ATOMUSDT"
instID := "ATOMUSDT"

tickerMap := map[string]BitgetTicker{}
tickerMap[instId] = BitgetTicker{
tickerMap[instID] = BitgetTicker{
Arg: BitgetSubscriptionArg{
Channel: "tickers",
InstID: instId,
InstID: instID,
},
Data: []BitgetTickerData{
{
InstID: instId,
InstID: instID,
Price: lastPrice,
Volume: volume,
},
Expand Down
2 changes: 1 addition & 1 deletion price-feeder/oracle/provider/coinbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (p *CoinbaseProvider) getTradePrices(key string) ([]CoinbaseTrade, error) {
return trades, nil
}

func (p *CoinbaseProvider) messageReceived(messageType int, bz []byte) {
func (p *CoinbaseProvider) messageReceived(_ int, bz []byte) {
var coinbaseTrade CoinbaseTradeResponse
if err := json.Unmarshal(bz, &coinbaseTrade); err != nil {
p.logger.Error().Err(err).Msg("unable to unmarshal response")
Expand Down
3 changes: 1 addition & 2 deletions price-feeder/oracle/provider/gate.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (p *GateProvider) getTickerPrice(cp types.CurrencyPair) (types.TickerPrice,
return types.TickerPrice{}, fmt.Errorf("gate failed to get ticker price for %s", gp)
}

func (p *GateProvider) messageReceived(messageType int, bz []byte) {
func (p *GateProvider) messageReceived(_ int, bz []byte) {
var (
gateEvent GateEvent
gateErr error
Expand All @@ -262,7 +262,6 @@ func (p *GateProvider) messageReceived(messageType int, bz []byte) {
case "success":
return
case "":
break
default:
return
}
Expand Down
2 changes: 1 addition & 1 deletion price-feeder/oracle/provider/mexc.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (p *MexcProvider) getCandlePrices(key string) ([]types.CandlePrice, error)
return candleList, nil
}

func (p *MexcProvider) messageReceived(messageType int, bz []byte) {
func (p *MexcProvider) messageReceived(_ int, bz []byte) {
var (
tickerResp MexcTickerResponse
tickerErr error
Expand Down
2 changes: 1 addition & 1 deletion price-feeder/oracle/provider/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewMockProvider() *MockProvider {
}

// SubscribeCurrencyPairs performs a no-op since mock does not use websockets
func (p MockProvider) SubscribeCurrencyPairs(pairs ...types.CurrencyPair) error {
func (p MockProvider) SubscribeCurrencyPairs(...types.CurrencyPair) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion price-feeder/oracle/provider/okx.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (p *OkxProvider) getCandlePrices(cp types.CurrencyPair) ([]types.CandlePric
return candleList, nil
}

func (p *OkxProvider) messageReceived(messageType int, bz []byte) {
func (p *OkxProvider) messageReceived(_ int, bz []byte) {
var (
tickerResp OkxTickerResponse
tickerErr error
Expand Down
2 changes: 1 addition & 1 deletion price-feeder/oracle/provider/osmosis.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func NewOsmosisProvider(endpoint Endpoint) *OsmosisProvider {
}

// SubscribeCurrencyPairs performs a no-op since osmosis does not use websockets
func (p OsmosisProvider) SubscribeCurrencyPairs(pairs ...types.CurrencyPair) error {
func (OsmosisProvider) SubscribeCurrencyPairs(...types.CurrencyPair) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion price-feeder/oracle/provider/osmosisv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (p *OsmosisV2Provider) getCandlePrices(key string) ([]types.CandlePrice, er
return candleList, nil
}

func (p *OsmosisV2Provider) messageReceived(messageType int, bz []byte) {
func (p *OsmosisV2Provider) messageReceived(_ int, bz []byte) {
// check if message is an ack first
if string(bz) == "ack" {
return
Expand Down
2 changes: 1 addition & 1 deletion price-feeder/oracle/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (n Name) String() string {

// preventRedirect avoid any redirect in the http.Client the request call
// will not return an error, but a valid response with redirect response code.
func preventRedirect(_ *http.Request, _ []*http.Request) error {
func preventRedirect(*http.Request, []*http.Request) error {
return http.ErrUseLastResponse
}

Expand Down
2 changes: 1 addition & 1 deletion price-feeder/oracle/provider/websocket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (wsc *WebsocketController) reconnect() {

// pingHandler is called by the websocket library whenever a ping message is received
// and responds with a pong message to the server
func (wsc *WebsocketController) pingHandler(appData string) error {
func (wsc *WebsocketController) pingHandler(string) error {
if err := wsc.client.WriteMessage(websocket.PongMessage, []byte("pong")); err != nil {
wsc.logger.Error().Err(err).Msg("error sending pong")
}
Expand Down
2 changes: 1 addition & 1 deletion price-feeder/oracle/provider/websocket_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type TestProvider struct {
handlerCalled bool
}

func (mp *TestProvider) messageHandler(messageType int, bz []byte) {
func (mp *TestProvider) messageHandler(int, []byte) {
mp.handlerCalled = true
}

Expand Down
2 changes: 1 addition & 1 deletion x/leverage/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
)

// GetQueryCmd returns the CLI query commands for the x/leverage module.
func GetQueryCmd(queryRoute string) *cobra.Command {
func GetQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
Expand Down
5 changes: 1 addition & 4 deletions x/leverage/keeper/borrows.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ func (k Keeper) setBorrow(ctx sdk.Context, borrowerAddr sdk.AccAddress, borrow s
newAdjustedAmount := toDec(borrow.Amount).Quo(k.getInterestScalar(ctx, borrow.Denom))

// Set new borrow value
if err := k.setAdjustedBorrow(ctx, borrowerAddr, sdk.NewDecCoinFromDec(borrow.Denom, newAdjustedAmount)); err != nil {
return err
}
return nil
return k.setAdjustedBorrow(ctx, borrowerAddr, sdk.NewDecCoinFromDec(borrow.Denom, newAdjustedAmount))
}

// GetTotalBorrowed returns the total borrowed in a given denom.
Expand Down
15 changes: 0 additions & 15 deletions x/leverage/keeper/iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,6 @@ func (k Keeper) GetBorrowerCollateral(ctx sdk.Context, borrowerAddr sdk.AccAddre
return totalCollateral
}

// HasCollateral returns true if a borrower has any collateral.
func (k Keeper) HasCollateral(ctx sdk.Context, borrowerAddr sdk.AccAddress) bool {
iter := sdk.KVStorePrefixIterator(
ctx.KVStore(k.storeKey),
types.KeyPrefixCollateralAmount,
)
defer iter.Close()

for ; iter.Valid(); iter.Next() {
// Stored collateral amounts are never zero, so this is enough
return true
}
return false
}

// GetEligibleLiquidationTargets returns a list of borrower addresses eligible for liquidation.
func (k Keeper) GetEligibleLiquidationTargets(ctx sdk.Context) ([]sdk.AccAddress, error) {
prefix := types.KeyPrefixAdjustedBorrow
Expand Down
4 changes: 2 additions & 2 deletions x/leverage/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,13 @@ func (s msgServer) GovUpdateRegistry(
}

// update the token settings
err := s.keeper.SaveOrUpdateTokenSettingsToRegistry(ctx, msg.Authority, msg.UpdateTokens, registeredTokenDenoms, true)
err := s.keeper.SaveOrUpdateTokenSettingsToRegistry(ctx, msg.UpdateTokens, registeredTokenDenoms, true)
if err != nil {
return &types.MsgGovUpdateRegistryResponse{}, err
}

// adds the new token settings
err = s.keeper.SaveOrUpdateTokenSettingsToRegistry(ctx, msg.Authority, msg.AddTokens, registeredTokenDenoms, false)
err = s.keeper.SaveOrUpdateTokenSettingsToRegistry(ctx, msg.AddTokens, registeredTokenDenoms, false)
if err != nil {
return &types.MsgGovUpdateRegistryResponse{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion x/leverage/keeper/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestKeeperTestSuite(t *testing.T) {

func (s *IntegrationTestSuite) SetupTest() {
require := s.Require()
app := umeeapp.Setup(s.T(), false, 1)
app := umeeapp.Setup(s.T())
ctx := app.BaseApp.NewContext(false, tmproto.Header{
ChainID: fmt.Sprintf("test-chain-%s", tmrand.Str(4)),
Height: 1,
Expand Down
2 changes: 1 addition & 1 deletion x/leverage/keeper/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (k Keeper) GetTokenSettings(ctx sdk.Context, denom string) (types.Token, er

// SaveOrUpdateTokenSettingsToRegistry adds new tokens or updates the new tokens settings to registry.
func (k Keeper) SaveOrUpdateTokenSettingsToRegistry(
ctx sdk.Context, authority string, tokens []types.Token, registeredTokenDenoms map[string]bool, update bool,
ctx sdk.Context, tokens []types.Token, registeredTokenDenoms map[string]bool, update bool,
) error {
for _, token := range tokens {
if err := token.Validate(); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions x/leverage/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
// ValidateGenesis performs genesis state validation for the x/leverage module.
func (AppModuleBasic) ValidateGenesis(
cdc codec.JSONCodec,
config client.TxEncodingConfig,
_ client.TxEncodingConfig,
bz json.RawMessage,
) error {
var genState types.GenesisState
Expand Down Expand Up @@ -95,7 +95,7 @@ func (a AppModuleBasic) GetTxCmd() *cobra.Command {

// GetQueryCmd returns the x/leverage module's root query command.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd(types.StoreKey)
return cli.GetQueryCmd()
}

// AppModule implements the AppModule interface for the x/leverage module.
Expand Down Expand Up @@ -134,7 +134,7 @@ func (am AppModule) Route() sdk.Route {
func (AppModule) QuerierRoute() string { return types.QuerierRoute }

// LegacyQuerierHandler returns a no-op legacy querier.
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier {
return func(sdk.Context, []string, abci.RequestQuery) ([]byte, error) {
return nil, fmt.Errorf("legacy querier not supported for the x/%s module", types.ModuleName)
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// BeginBlock executes all ABCI BeginBlock logic respective to the x/leverage module.
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
func (am AppModule) BeginBlock(sdk.Context, abci.RequestBeginBlock) {}

// EndBlock executes all ABCI EndBlock logic respective to the x/leverage module.
// It returns no validator updates.
Expand Down
Loading

0 comments on commit 514380a

Please sign in to comment.