Skip to content

Commit

Permalink
more lint
Browse files Browse the repository at this point in the history
  • Loading branch information
puneet2019 committed Jan 12, 2024
1 parent 7021b52 commit c32d746
Show file tree
Hide file tree
Showing 20 changed files with 117 additions and 43 deletions.
104 changes: 93 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,41 @@ run:
tests: false
skip-dirs:
- tests/e2e

skip-files:
- ".*\\.pb\\.go$"
- ".*\\.pb\\.gw\\.go$"
- ".*\\.pulsar\\.go$"
linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
# - depguard
- dogsled
- errcheck
- exportloopref
- goconst
- gocritic
- gofmt
- goimports
- golint
- gci
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- maligned
- misspell
- nakedret
- prealloc
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- thelper
- unconvert
- unused
- unparam
# - wsl
- nolintlint
- revive

issues:
exclude-rules:
Expand All @@ -57,20 +60,99 @@ issues:
- text: "ST1016:"
linters:
- stylecheck
- text: "SA1019: codec.LegacyAmino is deprecated"
- path: "migrations"
text: "SA1019:"
linters:
- staticcheck
- text: "SA1019: codec.NewAminoCodec is deprecated" # TODO remove once migration path is set out
linters:
- staticcheck
- text: "SA1019: legacybech32.MustMarshalPubKey" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "SA1019: legacybech32.MarshalPubKey" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "SA1019: legacybech32.UnmarshalPubKey" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "SA1019: params.SendEnabled is deprecated" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "leading space"
linters:
- nolintlint
max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
gci:
custom-order: true
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/persistenceOne/pstake-native)
revive:
rules:
- name: redefines-builtin-id
disabled: true

gosec:
# To select a subset of rules to run.
# Available rules: https://github.com/securego/gosec#available-rules
# Default: [] - means include all rules
includes:
# - G101 # Look for hard coded credentials
- G102 # Bind to all interfaces
- G103 # Audit the use of unsafe block
- G104 # Audit errors not checked
- G106 # Audit the use of ssh.InsecureIgnoreHostKey
- G107 # Url provided to HTTP request as taint input
- G108 # Profiling endpoint automatically exposed on /debug/pprof
- G109 # Potential Integer overflow made by strconv.Atoi result conversion to int16/32
- G110 # Potential DoS vulnerability via decompression bomb
- G111 # Potential directory traversal
- G112 # Potential slowloris attack
- G113 # Usage of Rat.SetString in math/big with an overflow (CVE-2022-23772)
- G114 # Use of net/http serve function that has no support for setting timeouts
- G201 # SQL query construction using format string
- G202 # SQL query construction using string concatenation
- G203 # Use of unescaped data in HTML templates
- G204 # Audit use of command execution
- G301 # Poor file permissions used when creating a directory
- G302 # Poor file permissions used with chmod
- G303 # Creating tempfile using a predictable path
- G304 # File path provided as taint input
- G305 # File traversal when extracting zip/tar archive
- G306 # Poor file permissions used when writing to a new file
- G307 # Deferring a method which returns an error
- G401 # Detect the usage of DES, RC4, MD5 or SHA1
- G402 # Look for bad TLS connection settings
- G403 # Ensure minimum RSA key length of 2048 bits
- G404 # Insecure random number source (rand)
- G501 # Import blocklist: crypto/md5
- G502 # Import blocklist: crypto/des
- G503 # Import blocklist: crypto/rc4
- G504 # Import blocklist: net/http/cgi
- G505 # Import blocklist: crypto/sha1
- G601 # Implicit memory aliasing of items from a range statement
misspell:
locale: US
gofumpt:
extra-rules: true
dogsled:
max-blank-identifiers: 3
max-blank-identifiers: 6
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
nolintlint:
allow-unused: false
allow-leading-space: true
require-explanation: false
require-explanation: true
require-specific: false
gosimple:
checks: ["all"]
gocritic:
disabled-checks:
- regexpMust
- appendAssign
- ifElseChain
2 changes: 1 addition & 1 deletion ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (s *IntegrationTestSuite) SetupTest() {
s.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig)
}

func (s *IntegrationTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (xauthsigning.Tx, error) {
func (s *IntegrationTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums, accSeqs []uint64, chainID string) (xauthsigning.Tx, error) {
var sigsV2 []signing.SignatureV2
for i, priv := range privs {
sigV2 := signing.SignatureV2{
Expand Down
2 changes: 0 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,6 @@ func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router) {
}

// initParamsKeeper init params keeper and its subspaces
//
//nolint:staticcheck
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey store.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

Expand Down
2 changes: 1 addition & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// ExportAppStateAndValidators exports the state of the application for a genesis
// file.
func (app *PstakeApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string) (servertypes.ExportedApp, error) {
func (app *PstakeApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs, modulesToExport []string) (servertypes.ExportedApp, error) {
// as if they could withdraw from the start of the next block
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var DefaultConsensusParams = &tmproto.ConsensusParams{
},
}

func newTestApp(t *testing.T, isCheckTx bool, _ bool) app.PstakeApp {
func newTestApp(t *testing.T, isCheckTx, _ bool) app.PstakeApp {
testApp := Setup(t, isCheckTx, 5)
return *testApp
}
Expand Down Expand Up @@ -368,7 +368,7 @@ func ConvertAddrsToValAddrs(addrs []sdk.AccAddress) []sdk.ValAddress {
return valAddrs
}

func TestAddr(addr string, bech string) (sdk.AccAddress, error) {
func TestAddr(addr, bech string) (sdk.AccAddress, error) {
res, err := sdk.AccAddressFromHexUnsafe(addr)
if err != nil {
return nil, err
Expand Down
1 change: 0 additions & 1 deletion app/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
var (
// BypassMinFeeMsgTypesKey defines the configuration key for the
// BypassMinFeeMsgTypes value.
//nolint:gosec,nocredentials
BypassMinFeeMsgTypesKey = "bypass-min-fee-msg-types"

// CustomConfigTemplate defines pStake's custom application configuration TOML
Expand Down
2 changes: 1 addition & 1 deletion cmd/pstaked/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func calculateIP(ip string, i int) (string, error) {
return ipv4.String(), nil
}

func writeFile(name string, dir string, contents []byte) error {
func writeFile(name, dir string, contents []byte) error {
writePath := filepath.Clean(dir)
file := filepath.Join(writePath, name)

Expand Down
2 changes: 1 addition & 1 deletion x/liquidstake/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func (s *KeeperTestSuite) doubleSign(valOper sdk.ValAddress, consAddr sdk.ConsAd
}

func (s *KeeperTestSuite) createContinuousVestingAccount(
from sdk.AccAddress, to sdk.AccAddress, amt sdk.Coins,
from, to sdk.AccAddress, amt sdk.Coins,
startTime, endTime time.Time,
) vestingtypes.ContinuousVestingAccount {
baseAccount := s.app.AccountKeeper.NewAccountWithAddress(s.ctx, to)
Expand Down
2 changes: 1 addition & 1 deletion x/liquidstake/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// BankKeeper defines the expected bank send keeper
type BankKeeper interface {
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
SendCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error

GetSupply(ctx sdk.Context, denom string) sdk.Coin
SendCoinsFromModuleToModule(ctx sdk.Context, senderPool, recipientPool string, amt sdk.Coins) error
Expand Down
6 changes: 3 additions & 3 deletions x/liquidstake/types/liquidstake.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (v LiquidValidator) GetStatus(activeCondition bool) ValidatorStatus {
// - included on whitelist
// - existed valid validator on staking module ( existed, not nil del shares and tokens, valid exchange rate)
// - not tombstoned
func ActiveCondition(validator stakingtypes.Validator, whitelisted bool, tombstoned bool) bool {
func ActiveCondition(validator stakingtypes.Validator, whitelisted, tombstoned bool) bool {
return whitelisted &&
!tombstoned &&
// !Unspecified ==> Bonded, Unbonding, Unbonded
Expand All @@ -102,7 +102,7 @@ type (
)

// MinMaxGap Return the list of LiquidValidator with the maximum gap and minimum gap from the target weight of LiquidValidators, respectively.
func (vs LiquidValidators) MinMaxGap(targetMap, liquidTokenMap map[string]math.Int) (minGapVal LiquidValidator, maxGapVal LiquidValidator, amountNeeded math.Int, lastRedelegation bool) {
func (vs LiquidValidators) MinMaxGap(targetMap, liquidTokenMap map[string]math.Int) (minGapVal, maxGapVal LiquidValidator, amountNeeded math.Int, lastRedelegation bool) {
maxGap := sdk.ZeroInt()
minGap := sdk.ZeroInt()

Expand Down Expand Up @@ -177,7 +177,7 @@ func StkXPRTToNativeToken(stkXPRTAmount, stkXPRTTotalSupplyAmount math.Int, netA
}

// DeductFeeRate returns Input * (1-FeeRate) with truncations
func DeductFeeRate(input math.LegacyDec, feeRate math.LegacyDec) (feeDeductedOutput math.LegacyDec) {
func DeductFeeRate(input, feeRate math.LegacyDec) (feeDeductedOutput math.LegacyDec) {
return input.MulTruncate(sdk.OneDec().Sub(feeRate)).TruncateDec()
}

Expand Down
4 changes: 2 additions & 2 deletions x/liquidstakeibc/keeper/redelegation_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (k *Keeper) SetRedelegationTx(ctx sdk.Context, redelegationTx *types.Redele
store.Set(types.GetRedelegationTxStoreKey(redelegationTx.ChainId, redelegationTx.IbcSequenceId), bytes)
}

func (k *Keeper) GetRedelegationTx(ctx sdk.Context, chainID string, ibcSequenceID string) (*types.RedelegateTx, bool) {
func (k *Keeper) GetRedelegationTx(ctx sdk.Context, chainID, ibcSequenceID string) (*types.RedelegateTx, bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.RedelegationTxKey)
bz := store.Get(types.GetRedelegationTxStoreKey(chainID, ibcSequenceID))
if bz == nil {
Expand Down Expand Up @@ -60,7 +60,7 @@ func (k *Keeper) FilterRedelegationTx(
return redelegationTxs
}

func (k *Keeper) DeleteRedelegationTx(ctx sdk.Context, chainID string, ibcSequenceID string) {
func (k *Keeper) DeleteRedelegationTx(ctx sdk.Context, chainID, ibcSequenceID string) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.RedelegationTxKey)
store.Delete(types.GetRedelegationTxStoreKey(chainID, ibcSequenceID))
}
4 changes: 2 additions & 2 deletions x/liquidstakeibc/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
EventTypeDoDelegation = "send_delegation"
EventTypeDoDelegationDeposit = "send_individual_delegation"
EventTypeClaimedUnbondings = "claimed_unbondings"
EventTypeRedeemTokensForShares = "redeem_lsm_tokens_shares" //nolint:gosec
EventTypeRedeemTokensForShares = "redeem_lsm_tokens_shares"
EventTypeCValueUpdate = "c_value_update"
EventTypeDelegationWorkflow = "delegation_workflow"
EventTypeUndelegationWorkflow = "undelegation_workflow"
Expand Down Expand Up @@ -78,7 +78,7 @@ const (
AttributeClaimAmount = "claimed_amount"
AttributeClaimAddress = "claim_address"
AttributeModuleMintedAmount = "minted_amount"
AttributeModuleLSMTokenizedAmount = "lsm_tokenized_amount" //nolint:gosec
AttributeModuleLSMTokenizedAmount = "lsm_tokenized_amount"
AttributeModuleStakedAmount = "staked_amount"
AttributeModuleAmountOnPersistence = "amount_on_persistence"
AttributeModuleAmountOnHostChain = "amount_on_host_chain"
Expand Down
6 changes: 3 additions & 3 deletions x/liquidstakeibc/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type BankKeeper interface {
BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error
GetSupply(ctx sdk.Context, denom string) sdk.Coin
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
SendCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
}
Expand All @@ -30,13 +30,13 @@ type ScopedKeeper interface {
}

type ICAControllerKeeper interface {
RegisterInterchainAccount(ctx sdk.Context, connectionID, owner string, version string) error
RegisterInterchainAccount(ctx sdk.Context, connectionID, owner, version string) error
GetInterchainAccountAddress(ctx sdk.Context, connectionID, portID string) (string, bool)
GetOpenActiveChannel(ctx sdk.Context, connectionID, portID string) (string, bool)
}

type ICQKeeper interface {
MakeRequest(ctx sdk.Context, connectionID string, chainID string, queryType string, request []byte, period math.Int, module string, callbackID string, ttl uint64)
MakeRequest(ctx sdk.Context, connectionID, chainID, queryType string, request []byte, period math.Int, module, callbackID string, ttl uint64)
}

type EpochsKeeper interface {
Expand Down
2 changes: 1 addition & 1 deletion x/liquidstakeibc/types/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewMultiLiquidStakeIBCHooks(hooks ...LiquidStakeIBCHooks) MultiLiquidStakeI
func (h MultiLiquidStakeIBCHooks) PostCValueUpdate(ctx sdk.Context, mintDenom, hostDenom string, cValue sdk.Dec) error {
for i := range h {
wrappedHookFn := func(ctx sdk.Context) error {
//nolint:scopelint
//nolint:scopelint // the variables will be same for each loop, ok to use global
return h[i].PostCValueUpdate(ctx, mintDenom, hostDenom, cValue)
}

Expand Down
2 changes: 1 addition & 1 deletion x/liquidstakeibc/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ func GetRedelegationsStoreKey(chainID string) []byte {
return []byte(chainID)
}

func GetRedelegationTxStoreKey(chainID string, ibcSequenceID string) []byte {
func GetRedelegationTxStoreKey(chainID, ibcSequenceID string) []byte {
return append([]byte(chainID), []byte(ibcSequenceID)...)
}
5 changes: 0 additions & 5 deletions x/liquidstakeibc/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ func (m *MsgUpdateHostChain) ValidateBasic() error {
return nil
}

//nolint:interfacer
func NewMsgLiquidStake(amount sdk.Coin, address sdk.AccAddress) *MsgLiquidStake {
return &MsgLiquidStake{
DelegatorAddress: address.String(),
Expand Down Expand Up @@ -417,7 +416,6 @@ func (m *MsgLiquidStake) ValidateBasic() error {
return ibctransfertypes.ValidateIBCDenom(m.Amount.Denom)
}

//nolint:interfacer
func NewMsgLiquidStakeLSM(delegations sdk.Coins, address sdk.AccAddress) *MsgLiquidStakeLSM {
return &MsgLiquidStakeLSM{
DelegatorAddress: address.String(),
Expand Down Expand Up @@ -470,7 +468,6 @@ func (m *MsgLiquidStakeLSM) ValidateBasic() error {
return nil
}

//nolint:interfacer
func NewMsgLiquidUnstake(amount sdk.Coin, address sdk.AccAddress) *MsgLiquidUnstake {
return &MsgLiquidUnstake{
DelegatorAddress: address.String(),
Expand Down Expand Up @@ -522,7 +519,6 @@ func (m *MsgLiquidUnstake) ValidateBasic() error {
return nil
}

//nolint:interfacer
func NewMsgRedeem(amount sdk.Coin, address sdk.AccAddress) *MsgRedeem {
return &MsgRedeem{
DelegatorAddress: address.String(),
Expand Down Expand Up @@ -573,7 +569,6 @@ func (m *MsgRedeem) ValidateBasic() error {
return nil
}

//nolint:interfacer
func NewMsgUpdateParams(authority sdk.AccAddress, amount Params) *MsgUpdateParams {
return &MsgUpdateParams{
Authority: authority.String(),
Expand Down
2 changes: 1 addition & 1 deletion x/ratesync/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (k Keeper) AllHostChains(goCtx context.Context, req *types.QueryAllHostChai
store := ctx.KVStore(k.storeKey)
chainStore := prefix.NewStore(store, types.HostChainKeyPrefix)

pageRes, err := query.Paginate(chainStore, req.Pagination, func(key []byte, value []byte) error {
pageRes, err := query.Paginate(chainStore, req.Pagination, func(key, value []byte) error {
var chain types.HostChain
if err := k.cdc.Unmarshal(value, &chain); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion x/ratesync/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) {
types.RegisterInterfaces(reg)
}

// DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. The default GenesisState need to be defined by the module developer and is primarily used for testing
// DefaultGenesis returns a default GenesisState for the module, marshaled to json.RawMessage. The default GenesisState need to be defined by the module developer and is primarily used for testing
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesis())
}
Expand Down
Loading

0 comments on commit c32d746

Please sign in to comment.