Skip to content

Commit

Permalink
lint: enable staticcheck (#1956)
Browse files Browse the repository at this point in the history
* lint: enable staticcheck

* remove more dead code from balances from state export command

* named return for error in forceprune

* remove nolint
  • Loading branch information
p0mvn committed Jul 8, 2022
1 parent c79f28b commit 1b5a1d3
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
5 changes: 4 additions & 1 deletion .golangci.yml
Expand Up @@ -68,7 +68,7 @@ linters:
# - revive <- temporarily disabled while jacob figures out how to make poolId not trigger it.
# - rowserrcheck <- needs go 1.18 support
# - sqlclosecheck <- needs go 1.18 support
# - staticcheck <- later
- staticcheck # set of rules from staticcheck, subset of staticcheck binary.
# - structcheck <- later
- stylecheck # replacement of golint, subset of staticcheck binary.
# - tagliatelle <- disabled for defying cosmos idiom
Expand Down Expand Up @@ -102,6 +102,9 @@ issues:
# across its files, once stableswap is fully complete.
- unused
- deadcode
- linters:
- staticcheck
text: "SA1024: cutset contains duplicate characters" # proved to not provide much value, only false positives.
- linters:
- stylecheck
text: "ST1003:" # requires identifiers with "id" to be "ID".
Expand Down
10 changes: 0 additions & 10 deletions cmd/osmosisd/cmd/balances_from_state_export.go
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
Expand Down Expand Up @@ -141,7 +140,6 @@ func getGenStateFromPath(genesisFilePath string) (map[string]json.RawMessage, er
}

// ExportAirdropSnapshotCmd generates a snapshot.json from a provided exported genesis.json.
//nolint:ineffassign // because of accounts = authtypes.SanitizeGenesisAccounts(accounts)
func ExportDeriveBalancesCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "export-derive-balances [input-genesis-file] [output-snapshot-json]",
Expand Down Expand Up @@ -177,14 +175,6 @@ Example:
}
}

authGenesis := authtypes.GenesisState{}
clientCtx.Codec.MustUnmarshalJSON(genState["auth"], &authGenesis)
accounts, err := authtypes.UnpackAccounts(authGenesis.Accounts)
if err != nil {
panic(err)
}
accounts = authtypes.SanitizeGenesisAccounts(accounts)

// Produce the map of address to total atom balance, both staked and UnbondingStake
snapshotAccs := make(map[string]DerivedAccount)

Expand Down
17 changes: 15 additions & 2 deletions cmd/osmosisd/cmd/forceprune.go
Expand Up @@ -105,6 +105,8 @@ func pruneBlockStoreAndGetHeights(dbPath string, fullHeight int64) (
if err != nil {
return 0, 0, err
}

// nolint: staticcheck
defer db_bs.Close()

bs := tmstore.NewBlockStore(db_bs)
Expand All @@ -117,18 +119,29 @@ func pruneBlockStoreAndGetHeights(dbPath string, fullHeight int64) (
return 0, 0, err
}
fmt.Println("Pruned Block Store ...", prunedBlocks)

// N.B: We duplicate the call to db_bs.Close() on top of
// the call in defer statement above to make sure that the resources
// are properly released and any potential error from Close()
// is handled. Close() should be idempotent so this is acceptable.
if err := db_bs.Close(); err != nil {
return 0, 0, err
}

return startHeight, currentHeight, nil
}

func compactBlockStore(dbPath string) error {
func compactBlockStore(dbPath string) (err error) {
compactOpts := opt.Options{
DisableSeeksCompaction: true,
}

fmt.Println("Compacting Block Store ...")

db, err := leveldb.OpenFile(dbPath+"/blockstore.db", &compactOpts)
defer db.Close()
defer func() {
err = db.Close()
}()
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/osmosisd/cmd/genesis.go
Expand Up @@ -78,6 +78,9 @@ Example:

// run Prepare Genesis
appState, genDoc, err = PrepareGenesis(clientCtx, appState, genDoc, genesisParams, chainID)
if err != nil {
return err
}

// validate genesis state
if err = mbm.ValidateGenesis(cdc, clientCtx.TxConfig, appState); err != nil {
Expand Down
5 changes: 4 additions & 1 deletion cmd/osmosisd/cmd/testnet.go
Expand Up @@ -25,6 +25,7 @@ import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/server"
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -40,6 +41,8 @@ var (
flagOutputDir = "output-dir"
flagNodeDaemonHome = "node-daemon-home"
flagStartingIPAddress = "starting-ip-address"

emptyMnemonic = ""
)

// get cmd to initialize all files for tendermint testnet and application.
Expand Down Expand Up @@ -180,7 +183,7 @@ func InitTestnet(
return err
}

addr, secret, err := server.GenerateSaveCoinKey(kb, nodeDirName, true, algo)
addr, secret, err := testutil.GenerateSaveCoinKey(kb, nodeDirName, emptyMnemonic, true, algo)
if err != nil {
_ = os.RemoveAll(outputDir)
return err
Expand Down
3 changes: 0 additions & 3 deletions x/incentives/types/genesis.go
Expand Up @@ -45,8 +45,5 @@ func (gs GenesisState) Validate() error {
if gs.Params.DistrEpochIdentifier == "" {
return errors.New("epoch identifier should NOT be empty")
}
if gs.LastGaugeId < 0 {
return errors.New("lock gauge lock id should be non-negative")
}
return nil
}
5 changes: 0 additions & 5 deletions x/lockup/types/genesis.go
@@ -1,7 +1,5 @@
package types

import "errors"

// DefaultIndex is the default capability global index.
const DefaultIndex uint64 = 1

Expand All @@ -13,8 +11,5 @@ func DefaultGenesis() *GenesisState {
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
if gs.LastLockId < 0 {
return errors.New("lock last lock id should be non-negative")
}
return nil
}

0 comments on commit 1b5a1d3

Please sign in to comment.