Skip to content

Commit

Permalink
chore: gofumpt (#722)
Browse files Browse the repository at this point in the history
* gofumpt

* lint

* more lint

* more lint

* more lint

* more lint

* more lint
  • Loading branch information
puneet2019 authored Jan 12, 2024
1 parent c53c0a7 commit d55fe77
Show file tree
Hide file tree
Showing 84 changed files with 414 additions and 350 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: "v1.52.2"
version: "v1.55.0"
args: --timeout=5m
104 changes: 92 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,39 @@ run:
tests: false
skip-dirs:
- tests/e2e

skip-files:
- ".*\\.pb\\.go$"
- ".*\\.pb\\.gw\\.go$"
- ".*\\.pulsar\\.go$"
linters:
disable-all: true
enable:
- bodyclose
- deadcode
- 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 +58,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
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ rm-testcache:
###############################################################################
### Linting ###
###############################################################################
golangci_version=v1.55.0

lint-install:
@echo "--> Installing golangci-lint $(golangci_version)"
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version)


lint:
golangci-lint run
Expand Down
2 changes: 1 addition & 1 deletion ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

var sigGasConsumer = opts.SigGasConsumer
sigGasConsumer := opts.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
}
Expand Down
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
20 changes: 10 additions & 10 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ func NewpStakeApp(
app.BankKeeper,
scopedTransferKeeper,
)
//transferModule := transfer.NewAppModule(app.TransferKeeper)
//transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)
// transferModule := transfer.NewAppModule(app.TransferKeeper)
// transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)

app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec, keys[icacontrollertypes.StoreKey],
Expand All @@ -487,7 +487,7 @@ func NewpStakeApp(
app.MsgServiceRouter(),
)

//icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper)
// icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper)

app.InterchainQueryKeeper = interchainquerykeeper.NewKeeper(appCodec, keys[interchainquerytypes.StoreKey], app.IBCKeeper)
interchainQueryModule := interchainquery.NewAppModule(appCodec, app.InterchainQueryKeeper)
Expand Down Expand Up @@ -623,7 +623,7 @@ func NewpStakeApp(
transfer.NewAppModule(app.TransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
//ibchooker.NewAppModule(),
// ibchooker.NewAppModule(),
interchainQueryModule,
liquidstakeibc.NewAppModule(app.LiquidStakeIBCKeeper),
liquidstake.NewAppModule(app.LiquidStakeKeeper),
Expand Down Expand Up @@ -659,7 +659,7 @@ func NewpStakeApp(
feegrant.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
ibchookertypes.ModuleName, //Noop
ibchookertypes.ModuleName, // Noop
interchainquerytypes.ModuleName,
liquidstakeibctypes.ModuleName,
liquidstaketypes.ModuleName,
Expand Down Expand Up @@ -688,7 +688,7 @@ func NewpStakeApp(
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
ibchookertypes.ModuleName, //Noop
ibchookertypes.ModuleName, // Noop
interchainquerytypes.ModuleName,
liquidstakeibctypes.ModuleName,
liquidstaketypes.ModuleName,
Expand Down Expand Up @@ -724,7 +724,7 @@ func NewpStakeApp(
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
ibchookertypes.ModuleName, //Noop
ibchookertypes.ModuleName, // Noop
interchainquerytypes.ModuleName,
liquidstakeibctypes.ModuleName,
liquidstaketypes.ModuleName,
Expand Down Expand Up @@ -849,6 +849,7 @@ func (app *PstakeApp) ModuleAccountAddrs() map[string]bool {

return modAccAddrs
}

func (app *PstakeApp) SendCoinBlockedAddrs() map[string]bool {
modAccAddrs := make(map[string]bool)
for acc := range maccPerms {
Expand Down Expand Up @@ -966,11 +967,11 @@ func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router) {

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

paramsKeeper.Subspace(authtypes.ModuleName).WithKeyTable(authtypes.ParamKeyTable())
paramsKeeper.Subspace(authtypes.ModuleName).WithKeyTable(authtypes.ParamKeyTable()) //
paramsKeeper.Subspace(banktypes.ModuleName).WithKeyTable(banktypes.ParamKeyTable())
paramsKeeper.Subspace(stakingtypes.ModuleName).WithKeyTable(stakingtypes.ParamKeyTable())
paramsKeeper.Subspace(minttypes.ModuleName).WithKeyTable(minttypes.ParamKeyTable())
Expand Down Expand Up @@ -1018,7 +1019,6 @@ func (app *PstakeApp) RegisterUpgradeHandler() {
app.UpgradeKeeper.SetUpgradeHandler(
UpgradeName,
func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {

// stuck unbonding epoch numbers
RemovableUnbondings := map[string]map[int64]any{"cosmoshub-4": {312: nil}, "osmosis-1": {429: nil, 432: nil}}

Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -43,7 +43,7 @@ func (app *PstakeApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowe

// prepare for fresh start at zero height
// NOTE zero height genesis is a temporary feature which will be deprecated
// in favour of export at a block height
// in favor of export at a block height
func (app *PstakeApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
applyAllowedAddrs := false

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

func newTestApp(t *testing.T, isCheckTx bool, _ bool) app.PstakeApp {
func newTestApp(t *testing.T, isCheckTx, _ bool) app.PstakeApp {
t.Helper()
testApp := Setup(t, isCheckTx, 5)
return *testApp
}

func CreateTestApp(t *testing.T) (*codec.LegacyAmino, app.PstakeApp, sdk.Context) {
t.Helper()
testApp := newTestApp(t, false, false)
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{})

Expand Down Expand Up @@ -148,6 +150,7 @@ func genesisStateWithValSet(t *testing.T,
valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount,
balances ...banktypes.Balance,
) app.GenesisState {
t.Helper()
// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis)
Expand Down Expand Up @@ -263,7 +266,7 @@ func NewConfig(dbm *dbm.MemDB) network.Config {

// NewAppConstructor returns a new network AppConstructor.
//
//nolint:interfacer
//nolint:interfacer // only used for tests
func NewAppConstructor(encodingCfg appparams.EncodingConfig, db *dbm.MemDB) network.AppConstructor {
return func(val network.ValidatorI) types.Application {
return app.NewpStakeApp(
Expand Down Expand Up @@ -368,7 +371,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 All @@ -391,6 +394,7 @@ func TestAddr(addr string, bech string) (sdk.AccAddress, error) {

// CheckBalance checks the balance of an account.
func CheckBalance(t *testing.T, app *app.PstakeApp, addr sdk.AccAddress, balances sdk.Coins) {
t.Helper()
ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{})
require.True(t, balances.IsEqual(app.BankKeeper.GetAllBalances(ctxCheck, addr)))
}
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/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func initTendermintConfig() *tmcfg.Config {

return cfg
}

func initAppConfig() (string, interface{}) {
srvCfg := serverconfig.DefaultConfig()
srvCfg.StateSync.SnapshotInterval = 1000
Expand Down Expand Up @@ -245,5 +246,4 @@ func (ac appCreator) appExport(
}

return pStakeApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)

}
1 change: 0 additions & 1 deletion cmd/pstaked/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func TestRootCmdConfig(t *testing.T) {

rootCmd, _ := cmd.NewRootCmd()
rootCmd.SetArgs([]string{
"config", // Test the config cmd
Expand Down
Loading

0 comments on commit d55fe77

Please sign in to comment.