diff --git a/.golangci.yml b/.golangci.yml index b672a52652..9ccc39b8e2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,16 +6,25 @@ linters: disable: - gocyclo - gochecknoinits - - golint - gochecknoglobals - dupl - interfacer - - gosec - unparam - lll - maligned - nakedret - errcheck - scopelint - - prealloc - varcheck + +issues: + exclude-rules: + - text: "Use of weak random number generator" + linters: + - gosec + - text: "comment on exported var" + linters: + - golint + - text: "don't use an underscore in package name" + linters: + - golint diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index f284cc9030..6053937df3 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -631,8 +631,8 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (result sdk func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (result sdk.Result) { msgLogs := make(sdk.ABCIMessageLogs, 0, len(msgs)) + data := make([]byte, 0, len(msgs)) var ( - data []byte code sdk.CodeType codespace sdk.CodespaceType ) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index d9c9fd3dce..46ac690829 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -540,7 +540,7 @@ func (msg msgCounter) ValidateBasic() sdk.Error { } func newTxCounter(txInt int64, msgInts ...int64) *txTest { - var msgs []sdk.Msg + msgs := make([]sdk.Msg, 0, len(msgInts)) for _, msgInt := range msgInts { msgs = append(msgs, msgCounter{msgInt, false}) } diff --git a/server/mock/store.go b/server/mock/store.go index 03c01c0940..bf8e66a4dc 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -19,7 +19,7 @@ func (ms multiStore) CacheMultiStore() sdk.CacheMultiStore { panic("not implemented") } -func (kv multiStore) CacheMultiStoreWithVersion(_ int64) (sdk.CacheMultiStore, error) { +func (ms multiStore) CacheMultiStoreWithVersion(_ int64) (sdk.CacheMultiStore, error) { panic("not implemented") } diff --git a/types/errors/errors.go b/types/errors/errors.go index 77cd698f18..642c433d90 100644 --- a/types/errors/errors.go +++ b/types/errors/errors.go @@ -153,23 +153,23 @@ func (e Error) Codespace() string { // Is check if given error instance is of a given kind/type. This involves // unwrapping given error using the Cause method if available. -func (kind *Error) Is(err error) bool { +func (e *Error) Is(err error) bool { // Reflect usage is necessary to correctly compare with // a nil implementation of an error. - if kind == nil { + if e == nil { return isNilErr(err) } for { - if err == kind { + if err == e { return true } // If this is a collection of errors, this function must return // true if at least one from the group match. if u, ok := err.(unpacker); ok { - for _, e := range u.Unpack() { - if kind.Is(e) { + for _, er := range u.Unpack() { + if e.Is(er) { return true } } diff --git a/types/events.go b/types/events.go index 87c95c3bab..019a53f1f6 100644 --- a/types/events.go +++ b/types/events.go @@ -174,11 +174,8 @@ func (se StringEvents) Flatten() StringEvents { for _, e := range se { flatEvents[e.Type] = append(flatEvents[e.Type], e.Attributes...) } - - var ( - res StringEvents - keys []string - ) + keys := make([]string, 0, len(flatEvents)) + res := make(StringEvents, 0, len(flatEvents)) // appeneded to keys, same length of what is allocated to keys for ty := range flatEvents { keys = append(keys, ty) @@ -209,7 +206,7 @@ func StringifyEvent(e abci.Event) StringEvent { // StringifyEvents converts a slice of Event objects into a slice of StringEvent // objects. func StringifyEvents(events []abci.Event) StringEvents { - var res StringEvents + res := make(StringEvents, 0, len(events)) for _, e := range events { res = append(res, StringifyEvent(e)) diff --git a/types/module/module.go b/types/module/module.go index 89b8d92715..924c998342 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -201,7 +201,7 @@ type Manager struct { func NewManager(modules ...AppModule) *Manager { moduleMap := make(map[string]AppModule) - var modulesStr []string + modulesStr := make([]string, 0, len(modules)) for _, module := range modules { moduleMap[module.Name()] = module modulesStr = append(modulesStr, module.Name()) diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index 9e71b1127d..945d9afd86 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -168,7 +168,7 @@ type StdSignDoc struct { // StdSignBytes returns the bytes to sign for a transaction. func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, msgs []sdk.Msg, memo string) []byte { - var msgsBytes []json.RawMessage + msgsBytes := make([]json.RawMessage, 0, len(msgs)) for _, msg := range msgs { msgsBytes = append(msgsBytes, json.RawMessage(msg.GetSignBytes())) } diff --git a/x/distribution/client/common/common.go b/x/distribution/client/common/common.go index 077933f037..44c08e8d5f 100644 --- a/x/distribution/client/common/common.go +++ b/x/distribution/client/common/common.go @@ -108,7 +108,7 @@ func WithdrawAllDelegatorRewards(cliCtx context.CLIContext, queryRoute string, d } // build multi-message transaction - var msgs []sdk.Msg + msgs := make([]sdk.Msg, 0, len(validators)) for _, valAddr := range validators { msg := types.NewMsgWithdrawDelegatorReward(delegatorAddr, valAddr) if err := msg.ValidateBasic(); err != nil { diff --git a/x/genutil/client/cli/migrate.go b/x/genutil/client/cli/migrate.go index 3702b8a87e..5d2e69abd3 100644 --- a/x/genutil/client/cli/migrate.go +++ b/x/genutil/client/cli/migrate.go @@ -28,7 +28,7 @@ var migrationMap = extypes.MigrationMap{ const ( flagGenesisTime = "genesis-time" - flagChainId = "chain-id" + flagChainID = "chain-id" ) func MigrateGenesisCmd(_ *server.Context, cdc *codec.Codec) *cobra.Command { @@ -72,9 +72,9 @@ $ %s migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2 genDoc.GenesisTime = t } - chainId := cmd.Flag(flagChainId).Value.String() - if chainId != "" { - genDoc.ChainID = chainId + chainID := cmd.Flag(flagChainID).Value.String() + if chainID != "" { + genDoc.ChainID = chainID } out, err := cdc.MarshalJSONIndent(genDoc, "", " ") @@ -88,7 +88,7 @@ $ %s migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2 } cmd.Flags().String(flagGenesisTime, "", "Override genesis_time with this flag") - cmd.Flags().String(flagChainId, "", "Override chain_id with this flag") + cmd.Flags().String(flagChainID, "", "Override chain_id with this flag") return cmd } diff --git a/x/genutil/client/cli/migrate_test.go b/x/genutil/client/cli/migrate_test.go index 4df0ebdbbc..de83d3d2a5 100644 --- a/x/genutil/client/cli/migrate_test.go +++ b/x/genutil/client/cli/migrate_test.go @@ -17,7 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/tests" ) -func setupCmd(genesisTime string, chainId string) *cobra.Command { +func setupCmd(genesisTime string, chainID string) *cobra.Command { c := &cobra.Command{ Use: "c", Args: cobra.ArbitraryArgs, @@ -25,7 +25,7 @@ func setupCmd(genesisTime string, chainId string) *cobra.Command { } c.Flags().String(flagGenesisTime, genesisTime, "") - c.Flags().String(flagChainId, chainId, "") + c.Flags().String(flagChainID, chainID, "") return c } diff --git a/x/genutil/gentx.go b/x/genutil/gentx.go index c9f55c3e84..dce958f063 100644 --- a/x/genutil/gentx.go +++ b/x/genutil/gentx.go @@ -22,7 +22,7 @@ func SetGenTxsInAppGenesisState(cdc *codec.Codec, appGenesisState map[string]jso genesisState := GetGenesisStateFromAppState(cdc, appGenesisState) // convert all the GenTxs to JSON - var genTxsBz []json.RawMessage + genTxsBz := make([]json.RawMessage, 0, len(genTxs)) for _, genTx := range genTxs { txBz, err := cdc.MarshalJSON(genTx) if err != nil { diff --git a/x/gov/module.go b/x/gov/module.go index bbcd22498a..26b238f1e9 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -69,7 +69,7 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { // RegisterRESTRoutes registers the REST routes for the gov module. func (a AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) { - var proposalRESTHandlers []rest.ProposalRESTHandler + proposalRESTHandlers := make([]rest.ProposalRESTHandler, 0, len(a.proposalHandlers)) for _, proposalHandler := range a.proposalHandlers { proposalRESTHandlers = append(proposalRESTHandlers, proposalHandler.RESTHandler(ctx)) } @@ -80,7 +80,7 @@ func (a AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Rout // GetTxCmd returns the root tx command for the gov module. func (a AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { - var proposalCLIHandlers []*cobra.Command + proposalCLIHandlers := make([]*cobra.Command, 0, len(a.proposalHandlers)) for _, proposalHandler := range a.proposalHandlers { proposalCLIHandlers = append(proposalCLIHandlers, proposalHandler.CLIHandler(cdc)) }