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 main branch #1272

Closed
wants to merge 19 commits into from
61 changes: 32 additions & 29 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,66 @@
run:
tests: false
tests: true
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- errcheck
- exportloopref
- goconst
- gocritic
- gofmt
- goimports
- revive
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- prealloc
- exportloopref
- nolintlint
- revive
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck

issues:
exclude-rules:
- text: "simtypes"
linters:
- staticcheck
- text: "Use of weak random number generator"
linters:
- gosec
- 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
- path: "migrations"
text: "SA1019:"
linters:
- staticcheck

max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
dogsled:
max-blank-identifiers: 3
errcheck:
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: true
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
golint:
# minimal confidence for issues, default is 0.8
min-confidence: 0
prealloc:
# XXX: we don't recommend using this linter before doing performance profiling.
# For most programs usage of prealloc will be a premature optimization.
revive:
enableAllRules: true
# When set to false, ignores files with "GENERATED" header, similar to golint
ignoreGeneratedHeader: true

# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
# True by default.
simple: false
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: true # Report preallocation suggestions on for loops, false by default
nolintlint:
allow-unused: false
allow-leading-space: true
require-explanation: false
require-specific: false
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ var (
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
append(
wasmclient.ProposalHandlers, //nolint:staticcheck
wasmclient.ProposalHandlers,
paramsclient.ProposalHandler,
distrclient.ProposalHandler,
upgradeclient.ProposalHandler,
Expand Down Expand Up @@ -236,7 +236,7 @@ var (
// WasmApp extended ABCI application
type WasmApp struct {
*baseapp.BaseApp
legacyAmino *codec.LegacyAmino //nolint:staticcheck
legacyAmino *codec.LegacyAmino
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry

Expand Down Expand Up @@ -862,7 +862,7 @@ func (app *WasmApp) ModuleAccountAddrs() map[string]bool {
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *WasmApp) LegacyAmino() *codec.LegacyAmino { //nolint:staticcheck
func (app *WasmApp) LegacyAmino() *codec.LegacyAmino {
return app.legacyAmino
}

Expand Down
21 changes: 1 addition & 20 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
)

var emptyWasmOpts []wasm.Option = nil
var emptyWasmOpts []wasm.Option

func TestWasmdExport(t *testing.T) {
db := db.NewMemDB()
Expand Down Expand Up @@ -89,22 +89,3 @@ func TestGetEnabledProposals(t *testing.T) {
})
}
}

func setGenesis(gapp *WasmApp) error {
genesisState := NewDefaultGenesisState()
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil {
return err
}

// Initialize the chain
gapp.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
},
)

gapp.Commit()
return nil
}
4 changes: 2 additions & 2 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [

// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) //nolint:errcheck
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
return false
})

Expand All @@ -89,7 +89,7 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
if err != nil {
panic(err)
}
_, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) //nolint:errcheck
_, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr)
}

// clear validator slash events
Expand Down
2 changes: 1 addition & 1 deletion app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestAppImportExport(t *testing.T) {

t.Log("importing genesis...")

_, newDB, newDir, _, _, err := SetupSimulation("leveldb-app-sim-2", "Simulation-2")
_, newDB, newDir, _, _, err := SetupSimulation("leveldb-app-sim-2", "Simulation-2") //nolint:dogsled
require.NoError(t, err, "simulation setup failed")

defer func() {
Expand Down
2 changes: 1 addition & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func NewPubKeyFromHex(pk string) (res cryptotypes.PubKey) {
type EmptyBaseAppOptions struct{}

// Get implements AppOptions
func (ao EmptyBaseAppOptions) Get(o string) interface{} {
func (ao EmptyBaseAppOptions) Get(_ string) interface{} {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions benchmarks/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo {
}
storeTx, err := helpers.GenTx(txGen, []sdk.Msg{&storeMsg}, nil, 55123123, "", []uint64{0}, []uint64{0}, minter)
require.NoError(b, err)
_, res, err := wasmApp.Deliver(txGen.TxEncoder(), storeTx)
_, _, err = wasmApp.Deliver(txGen.TxEncoder(), storeTx)
require.NoError(b, err)
codeID := uint64(1)

Expand Down Expand Up @@ -161,7 +161,7 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo {
gasWanted := 500000 + 10000*uint64(numAccounts)
initTx, err := helpers.GenTx(txGen, []sdk.Msg{&initMsg}, nil, gasWanted, "", []uint64{0}, []uint64{1}, minter)
require.NoError(b, err)
_, res, err = wasmApp.Deliver(txGen.TxEncoder(), initTx)
_, res, err := wasmApp.Deliver(txGen.TxEncoder(), initTx)
require.NoError(b, err)

// TODO: parse contract address better
Expand Down Expand Up @@ -202,7 +202,7 @@ func GenSequenceOfTxs(b testing.TB, info *AppInfo, msgGen func(*AppInfo) ([]sdk.
info.MinterKey,
)
require.NoError(b, err)
info.SeqNum += 1
info.SeqNum++
}

return txs
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func buildTxFromMsg(builder func(info *AppInfo) ([]sdk.Msg, error)) func(b *test
}
}

func buildMemDB(b *testing.B) dbm.DB {
func buildMemDB(_ *testing.B) dbm.DB {
return dbm.NewMemDB()
}

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/ica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestICA(t *testing.T) {
ownerAddr := sdk.AccAddress(controllerChain.SenderPrivKey.PubKey().Address())
msg := intertxtypes.NewMsgRegisterAccount(ownerAddr.String(), path.EndpointA.ConnectionID, "")
res, err := controllerChain.SendMsgs(msg)
require.NoError(t, err)
chanID, portID, version := parseIBCChannelEvents(t, res)

// next open channels on both sides
Expand Down Expand Up @@ -69,7 +70,7 @@ func TestICA(t *testing.T) {
payloadMsg := banktypes.NewMsgSend(icaAddr, targetAddr, sdk.NewCoins(sendCoin))
msg2, err := intertxtypes.NewMsgSubmitTx(payloadMsg, path.EndpointA.ConnectionID, ownerAddr.String())
require.NoError(t, err)
res, err = controllerChain.SendMsgs(msg2)
_, err = controllerChain.SendMsgs(msg2)
require.NoError(t, err)

assert.Equal(t, 1, len(controllerChain.PendingSendPackets))
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/alias.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// nolint
//nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/Cosmwasm/wasmd/x/wasm/types
Expand Down
5 changes: 1 addition & 4 deletions x/wasm/client/cli/gov_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,7 @@ func ProposalUpdateContractAdminCmd() *cobra.Command {
return err
}

src, err := parseUpdateContractAdminArgs(args, clientCtx)
if err != nil {
return err
}
src := parseUpdateContractAdminArgs(args, clientCtx)

content := types.UpdateAdminProposal{
Title: proposalTitle,
Expand Down
10 changes: 4 additions & 6 deletions x/wasm/client/cli/new_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ func UpdateContractAdminCmd() *cobra.Command {
return err
}

msg, err := parseUpdateContractAdminArgs(args, clientCtx)
if err != nil {
return err
}
msg := parseUpdateContractAdminArgs(args, clientCtx)

if err := msg.ValidateBasic(); err != nil {
return err
}
Expand All @@ -86,13 +84,13 @@ func UpdateContractAdminCmd() *cobra.Command {
return cmd
}

func parseUpdateContractAdminArgs(args []string, cliCtx client.Context) (types.MsgUpdateAdmin, error) {
func parseUpdateContractAdminArgs(args []string, cliCtx client.Context) types.MsgUpdateAdmin {
msg := types.MsgUpdateAdmin{
Sender: cliCtx.GetFromAddress().String(),
Contract: args[0],
NewAdmin: args[1],
}
return msg, nil
return msg
}

// ClearContractAdminCmd clears an admin for a contract
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/client/rest/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func toStdTxResponse(cliCtx client.Context, w http.ResponseWriter, data wasmProp
tx.WriteGeneratedTxResponse(cliCtx, w, baseReq, msg)
}

func EmptyRestHandler(cliCtx client.Context) govrest.ProposalRESTHandler {
func EmptyRestHandler(_ client.Context) govrest.ProposalRESTHandler {
return govrest.ProposalRESTHandler{
SubRoute: "unsupported",
Handler: func(w http.ResponseWriter, r *http.Request) {
Expand Down
11 changes: 6 additions & 5 deletions x/wasm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func TestInitGenesis(t *testing.T) {
creator := data.faucet.NewFundedRandomAccount(data.ctx, deposit.Add(deposit...)...)
fred := data.faucet.NewFundedRandomAccount(data.ctx, topUp...)

h := data.module.Route().Handler()
q := data.module.LegacyQuerierHandler(nil)
h := data.module.Route().Handler() //nolint:staticcheck
q := data.module.LegacyQuerierHandler(nil) //nolint:staticcheck

msg := MsgStoreCode{
Sender: creator.String(),
Expand All @@ -30,7 +30,7 @@ func TestInitGenesis(t *testing.T) {
require.NoError(t, err)
assertStoreCodeResponse(t, res.Data, 1)

_, _, bob := keyPubAddr()
bob := keyPubAddr()
initMsg := initMsg{
Verifier: fred,
Beneficiary: bob,
Expand Down Expand Up @@ -77,10 +77,11 @@ func TestInitGenesis(t *testing.T) {

// create new app to import genstate into
newData := setupTest(t)
q2 := newData.module.LegacyQuerierHandler(nil)
q2 := newData.module.LegacyQuerierHandler(nil) //nolint:staticcheck

// initialize new app with genstate
InitGenesis(newData.ctx, &newData.keeper, *genState)
_, err = InitGenesis(newData.ctx, &newData.keeper, *genState)
require.NoError(t, err)

// run same checks again on newdata, to make sure it was reinitialized correctly
assertCodeList(t, q2, newData.ctx, 1)
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewHandler(k types.ContractOpsKeeper) sdk.Handler {
err error
)
switch msg := msg.(type) {
case *MsgStoreCode: //nolint:typecheck
case *MsgStoreCode:
res, err = msgServer.StoreCode(sdk.WrapSDKContext(ctx), msg)
case *MsgInstantiateContract:
res, err = msgServer.InstantiateContract(sdk.WrapSDKContext(ctx), msg)
Expand Down
Loading