Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: tighten linting #2771

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 31 additions & 60 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,106 +10,77 @@ linters:
enable:
- asciicheck
- bidichk
# - bodyclose <- needs go 1.18 support
# - contextcheck <- needs go 1.18 support
# - cyclop
- depguard
# - dogsled <- disabled because we would like to participate in the iditerod
# - dupl <- really just catches cli stub text
- durationcheck
- errcheck
- errname
# - errorlint <- later
# - exhaustive <- too picky
# - exhaustivestruct <- disabled because we don't want to use every element of every struct
- exportloopref
# - forbidigo <- forbids fmt.Print* by default
- forcetypeassert
# - funlen <- some of our functions are longer than this by necessity
# - gci <- questionable utility
# - gochecknoglobals <- disabled because we want some globals
# - gochecknoinits <- disabled because we want to use init()
# - gocognit <- disabled for same reason as gocyclo
- goconst
# - gocritic <- re enable later to catch capitalized local variables
# - gocyclo <- disabled because it won't work with how we cosmos
# - godot
# - godox <- detects TODO/BUG/FIXME and we may wantnthis later but isn't appropriate now
# - goerr113 <- disabled due to lack of comprehension
- gofmt
# - gofumpt <- disabled https://github.com/osmosis-labs/osmosis/issues/1309
- gocritic
- gofumpt
- goheader
- goimports
# - gomoddirectives <- disables replaces
- gomodguard
- goprintffuncname
# - gosec <- triggers too much for this round and should be re-enabled later
- gosimple # specializes in simplifying code, subset of staticcheck binary.
- gosec
- gosimple
- govet
# - ifshort <- questionable value, unclear if globally helping readability.
- importas
- ineffassign
# - ireturn <- disabled because we want to return interfaces
# - lll <- disabled as it is a bit much. Maybe we have a desired limit?
- makezero
- misspell
- nakedret
# - nestif <- ?
# - nilerr <- needs go 1.18 support
- nilnil
# - nlreturn <- disabled as it doesn't auto-fix something simple and doesn't add anything useful
# - noctx <- needs go 1.18 support
# - nolintlint <- disabled because we use nolint in some places
- nolintlint
- paralleltest
# - prealloc <- disabled because it makes simple code complicated
# - predeclared <- later
- promlinter
# - 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 # set of rules from staticcheck, subset of staticcheck binary.
- stylecheck # replacement of golint, subset of staticcheck binary.
# - tagliatelle <- disabled for defying cosmos idiom
- revive
- staticcheck
- stylecheck
- tenv
- testpackage
# - thelper <- later
# - tparallel <- needs go 1.18 support
- typecheck
- unconvert
# - unparam <- looks for unused parameters (enable later)
- unused # looks for unused variables, subset of staticcheck binary.
# - varnamelen <- disabled because defies idiom
# - wastedassign
- unparam
- unused
- whitespace
# - wrapcheck
# - wsl

issues:
exclude:
- "var-naming"
- "poolId should be poolID"
- "lockId should be lockID"
- "gaugeId should be gaugeID"
- "nodeNameToId should be nodeNameToID"
- "lastCommitId should be lastCommitID"
- "latestPoolId should be latestPoolID"
- "poolIDStr should be poolIDStr"
- "chainId should be chainID"
- "portId should be portID"
- "setNextPoolId should be setNextPoolID"
- "getNextPoolId should be getNextPoolID"
exclude-rules:
- path: bench_test\.go
linters:
- errcheck
- path: client/docs
linters:
- all
- path: x/gamm/pool-models/stableswap
linters:
# Stableswap is in development.
# We should re-enable deadcode and unused linting
# across its files, once stableswap is fully complete.
- unused
- deadcode
- linters:
- staticcheck
- staticcheck
text: "SA1024: cutset contains duplicate characters" # proved to not provide much value, only false positives.
- linters:
- staticcheck
- staticcheck
text: "SA9004: only the first constant in this group has an explicit type" # explicitly recommended in go syntax
- linters:
- stylecheck
- stylecheck
text: "ST1003:" # requires identifiers with "id" to be "ID".
- linters:
- stylecheck
- stylecheck
- revive
text: "ST1005:" # punctuation in error messages
- linters:
- nolintlint
text: "should be written without leading space as" # conflicts with gofumpt
max-issues-per-linter: 10000
max-same-issues: 10000
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"tabnine.experimentalAutoImports": true,
"go.lintTool": "golangci-lint",
"go.formatTool": "goimports",
"go.formatTool": "gofumpt",
"go.useLanguageServer": true,
"[go.mod]": {
"editor.formatOnSave": true,
Expand All @@ -24,4 +24,4 @@
"editor.defaultFormatter": "xaver.clang-format"
},
"clang-format.style": "{BasedOnStyle: Google, IndentWidth: 2, ColumnLimit: 120, AlignConsecutiveAssignments: true, AlignConsecutiveDeclarations: true, SpacesInSquareBrackets: true}"
}
}
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
v7 "github.com/osmosis-labs/osmosis/v12/app/upgrades/v7"
v8 "github.com/osmosis-labs/osmosis/v12/app/upgrades/v8"
v9 "github.com/osmosis-labs/osmosis/v12/app/upgrades/v9"
_ "github.com/osmosis-labs/osmosis/v12/client/docs/statik"
_ "github.com/osmosis-labs/osmosis/v12/client/docs/statik" // imports statik file system for swagger UI support
"github.com/osmosis-labs/osmosis/v12/simulation/simtypes"
)

Expand Down
2 changes: 1 addition & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (
// IBC Transfer: Defines the "transfer" IBC port
transfer "github.com/cosmos/ibc-go/v3/modules/apps/transfer"

_ "github.com/osmosis-labs/osmosis/v12/client/docs/statik"
_ "github.com/osmosis-labs/osmosis/v12/client/docs/statik" // Import statik for docs
owasm "github.com/osmosis-labs/osmosis/v12/wasmbinding"
epochskeeper "github.com/osmosis-labs/osmosis/v12/x/epochs/keeper"
epochstypes "github.com/osmosis-labs/osmosis/v12/x/epochs/types"
Expand Down
2 changes: 1 addition & 1 deletion app/keepers/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
ica "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts"

_ "github.com/osmosis-labs/osmosis/v12/client/docs/statik"
_ "github.com/osmosis-labs/osmosis/v12/client/docs/statik" // import statik for docs
"github.com/osmosis-labs/osmosis/v12/x/epochs"
"github.com/osmosis-labs/osmosis/v12/x/gamm"
"github.com/osmosis-labs/osmosis/v12/x/incentives"
Expand Down
4 changes: 2 additions & 2 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

appparams "github.com/osmosis-labs/osmosis/v12/app/params"
_ "github.com/osmosis-labs/osmosis/v12/client/docs/statik"
_ "github.com/osmosis-labs/osmosis/v12/client/docs/statik" // Import statik for docs
"github.com/osmosis-labs/osmosis/v12/osmoutils/partialord"
"github.com/osmosis-labs/osmosis/v12/simulation/simtypes"
"github.com/osmosis-labs/osmosis/v12/x/epochs"
Expand Down Expand Up @@ -217,7 +217,7 @@ func OrderInitGenesis(allModuleNames []string) []string {
func createSimulationManager(
app *OsmosisApp,
encodingConfig appparams.EncodingConfig,
skipGenesisInvariants bool,
skipGenesisInvariants bool, //nolint:unparam
) *simtypes.Manager {
appCodec := encodingConfig.Marshaler

Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/v5/whitelist_feetokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// We nolint because these are strings of whitelisted ibc denoms.
//
//nolint:gosec
var feetoken_whitelist_data = `
var feetokenWhitelistData = `
ion,uion,2
atom,ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2,1
akt,ibc/1480B8FD20AD5FCAE81EA87584D269547DD4D436843C1D20F15E00EB64743EF4,3
Expand All @@ -43,7 +43,7 @@ boot,ibc/FE2CD1E6828EC0FAB8AF39BAC45BC25B965BA67CCBC50C13A14BD610B0D1E2C4,597
`

func InitialWhitelistedFeetokens(ctx sdk.Context, gamm *gammkeeper.Keeper) []types.FeeToken {
r := csv.NewReader(strings.NewReader(feetoken_whitelist_data))
r := csv.NewReader(strings.NewReader(feetokenWhitelistData))
assets, err := r.ReadAll()
if err != nil {
panic(err)
Expand Down
3 changes: 2 additions & 1 deletion app/upgrades/v8/msg_filter_ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"

superfluidtypes "github.com/osmosis-labs/osmosis/v12/x/superfluid/types"
)

Expand All @@ -26,7 +27,7 @@ func (mfd MsgFilterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo

func hasInvalidMsgs(msgs []sdk.Msg) bool {
for _, msg := range msgs {
switch msg.(type) {
switch msg.(type) { //nolint:gocritic // no reason to rewrite to an if statement
case *superfluidtypes.MsgUnPoolWhitelistedPool:
return true
}
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v9/msg_filter_ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (mfd MsgFilterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo

func hasInvalidMsgs(msgs []sdk.Msg) bool {
for _, msg := range msgs {
switch msg.(type) {
switch msg.(type) { //nolint:gocritic // no reason to rewrite to an if statement.
case *ibcchanneltypes.MsgTimeoutOnClose:
return true
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/osmosisd/cmd/balances_from_state_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ Example:
return fmt.Errorf("failed to marshal snapshot: %w", err)
}

err = os.WriteFile(snapshotOutput, snapshotJSON, 0o644)
err = os.WriteFile(snapshotOutput, snapshotJSON, 0o600)
return err
},
}
Expand Down
29 changes: 14 additions & 15 deletions cmd/osmosisd/cmd/forceprune.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (

const (
batchMaxSize = 1000
kValidators = "validatorsKey:"
kConsensusParams = "consensusParamsKey:"
kABCIResponses = "abciResponsesKey:"
Validators = "validatorsKey:"
ConsensusParams = "consensusParamsKey:"
ABCIResponses = "abciResponsesKey:"
fullHeight = "full_height"
minHeight = "min_height"
defaultFullHeight = "188000"
Expand Down Expand Up @@ -102,15 +102,14 @@ func pruneBlockStoreAndGetHeights(dbPath string, fullHeight int64) (
DisableSeeksCompaction: true,
}

db_bs, err := tmdb.NewGoLevelDBWithOpts("blockstore", dbPath, &opts)
blockstore, err := tmdb.NewGoLevelDBWithOpts("blockstore", dbPath, &opts)
if err != nil {
return 0, 0, err
}

// nolint: staticcheck
defer db_bs.Close()
defer blockstore.Close()

bs := tmstore.NewBlockStore(db_bs)
bs := tmstore.NewBlockStore(blockstore)
startHeight = bs.Base()
currentHeight = bs.Height()

Expand All @@ -125,7 +124,7 @@ func pruneBlockStoreAndGetHeights(dbPath string, fullHeight int64) (
// 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 {
if err := blockstore.Close(); err != nil {
return 0, 0, err
}

Expand Down Expand Up @@ -165,24 +164,24 @@ func forcepruneStateStore(dbPath string, startHeight, currentHeight, minHeight,
}
defer db.Close()

stateDBKeys := []string{kValidators, kConsensusParams, kABCIResponses}
stateDBKeys := []string{Validators, ConsensusParams, ABCIResponses}
fmt.Println("Pruning State Store ...")
for i, s := range stateDBKeys {
fmt.Println(i, s)

retain_height := int64(0)
if s == kABCIResponses {
retain_height = currentHeight - minHeight
retainHeight := int64(0)
if s == ABCIResponses {
retainHeight = currentHeight - minHeight
} else {
retain_height = currentHeight - fullHeight
retainHeight = currentHeight - fullHeight
}

batch := new(leveldb.Batch)
curBatchSize := uint64(0)

fmt.Println(startHeight, currentHeight, retain_height)
fmt.Println(startHeight, currentHeight, retainHeight)

for c := startHeight; c < retain_height; c++ {
for c := startHeight; c < retainHeight; c++ {
batch.Delete([]byte(s + strconv.FormatInt(c, 10)))
curBatchSize++

Expand Down
4 changes: 1 addition & 3 deletions cmd/osmosisd/cmd/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import (
)

// PrepareGenesisCmd returns prepare-genesis cobra Command.
//
//nolint:ineffassign
func PrepareGenesisCmd(defaultNodeHome string, mbm module.BasicManager) *cobra.Command {
cmd := &cobra.Command{
Use: "prepare-genesis",
Expand Down Expand Up @@ -67,7 +65,7 @@ Example:
// get genesis params
var genesisParams GenesisParams
network := args[0]
if network == "testnet" {
if network == "testnet" { //nolint:gocritic // no reason to rewrite this into a switch statement.
genesisParams = TestnetGenesisParams()
} else if network == "mainnet" {
genesisParams = MainnetGenesisParams()
Expand Down
2 changes: 1 addition & 1 deletion cmd/osmosisd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func calculateIP(ip string, i int) (string, error) {
}

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

err := tmos.EnsureDir(writePath, 0o755)
Expand Down
13 changes: 6 additions & 7 deletions osmomath/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
var powPrecision, _ = sdk.NewDecFromStr("0.00000001")

// Singletons.
// nolint: deadcode, unused
// nolint: unused
var zero sdk.Dec = sdk.ZeroDec()

var (
one_half sdk.Dec = sdk.MustNewDecFromStr("0.5")
one sdk.Dec = sdk.OneDec()
two sdk.Dec = sdk.MustNewDecFromStr("2")
oneHalf sdk.Dec = sdk.MustNewDecFromStr("0.5")
one sdk.Dec = sdk.OneDec()
two sdk.Dec = sdk.MustNewDecFromStr("2")
)

// Returns the internal "power precision".
Expand All @@ -37,9 +37,8 @@ func GetPowPrecision() sdk.Dec {
func AbsDifferenceWithSign(a, b sdk.Dec) (sdk.Dec, bool) {
if a.GTE(b) {
return a.SubMut(b), false
} else {
return a.NegMut().AddMut(b), true
}
return a.NegMut().AddMut(b), true
}

// func largeBasePow(base sdk.Dec, exp sdk.Dec) sdk.Dec {
Expand Down Expand Up @@ -94,7 +93,7 @@ func PowApprox(base sdk.Dec, exp sdk.Dec, precision sdk.Dec) sdk.Dec {

// Common case optimization
// Optimize for it being equal to one-half
if exp.Equal(one_half) {
if exp.Equal(oneHalf) {
output, err := base.ApproxSqrt()
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion osmomath/sigfig_round.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func SigFigRound(d sdk.Dec, tenToSigFig sdk.Int) sdk.Dec {
// take note of floor div, vs normal div
k := uint64(0)
dTimesK := d
for ; dTimesK.LT(pointOne); k += 1 {
for ; dTimesK.LT(pointOne); k++ {
dTimesK.MulInt64Mut(10)
}
// d * 10^k * 10^sigfig
Expand Down
Loading