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

make the linter config attractive #3486

Merged
merged 8 commits into from
Dec 17, 2022
Merged
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
71 changes: 11 additions & 60 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
run:
tests: false
# # timeout for analysis, e.g. 30s, 5m, default is 1m
# timeout: 5m
timeout: 5m

linters:
disable-all: true
Expand All @@ -10,88 +9,40 @@ 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
- goheader
- goimports
# - gomoddirectives <- disables replaces
# - gofumpt
- goheader
- gomodguard
- goprintffuncname
# - gosec <- triggers too much for this round and should be re-enabled later
- gosimple # specializes in simplifying code, subset of staticcheck binary.
- 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
- 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
- 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
- unused
- whitespace
# - wrapcheck
# - wsl

issues:
exclude-rules:
- path: bench_test\.go
linters:
- errcheck
- path: client/docs
linters:
- all
- path: x/gamm/pool-models/stableswap
linters:
# Stableswap is in development.
Expand All @@ -100,16 +51,16 @@ issues:
- 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
text: "ST1005:" # punctuation in error messages
max-issues-per-linter: 10000
max-same-issues: 10000
4 changes: 1 addition & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,8 @@ func NewOsmosisApp(

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)

// Uncomment this for debugging contracts. In the future this could be made into a param passed by the tests
//wasmConfig.ContractDebugMode = true

// wasmConfig.ContractDebugMode = true
if err != nil {
panic(fmt.Sprintf("error while reading wasm config: %s", err))
}
Expand Down
2 changes: 1 addition & 1 deletion app/apptesting/gamm.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (s *KeeperTestHelper) PrepareBalancerPoolWithPoolAsset(assets []balancer.Po
// Modify spotprice of a pool to target spotprice
func (s *KeeperTestHelper) ModifySpotPrice(poolID uint64, targetSpotPrice sdk.Dec, baseDenom string) {
var quoteDenom string
var int64Max = int64(^uint64(0) >> 1)
int64Max := int64(^uint64(0) >> 1)

s.Require().Positive(targetSpotPrice)
s.Require().Greater(gammtypes.MaxSpotPrice, targetSpotPrice)
Expand Down
4 changes: 1 addition & 3 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/std"
)

var (
encodingConfig params.EncodingConfig = MakeEncodingConfig()
)
var encodingConfig params.EncodingConfig = MakeEncodingConfig()

func GetEncodingConfig() params.EncodingConfig {
return encodingConfig
Expand Down
3 changes: 1 addition & 2 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
func (appKeepers *AppKeepers) WireICS20PreWasmKeeper(
appCodec codec.Codec,
bApp *baseapp.BaseApp,
hooksKeeper *ibchookskeeper.Keeper,
) {
hooksKeeper *ibchookskeeper.Keeper) {
// Setup the ICS4Wrapper used by the hooks middleware
wasmHooks := ibchooks.NewWasmHooks(hooksKeeper, nil) // The contract keeper needs to be set later
appKeepers.Ics20WasmHooks = &wasmHooks
Expand Down
6 changes: 4 additions & 2 deletions cmd/osmosisd/cmd/balances_from_state_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

const FlagSelectPoolIds = "breakdown-by-pool-ids"
const FlagMinimumStakeAmount = "minimum-stake-amount"
const (
FlagSelectPoolIds = "breakdown-by-pool-ids"
FlagMinimumStakeAmount = "minimum-stake-amount"
)

type DeriveSnapshot struct {
NumberAccounts uint64 `json:"num_accounts"`
Expand Down
1 change: 0 additions & 1 deletion cmd/osmosisd/cmd/forceprune.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func pruneBlockStoreAndGetHeights(dbPath string, fullHeight int64) (
return 0, 0, err
}

// nolint: staticcheck
defer db_bs.Close()

bs := tmstore.NewBlockStore(db_bs)
Expand Down
2 changes: 1 addition & 1 deletion cmd/osmosisd/cmd/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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
2 changes: 1 addition & 1 deletion osmoutils/module_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func CanCreateModuleAccountAtAddr(ctx sdk.Context, ak AccountKeeper, addr sdk.Ac
return fmt.Errorf("cannot create module account %s, "+
"due to an account at that address already existing & having sent txs", addr)
}
var overrideAccountTypes = map[reflect.Type]struct{}{
overrideAccountTypes := map[reflect.Type]struct{}{
reflect.TypeOf(&authtypes.BaseAccount{}): {},
reflect.TypeOf(&vestingtypes.DelayedVestingAccount{}): {},
reflect.TypeOf(&vestingtypes.ContinuousVestingAccount{}): {},
Expand Down
9 changes: 6 additions & 3 deletions osmoutils/osmocli/query_cmd_wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ func BuildQueryCli[reqP proto.Message, querier any](desc *QueryDescriptor, newQu
// with just the "Query" and "Request" args chopped off.
// It expects all proto fields to appear as arguments, in order.
func SimpleQueryCmd[reqP proto.Message, querier any](use string, short string, long string,
moduleName string, newQueryClientFn func(grpc1.ClientConn) querier) *cobra.Command {
moduleName string, newQueryClientFn func(grpc1.ClientConn) querier,
) *cobra.Command {
desc := QueryDescriptor{
Use: use,
Short: short,
Expand All @@ -122,7 +123,8 @@ func SimpleQueryCmd[reqP proto.Message, querier any](use string, short string, l
}

func GetParams[reqP proto.Message, querier any](moduleName string,
newQueryClientFn func(grpc1.ClientConn) querier) *cobra.Command {
newQueryClientFn func(grpc1.ClientConn) querier,
) *cobra.Command {
return BuildQueryCli[reqP](&QueryDescriptor{
Use: "params [flags]",
Short: fmt.Sprintf("Get the params for the x/%s module", moduleName),
Expand Down Expand Up @@ -156,7 +158,8 @@ func callQueryClientFn(ctx context.Context, fnName string, req proto.Message, q
}

func queryLogic[querier any](desc *QueryDescriptor,
newQueryClientFn func(grpc1.ClientConn) querier) func(cmd *cobra.Command, args []string) error {
newQueryClientFn func(grpc1.ClientConn) querier,
) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion simulation/simtypes/txbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func genTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, ch
if err != nil {
panic(err)
}
//nolint:forcetypeassert

sigs[i] = sig
err = txBuilder.SetSignatures(sigs...)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/initialization/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func addAccount(path, moniker, amountStr string, accAddr sdk.AccAddress, forkHei
return genutil.ExportGenesisFile(genDoc, genFile)
}

//nolint:typecheck
func updateModuleGenesis[V proto.Message](appGenState map[string]json.RawMessage, moduleName string, protoVal V, updateGenesis func(V)) error {
if err := util.Cdc.UnmarshalJSON(appGenState[moduleName], protoVal); err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions x/gamm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (q Querier) PoolsWithFilter(ctx context.Context, req *types.QueryPoolsWithF
store := sdkCtx.KVStore(q.Keeper.storeKey)
poolStore := prefix.NewStore(store, types.KeyPrefixPools)

var response = []*codectypes.Any{}
response := []*codectypes.Any{}
pageRes, err := query.FilteredPaginate(poolStore, req.Pagination, func(_, value []byte, accumulate bool) (bool, error) {
pool, err := q.Keeper.UnmarshalPool(value)
if err != nil {
Expand Down Expand Up @@ -214,7 +214,6 @@ func (q Querier) PoolsWithFilter(ctx context.Context, req *types.QueryPoolsWithF

return true, nil
})

if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down
4 changes: 1 addition & 3 deletions x/ibc-rate-limit/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import (
"github.com/osmosis-labs/osmosis/v13/x/ibc-rate-limit/types"
)

var (
_ module.AppModuleBasic = AppModuleBasic{}
)
var _ module.AppModuleBasic = AppModuleBasic{}

type AppModuleBasic struct{}

Expand Down
2 changes: 1 addition & 1 deletion x/lockup/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// REST Variable names
// nolint

const (
LockID = "lock-id"
RestOwnerAddress = "owner"
Expand Down
4 changes: 1 addition & 3 deletions x/protorev/keeper/epoch_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ type LiquidityPoolStruct struct {
PoolId uint64
}

var (
_ epochstypes.EpochHooks = EpochHooks{}
)
var _ epochstypes.EpochHooks = EpochHooks{}

func (k Keeper) EpochHooks() epochstypes.EpochHooks {
return EpochHooks{k}
Expand Down
1 change: 0 additions & 1 deletion x/protorev/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func NewKeeper(
bankKeeper types.BankKeeper,
gammKeeper types.GAMMKeeper,
epochKeeper types.EpochKeeper,

) Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
Expand Down