Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Jan 23, 2025
1 parent 45bcad7 commit 9b8ca7c
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 37 deletions.
11 changes: 7 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
run:
tests: true
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m

linters:
disable-all: true
enable:
- dogsled
- errcheck
- exportloopref
- goconst
- gocritic
- gofumpt
Expand All @@ -30,14 +28,19 @@ linters:
issues:
max-issues-per-linter: 10000
max-same-issues: 10000
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- gosec

linters-settings:
gofumpt:
# Choose whether to use the extra rules.
# Default: false
extra-rules: true

nolintlint:
allow-unused: true
allow-leading-space: true
require-explanation: false
require-specific: false

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ test-sim-multi-seed-short: runsim
###############################################################################

lint:
golangci-lint run --skip-files ".*.pb.go"
golangci-lint run
find . -name '*.go' -not -name "*.pb.go" -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofmt -d -s

format:
@go install mvdan.cc/gofumpt@latest
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -path "./tests/mocks/*" -not -name "*.pb.go" -not -name "*.pb.gw.go" -not -name "*.pulsar.go" -not -path "./crypto/keys/secp256k1/*" | xargs -I % sh -c 'gofumpt -w -l % && goimports -w -local github.com/neutron-org %'
golangci-lint run --fix --skip-files ".*.pb.go"
golangci-lint run --fix

.PHONY: format

Expand Down
2 changes: 1 addition & 1 deletion wasmbinding/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (m *CustomMessenger) dispatchDexMsg(ctx sdk.Context, contractAddr sdk.AccAd
msg.OrderType = dextypes.LimitOrderType(orderTypeInt)

if dex.PlaceLimitOrder.ExpirationTime != nil {
t := time.Unix(int64(*(dex.PlaceLimitOrder.ExpirationTime)), 0)
t := time.Unix(int64(*(dex.PlaceLimitOrder.ExpirationTime)), 0) //nolint:gosec
msg.ExpirationTime = &t
}

Expand Down
6 changes: 3 additions & 3 deletions wasmbinding/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (qp *QueryPlugin) DexQuery(ctx sdk.Context, query bindings.DexQuery) (data
}
q.OrderType = dextypes.LimitOrderType(orderTypeInt)
if query.EstimatePlaceLimitOrder.ExpirationTime != nil {
t := time.Unix(int64(*query.EstimatePlaceLimitOrder.ExpirationTime), 0)
t := time.Unix(int64(*query.EstimatePlaceLimitOrder.ExpirationTime), 0) //nolint:gosec
q.ExpirationTime = &t
}
data, err = dexQuery(ctx, &q, qp.dexKeeper.EstimatePlaceLimitOrder)
Expand Down Expand Up @@ -239,7 +239,7 @@ func (qp *QueryPlugin) MarketMapQuery(ctx sdk.Context, query bindings.MarketMapQ
func dexQuery[T, R any](ctx sdk.Context, query *T, queryHandler func(ctx context.Context, query *T) (R, error)) ([]byte, error) {
resp, err := queryHandler(ctx, query)
if err != nil {
return nil, errors.Wrapf(err, fmt.Sprintf("failed to query request %T", query))
return nil, errors.Wrap(err, fmt.Sprintf("failed to query request %T", query))
}
var data []byte

Expand All @@ -250,7 +250,7 @@ func dexQuery[T, R any](ctx sdk.Context, query *T, queryHandler func(ctx context
}

if err != nil {
return nil, errors.Wrapf(err, fmt.Sprintf("failed to marshal response %T", resp))
return nil, errors.Wrap(err, fmt.Sprintf("failed to marshal response %T", resp))
}

return data, nil
Expand Down
9 changes: 5 additions & 4 deletions x/cron/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ func (k *Keeper) AddSchedule(
Name: name,
Period: period,
Msgs: msgs,
LastExecuteHeight: uint64(ctx.BlockHeight()), // let's execute newly added schedule on `now + period` block
ExecutionStage: executionStage,
LastExecuteHeight: uint64(ctx.BlockHeight()), //nolint:gosec
// let's execute newly added schedule on `now + period` block
ExecutionStage: executionStage,
}

k.storeSchedule(ctx, schedule)
Expand Down Expand Up @@ -181,7 +182,7 @@ func (k *Keeper) getSchedulesReadyForExecution(ctx sdk.Context, executionStage t
func (k *Keeper) executeSchedule(ctx sdk.Context, schedule types.Schedule) error {
// Even if contract execution returned an error, we still increase the height
// and execute it after this interval
schedule.LastExecuteHeight = uint64(ctx.BlockHeight())
schedule.LastExecuteHeight = uint64(ctx.BlockHeight()) //nolint:gosec
k.storeSchedule(ctx, schedule)

cacheCtx, writeFn := ctx.CacheContext()
Expand Down Expand Up @@ -230,7 +231,7 @@ func (k *Keeper) scheduleExists(ctx sdk.Context, name string) bool {
}

func (k *Keeper) intervalPassed(ctx sdk.Context, schedule types.Schedule) bool {
return uint64(ctx.BlockHeight()) > (schedule.LastExecuteHeight + schedule.Period)
return uint64(ctx.BlockHeight()) > (schedule.LastExecuteHeight + schedule.Period) //nolint:gosec
}

func (k *Keeper) changeTotalCount(ctx sdk.Context, incrementAmount int32) {
Expand Down
2 changes: 1 addition & 1 deletion x/dex/client/cli/tx_place_limit_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func CmdPlaceLimitOrder() *cobra.Command {
const timeFormat = "01/02/2006 15:04:05"
tm, err := time.Parse(timeFormat, args[6])
if err != nil {
return sdkerrors.Wrapf(types.ErrInvalidTimeString, err.Error())
return sdkerrors.Wrap(types.ErrInvalidTimeString, err.Error())
}
goodTil = &tm
}
Expand Down
2 changes: 1 addition & 1 deletion x/dex/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (k Keeper) ExecuteDeposit(
if option.FailTxOnBel {
return nil, nil, math.ZeroInt(), math.ZeroInt(), nil, nil, nil, err
}
failedDeposits = append(failedDeposits, &types.FailedDeposit{DepositIdx: uint64(i), Error: err.Error()})
failedDeposits = append(failedDeposits, &types.FailedDeposit{DepositIdx: uint64(i), Error: err.Error()}) //nolint:gosec
continue
}

Expand Down
2 changes: 1 addition & 1 deletion x/dex/keeper/limit_order_tranche.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func NewTrancheKey(ctx sdk.Context) string {
blockGas := utils.MustGetBlockGasUsed(ctx)
totalGas := blockGas + txGas

blockStr := utils.Uint64ToSortableString(uint64(blockHeight))
blockStr := utils.Uint64ToSortableString(uint64(blockHeight)) //nolint:gosec
gasStr := utils.Uint64ToSortableString(totalGas)

return fmt.Sprintf("%s%s", blockStr, gasStr)
Expand Down
10 changes: 5 additions & 5 deletions x/dex/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ func KeyPrefix(p string) []byte {
func TickIndexToBytes(tickTakerToMaker int64) []byte {
key := make([]byte, 9)
if tickTakerToMaker < 0 {
copy(key[1:], sdk.Uint64ToBigEndian(uint64(tickTakerToMaker)))
copy(key[1:], sdk.Uint64ToBigEndian(uint64(tickTakerToMaker))) //nolint:gosec
} else {
copy(key[:1], []byte{0x01})
copy(key[1:], sdk.Uint64ToBigEndian(uint64(tickTakerToMaker)))
copy(key[1:], sdk.Uint64ToBigEndian(uint64(tickTakerToMaker))) //nolint:gosec
}

return key
Expand All @@ -85,10 +85,10 @@ func BytesToTickIndex(bz []byte) (int64, error) {
tickTakerToMaker := sdk.BigEndianToUint64(bz[1:])

if isNegative {
return int64(-tickTakerToMaker), nil
return int64(-tickTakerToMaker), nil //nolint:gosec
}
// else
return int64(tickTakerToMaker), nil
return int64(tickTakerToMaker), nil //nolint:gosec
}

// LimitOrderTrancheUserKey returns the store key to retrieve a LimitOrderTrancheUser from the index fields
Expand Down Expand Up @@ -119,7 +119,7 @@ func TimeBytes(timestamp time.Time) []byte {
var unixSecs uint64
// If timestamp is 0 use that instead of returning long negative number for unix time
if !timestamp.IsZero() {
unixSecs = uint64(timestamp.Unix())
unixSecs = uint64(timestamp.Unix()) //nolint:gosec
}

str := utils.Uint64ToSortableString(unixSecs)
Expand Down
2 changes: 1 addition & 1 deletion x/dex/types/pair_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewPairIDFromCanonicalString(pairIDStr string) (*PairID, error) {
return NewPairID(tokens[0], tokens[1])
}

return &PairID{}, sdkerrors.Wrapf(ErrInvalidPairIDStr, pairIDStr)
return &PairID{}, sdkerrors.Wrap(ErrInvalidPairIDStr, pairIDStr)
}

func SortTokens(tokenA, tokenB string) (string, string) {
Expand Down
4 changes: 2 additions & 2 deletions x/dex/types/price.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ func CalcTickIndexFromPrice(price math_utils.PrecDec) (int64, error) {
invPrice := math_utils.OnePrecDec().Quo(price)
tick := BinarySearchPriceToTick(invPrice)
// flip the sign back the other direction
return int64(tick) * -1, nil
return int64(tick) * -1, nil //nolint:gosec
}

tick := BinarySearchPriceToTick(price)

return int64(tick), nil
return int64(tick), nil //nolint:gosec
}

func MustCalcPrice(relativeTickIndex int64) math_utils.PrecDec {
Expand Down
2 changes: 1 addition & 1 deletion x/dex/types/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (t LimitOrderTranche) ToBinding() LimitOrderTrancheBinding {
LimitOrderTranche: t,
}
if t.ExpirationTime != nil && t.ExpirationTime.Unix() >= 0 {
ut := uint64(t.ExpirationTime.Unix())
ut := uint64(t.ExpirationTime.Unix()) //nolint:gosec
lo.ExpirationTime = &ut
}
return lo
Expand Down
2 changes: 1 addition & 1 deletion x/dex/utils/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Uint64ToSortableString(i uint64) string {
}

func SafeUint64ToInt64(in uint64) (out int64, overflow bool) {
return int64(in), in > math.MaxInt64
return int64(in), in > math.MaxInt64 //nolint:gosec
}

func MustSafeUint64ToInt64(in uint64) (out int64) {
Expand Down
4 changes: 2 additions & 2 deletions x/globalfee/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (mfd FeeDecorator) GetTxFeeRequired(ctx sdk.Context, tx sdk.FeeTx) (sdk.Coi
// to form the tx fee requirements

// Get local minimum-gas-prices
localFees := GetMinGasPrice(ctx, int64(tx.GetGas()))
localFees := GetMinGasPrice(ctx, int64(tx.GetGas())) //nolint:gosec
c, err := CombinedFeeRequirement(globalFees, localFees)

// Return combined fee requirements
Expand All @@ -180,7 +180,7 @@ func (mfd FeeDecorator) GetGlobalFee(ctx sdk.Context, feeTx sdk.FeeTx) sdk.Coins
requiredGlobalFees := make(sdk.Coins, len(globalMinGasPrices))
// Determine the required fees by multiplying each required minimum gas
// price by the gas limit, where fee = ceil(minGasPrice * gasLimit).
glDec := math.LegacyNewDec(int64(feeTx.GetGas()))
glDec := math.LegacyNewDec(int64(feeTx.GetGas())) //nolint:gosec
for i, gp := range globalMinGasPrices {
fee := gp.Amount.Mul(glDec)
requiredGlobalFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt())
Expand Down
2 changes: 1 addition & 1 deletion x/interchainqueries/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (k Keeper) saveKVQueryResult(ctx sdk.Context, query *types.RegisteredQuery,
store.Set(types.GetRegisteredQueryResultByIDKey(query.Id), bz)

k.updateLastRemoteHeight(ctx, query, ibcclienttypes.NewHeight(result.Revision, result.Height))
k.updateLastLocalHeight(ctx, query, uint64(ctx.BlockHeight()))
k.updateLastLocalHeight(ctx, query, uint64(ctx.BlockHeight())) //nolint:gosec
if err := k.SaveQuery(ctx, query); err != nil {
return errors.Wrapf(err, "failed to save query %d: %v", query.Id, err)
}
Expand Down
4 changes: 2 additions & 2 deletions x/interchainqueries/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (m msgServer) RegisterInterchainQuery(goCtx context.Context, msg *types.Msg
ConnectionId: msg.ConnectionId,
Deposit: params.QueryDeposit,
SubmitTimeout: params.QuerySubmitTimeout,
RegisteredAtHeight: uint64(ctx.BlockHeader().Height),
RegisteredAtHeight: uint64(ctx.BlockHeader().Height), //nolint:gosec
}

m.SetLastRegisteredQueryKey(ctx, lastID)
Expand Down Expand Up @@ -303,7 +303,7 @@ func (m msgServer) SubmitQueryResult(goCtx context.Context, msg *types.MsgSubmit
return nil, errors.Wrapf(err, "failed to ProcessBlock: %v", err)
}

if err = m.UpdateLastLocalHeight(ctx, query.Id, uint64(ctx.BlockHeight())); err != nil {
if err = m.UpdateLastLocalHeight(ctx, query.Id, uint64(ctx.BlockHeight())); err != nil { //nolint:gosec
return nil, errors.Wrapf(err,
"failed to update last local height for a result with id %d: %v", query.Id, err)
}
Expand Down
2 changes: 1 addition & 1 deletion x/interchainqueries/keeper/process_block_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (k Keeper) ProcessBlock(ctx sdk.Context, queryOwner sdk.AccAddress, queryID
}

// Let the query owner contract process the query result.
if _, err := k.contractManagerKeeper.SudoTxQueryResult(ctx, queryOwner, queryID, ibcclienttypes.NewHeight(tmHeader.TrustedHeight.GetRevisionNumber(), uint64(tmHeader.Header.Height)), txData); err != nil {
if _, err := k.contractManagerKeeper.SudoTxQueryResult(ctx, queryOwner, queryID, ibcclienttypes.NewHeight(tmHeader.TrustedHeight.GetRevisionNumber(), uint64(tmHeader.Header.Height)), txData); err != nil { //nolint:gosec
ctx.Logger().Debug("ProcessBlock: failed to SudoTxQueryResult",
"error", err, "query_id", queryID, "tx_hash", hex.EncodeToString(txHash))
return errors.Wrapf(err, "contract %s rejected transaction query result (tx_hash: %s)",
Expand Down
2 changes: 1 addition & 1 deletion x/interchainqueries/types/registered_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (q *RegisteredQuery) ValidateRemoval(ctx sdk.Context, caller string) error

registrationTimeoutBlock := q.RegisteredAtHeight + q.SubmitTimeout
submitTimeoutBlock := q.LastSubmittedResultLocalHeight + q.SubmitTimeout
currentBlock := uint64(ctx.BlockHeader().Height)
currentBlock := uint64(ctx.BlockHeader().Height) //nolint:gosec
if currentBlock <= registrationTimeoutBlock || currentBlock <= submitTimeoutBlock {
return fmt.Errorf("only owner can remove a query within its service period")
}
Expand Down
2 changes: 1 addition & 1 deletion x/interchaintxs/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (k Keeper) SubmitTx(goCtx context.Context, msg *ictxtypes.MsgSubmitTx) (*ic
Owner: icaOwner,
ConnectionId: msg.ConnectionId,
PacketData: packetData,
RelativeTimeout: uint64(time.Duration(msg.Timeout) * time.Second),
RelativeTimeout: uint64(time.Duration(msg.Timeout) * time.Second), //nolint:gosec
})
if err != nil {
// usually we use DEBUG level for such errors, but in this case we have checked full input before running SendTX, so error here may be critical
Expand Down
4 changes: 2 additions & 2 deletions x/tokenfactory/keeper/before_send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (suite *KeeperTestSuite) TestBeforeSendHook() {
},
{
desc: "sending 1 of non-factorydenom should not error",
msg: func(factorydenom string) *banktypes.MsgSend {
msg: func(_ string) *banktypes.MsgSend {
return banktypes.NewMsgSend(
suite.TestAccs[0],
suite.TestAccs[1],
Expand All @@ -102,7 +102,7 @@ func (suite *KeeperTestSuite) TestBeforeSendHook() {
},
{
desc: "sending 100 of non-factorydenom should work",
msg: func(factorydenom string) *banktypes.MsgSend {
msg: func(_ string) *banktypes.MsgSend {
return banktypes.NewMsgSend(
suite.TestAccs[0],
suite.TestAccs[1],
Expand Down

0 comments on commit 9b8ca7c

Please sign in to comment.