diff --git a/.golangci.yml b/.golangci.yml index 2b08da5ec..e294c954b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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: @@ -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 \ No newline at end of file diff --git a/ante/ante_test.go b/ante/ante_test.go index b41d4cb63..828beb7a2 100644 --- a/ante/ante_test.go +++ b/ante/ante_test.go @@ -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{ diff --git a/app/app.go b/app/app.go index 0b4a6322c..d75a3e1f3 100644 --- a/app/app.go +++ b/app/app.go @@ -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) diff --git a/app/export.go b/app/export.go index e24a8403c..52320dfb7 100644 --- a/app/export.go +++ b/app/export.go @@ -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()}) diff --git a/app/helpers/test_helpers.go b/app/helpers/test_helpers.go index 43427eedf..932857fe6 100644 --- a/app/helpers/test_helpers.go +++ b/app/helpers/test_helpers.go @@ -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 } @@ -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 diff --git a/app/params/config.go b/app/params/config.go index 3be0f9646..e4f2e0efd 100644 --- a/app/params/config.go +++ b/app/params/config.go @@ -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 diff --git a/cmd/pstaked/cmd/testnet.go b/cmd/pstaked/cmd/testnet.go index b20af550c..9374365e0 100644 --- a/cmd/pstaked/cmd/testnet.go +++ b/cmd/pstaked/cmd/testnet.go @@ -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) diff --git a/x/liquidstake/keeper/keeper_test.go b/x/liquidstake/keeper/keeper_test.go index 2666a19a3..9a3d24d8f 100644 --- a/x/liquidstake/keeper/keeper_test.go +++ b/x/liquidstake/keeper/keeper_test.go @@ -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) diff --git a/x/liquidstake/types/expected_keepers.go b/x/liquidstake/types/expected_keepers.go index 4cd3d77a6..5b2ddcc13 100644 --- a/x/liquidstake/types/expected_keepers.go +++ b/x/liquidstake/types/expected_keepers.go @@ -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 diff --git a/x/liquidstake/types/liquidstake.go b/x/liquidstake/types/liquidstake.go index 373d7eae9..3d85e7229 100644 --- a/x/liquidstake/types/liquidstake.go +++ b/x/liquidstake/types/liquidstake.go @@ -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 @@ -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() @@ -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() } diff --git a/x/liquidstakeibc/keeper/redelegation_txs.go b/x/liquidstakeibc/keeper/redelegation_txs.go index e5bb2ec68..0b5bce9cb 100644 --- a/x/liquidstakeibc/keeper/redelegation_txs.go +++ b/x/liquidstakeibc/keeper/redelegation_txs.go @@ -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 { @@ -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)) } diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index 9f25670c0..b33cdc7ea 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -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" @@ -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" diff --git a/x/liquidstakeibc/types/expected_keepers.go b/x/liquidstakeibc/types/expected_keepers.go index cb2c36814..913095f9f 100644 --- a/x/liquidstakeibc/types/expected_keepers.go +++ b/x/liquidstakeibc/types/expected_keepers.go @@ -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 } @@ -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 { diff --git a/x/liquidstakeibc/types/hooks.go b/x/liquidstakeibc/types/hooks.go index 73355b23a..945637e73 100644 --- a/x/liquidstakeibc/types/hooks.go +++ b/x/liquidstakeibc/types/hooks.go @@ -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) } diff --git a/x/liquidstakeibc/types/keys.go b/x/liquidstakeibc/types/keys.go index e8e651ec8..ca364793a 100644 --- a/x/liquidstakeibc/types/keys.go +++ b/x/liquidstakeibc/types/keys.go @@ -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)...) } diff --git a/x/liquidstakeibc/types/msgs.go b/x/liquidstakeibc/types/msgs.go index cad124f38..93ef428a7 100644 --- a/x/liquidstakeibc/types/msgs.go +++ b/x/liquidstakeibc/types/msgs.go @@ -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(), @@ -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(), @@ -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(), @@ -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(), @@ -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(), diff --git a/x/ratesync/keeper/query.go b/x/ratesync/keeper/query.go index dd0befe7b..048068e8e 100644 --- a/x/ratesync/keeper/query.go +++ b/x/ratesync/keeper/query.go @@ -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 diff --git a/x/ratesync/module.go b/x/ratesync/module.go index 3eb2c3a90..3b29e1b06 100644 --- a/x/ratesync/module.go +++ b/x/ratesync/module.go @@ -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()) } diff --git a/x/ratesync/module_simulation.go b/x/ratesync/module_simulation.go index 02a83af7e..5d26c0403 100644 --- a/x/ratesync/module_simulation.go +++ b/x/ratesync/module_simulation.go @@ -46,7 +46,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} // ProposalContents doesn't return any content functions for governance proposals. -func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg { return nil } diff --git a/x/ratesync/types/expected_keepers.go b/x/ratesync/types/expected_keepers.go index c29133133..340e98561 100644 --- a/x/ratesync/types/expected_keepers.go +++ b/x/ratesync/types/expected_keepers.go @@ -20,13 +20,13 @@ 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 } 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) }