Skip to content

Commit

Permalink
Merge pull request #6 from provenance-io/go-lint-fixes
Browse files Browse the repository at this point in the history
Go lint fixes
  • Loading branch information
iramiller authored Jan 22, 2021
2 parents 0b7e42d + e3ffef5 commit 5880ade
Show file tree
Hide file tree
Showing 37 changed files with 150 additions and 123 deletions.
40 changes: 22 additions & 18 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ linters:
- depguard
- dogsled
- errcheck
- funlen
- gocyclo
# - funlen
# - gocyclo
- goconst
- gocritic
- gofmt
- goimports
- golint
Expand All @@ -21,18 +23,23 @@ linters:
- govet
- ineffassign
- interfacer
- lll
# - lll
- maligned
- misspell
- nakedret
- prealloc
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- unparam
# - wsl
- varcheck
- whitespace
- nolintlint

issues:
exclude-rules:
Expand All @@ -48,11 +55,6 @@ issues:
- text: "ST1003:"
linters:
- stylecheck
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
# https://github.com/dominikh/go-tools/issues/389
- text: "ST1016:"
linters:
- stylecheck
max-issues-per-linter: 10000
max-same-issues: 10000

Expand All @@ -68,19 +70,21 @@ linters-settings:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
golint:
min-confidence: 0
gocyclo:
min-complexity: 15
# gocyclo:
# min-complexity: 15
dogsled:
max-blank-identifiers: 3
# lll:
# line-length: 120
# funlen:
# lines: 100
# statements: 50
# nakedret:
# max-func-lines: 50
maligned:
suggest-new: true
misspell:
locale: US
lll:
line-length: 120
funlen:
lines: 100
statements: 50
nakedret:
max-func-lines: 50
nolintlint:
allow-unused: false
allow-leading-space: true
Expand Down
7 changes: 4 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
appparams "github.com/provenance-io/provenance/app/params"
tmjson "github.com/tendermint/tendermint/libs/json"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

appparams "github.com/provenance-io/provenance/app/params"

"github.com/provenance-io/provenance/x/attribute"
attributekeeper "github.com/provenance-io/provenance/x/attribute/keeper"
attributetypes "github.com/provenance-io/provenance/x/attribute/types"
Expand All @@ -100,6 +101,7 @@ import (

"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"

"github.com/provenance-io/provenance/internal/provwasm"
)

Expand Down Expand Up @@ -239,7 +241,6 @@ func New(
homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig,
appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp),
) *App {

appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
Expand Down Expand Up @@ -399,7 +400,7 @@ func New(
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferModule)
app.IBCKeeper.SetRouter(ibcRouter)

// Create evidence Keeper for to register the IBC light client misbehaviour evidence route
// Create evidence Keeper for to register the IBC light client misbehavior evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec, keys[evidencetypes.StoreKey], &app.StakingKeeper, app.SlashingKeeper,
)
Expand Down
1 change: 1 addition & 0 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"github.com/cosmos/cosmos-sdk/std"

"github.com/provenance-io/provenance/app/params"
)

Expand Down
3 changes: 1 addition & 2 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
func (app *App) ExportAppStateAndValidators(
forZeroHeight bool, jailAllowedAddrs []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 @@ -50,7 +49,7 @@ func (app *App) ExportAppStateAndValidators(

// 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 *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
applyAllowedAddrs := false

Expand Down
10 changes: 4 additions & 6 deletions app/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ import (
)

const (
flagGenesisTime = "genesis-time"
flagInitialHeight = "initial-height"
flagReplacementKeys = "replacement-cons-keys"
flagNoProp29 = "no-prop-29"
flagGenesisTime = "genesis-time"
flagInitialHeight = "initial-height"
)

// MigrateGenesisCmd returns a command to execute genesis state migration.
Expand Down Expand Up @@ -66,7 +64,7 @@ $ %s migrate /path/to/genesis.json --chain-id=provenance-2 --genesis-time=2020-0
}

var initialState types.AppMap
if err := json.Unmarshal(genDoc.AppState, &initialState); err != nil {
if err = json.Unmarshal(genDoc.AppState, &initialState); err != nil {
return errors.Wrap(err, "failed to JSON unmarshal initial genesis state")
}

Expand Down Expand Up @@ -110,7 +108,7 @@ $ %s migrate /path/to/genesis.json --chain-id=provenance-2 --genesis-time=2020-0
if genesisTime != "" {
var t time.Time

err := t.UnmarshalText([]byte(genesisTime))
err = t.UnmarshalText([]byte(genesisTime))
if err != nil {
return errors.Wrap(err, "failed to unmarshal genesis time")
}
Expand Down
2 changes: 0 additions & 2 deletions app/sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
// SimAppChainID hardcoded chainID for simulation
const (
appName = "provenanced"
chainID = "sim-provenance"
)

func setup(withGenesis bool, invCheckPeriod uint) (*App, GenesisState) {
Expand Down Expand Up @@ -95,7 +94,6 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
}
validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec()))

}

// set validators and delegations
Expand Down
1 change: 1 addition & 0 deletions cmd/provenanced/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/x/genutil/client/cli"

"github.com/provenance-io/provenance/cmd/provenanced/cmd"
)

Expand Down
14 changes: 7 additions & 7 deletions cmd/provenanced/cmd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa

config.SetRoot(clientCtx.HomeDir)

addr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
addr, parseErr := sdk.AccAddressFromBech32(args[0])
if parseErr != nil {
inBuf := bufio.NewReader(cmd.InOrStdin())
keyringBackend, err := cmd.Flags().GetString(flags.FlagKeyringBackend)
if err != nil {
Expand All @@ -69,7 +69,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa

info, err := kb.Key(args[0])
if err != nil {
return fmt.Errorf("failed to get address from Keybase: %w", err)
return fmt.Errorf("failed to get address from Keybase: %w, could not use address as bech32 string: %s", err, parseErr.Error())
}

addr = info.GetAddress()
Expand Down Expand Up @@ -126,7 +126,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
genAccount = baseAccount
}

if err := genAccount.Validate(); err != nil {
if err = genAccount.Validate(); err != nil {
return fmt.Errorf("failed to validate new genesis account: %w", err)
}

Expand Down Expand Up @@ -217,8 +217,8 @@ func AddRootDomainAccountCmd(defaultNodeHome string) *cobra.Command {

config.SetRoot(clientCtx.HomeDir)

addr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
addr, parseErr := sdk.AccAddressFromBech32(args[0])
if parseErr != nil {
inBuf := bufio.NewReader(cmd.InOrStdin())
keyringBackend, err := cmd.Flags().GetString(flags.FlagKeyringBackend)
if err != nil {
Expand All @@ -233,7 +233,7 @@ func AddRootDomainAccountCmd(defaultNodeHome string) *cobra.Command {

info, err := kb.Key(args[0])
if err != nil {
return fmt.Errorf("failed to get address from Keybase: %w", err)
return fmt.Errorf("failed to get address from Keybase: %w, could use use address as bech32 string: %s", err, parseErr.Error())
}

addr = info.GetAddress()
Expand Down
25 changes: 19 additions & 6 deletions cmd/provenanced/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/snapshots"

"github.com/provenance-io/provenance/app/params"

"github.com/spf13/cast"
Expand All @@ -34,6 +35,7 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"

"github.com/provenance-io/provenance/app"
)

Expand Down Expand Up @@ -113,6 +115,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
AddGenesisAccountCmd(app.DefaultNodeHome(appName)),
AddRootDomainAccountCmd(app.DefaultNodeHome(appName)),
tmcli.NewCompletionCmd(rootCmd, true),
testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}),
debug.Cmd(),
)

Expand Down Expand Up @@ -202,8 +205,11 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty

snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots")
// Create the snapshot dir if not exists
if _, err := os.Stat(snapshotDir); os.IsNotExist(err) {
os.Mkdir(snapshotDir, 0755)
if _, err = os.Stat(snapshotDir); os.IsNotExist(err) {
err = os.Mkdir(snapshotDir, 0755)
if err != nil {
panic(err)
}
}
snapshotDB, err := sdk.NewLevelDB("metadata", snapshotDir)
if err != nil {
Expand Down Expand Up @@ -235,9 +241,14 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty
}

func createSimappAndExport(
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string,
appOpts servertypes.AppOptions) (servertypes.ExportedApp, error) {

logger log.Logger,
db dbm.DB,
traceStore io.Writer,
height int64,
forZeroHeight bool,
jailAllowedAddrs []string,
appOpts servertypes.AppOptions,
) (servertypes.ExportedApp, error) {
encCfg := app.MakeEncodingConfig() // Ideally, we would reuse the one created by NewRootCmd.
encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry)
var a *app.App
Expand All @@ -258,7 +269,9 @@ func overwriteFlagDefaults(c *cobra.Command, defaults map[string]string) {
set := func(s *pflag.FlagSet, key, val string) {
if f := s.Lookup(key); f != nil {
f.DefValue = val
f.Value.Set(val)
if err := f.Value.Set(val); err != nil {
panic(err)
}
}
}
for key, val := range defaults {
Expand Down
Loading

0 comments on commit 5880ade

Please sign in to comment.