Skip to content

Commit

Permalink
Add golangci lint check on pull requests (#645)
Browse files Browse the repository at this point in the history
* added golangci lint check on pull requests

* changelog update

* updated to use circleci instead of github actions

* testing a golang change

* added workflow

* updated how we find the golangci command in the make file

* using orb for golangci

* Added golangci install make command

* use docker image for golangci

* stop using make in circleci

* reverted golang change to trigger ci

* gofmt

* make fmt

* fixed a few things

* updated version on golintci

* fixed all the lint errors

* check version

* skipped wrongly failing lint

* Revert generated file changes

* fix import grouping, return errors on failures, initialization of arrays revert

* fixed a few lint errors

* addressed more code review comments

* updated with error check

* increased timeout for golangci-lint

* dont format autogenerated files

Co-authored-by: Carlton Hanna <channa@figure.com>
  • Loading branch information
fkneeland-figure and channa-figure authored Oct 25, 2021
1 parent c34b486 commit 57517b0
Show file tree
Hide file tree
Showing 44 changed files with 282 additions and 243 deletions.
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ jobs:
paths:
- ".git"

lint:
executor: golang
docker:
- image: golangci/golangci-lint:v1.42.1-alpine
steps:
- checkout
- run:
name: Lint
command: |
golangci-lint run --version
golangci-lint run --tests=false --timeout=5m0s
test-cover:
executor: golang
parallelism: 4
Expand Down Expand Up @@ -191,6 +203,9 @@ workflows:
tags:
only:
- /^v.*/
- lint:
requires:
- setup-dependencies
- test-cover:
requires:
- setup-dependencies
Expand Down
16 changes: 9 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
run:
tests: false

linters:
disable-all: true
enable:
- bodyclose
- deadcode
Expand All @@ -9,17 +13,15 @@ linters:
- gocritic
- gofmt
- goimports
- golint
- revive
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- misspell
- maligned
- nakedret
- prealloc
- scopelint
- exportloopref
- staticcheck
- structcheck
- stylecheck
Expand All @@ -40,13 +42,13 @@ issues:
linters-settings:
dogsled:
max-blank-identifiers: 3
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Remove unused flags from command prompt for storing contract [\#647](https://github.com/CosmWasm/wasmd/issues/647)
- Ran `make format` [\#649](https://github.com/CosmWasm/wasmd/issues/649)
- Add golangci lint check to circleci jobs [\620](https://github.com/CosmWasm/wasmd/issues/620)

[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.20.0...HEAD)

Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ test-sim-multi-seed-short: runsim
###############################################################################

lint:
golangci-lint run
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
golangci-lint run --tests=false
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofmt -d -s

format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs goimports -w -local github.com/CosmWasm/wasmd
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" -not -path "*.pb.go" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" -not -path "*.pb.go" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" -not -path "*.pb.go" | xargs goimports -w -local github.com/CosmWasm/wasmd


###############################################################################
Expand Down
11 changes: 3 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,6 @@ var (
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
wasm.ModuleName: {authtypes.Burner},
}

// module accounts that are allowed to receive tokens
allowedReceivingModAcc = map[string]bool{
distrtypes.ModuleName: true,
}
)

// Verify app interface at compile time
Expand All @@ -200,7 +195,7 @@ var (
// WasmApp extended ABCI application
type WasmApp struct {
*baseapp.BaseApp
legacyAmino *codec.LegacyAmino
legacyAmino *codec.LegacyAmino //nolint
appCodec codec.Marshaler
interfaceRegistry types.InterfaceRegistry

Expand Down Expand Up @@ -562,7 +557,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 {
func (app *WasmApp) LegacyAmino() *codec.LegacyAmino { //nolint
return app.legacyAmino
}

Expand Down Expand Up @@ -636,7 +631,7 @@ func GetMaccPerms() map[string][]string {
}

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper {
func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper { //nolint
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

paramsKeeper.Subspace(authtypes.ModuleName)
Expand Down
2 changes: 1 addition & 1 deletion app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Marshaler codec.Marshaler
TxConfig client.TxConfig
Amino *codec.LegacyAmino
Amino *codec.LegacyAmino //nolint
}

func MakeEncodingConfig() EncodingConfig {
Expand Down
10 changes: 8 additions & 2 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ 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())
_, err := app.distrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
if err != nil {
panic(err)
}
return false
})

Expand All @@ -88,7 +91,10 @@ func (app *WasmApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [
if err != nil {
panic(err)
}
_, _ = app.distrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr)
_, err = app.distrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr)
if err != nil {
panic(err)
}
}

// clear validator slash events
Expand Down
18 changes: 12 additions & 6 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,24 @@ func createRandomAccounts(accNum int) []sdk.AccAddress {

// createIncrementalAccounts is a strategy used by addTestAddrs() in order to generated addresses in ascending order.
func createIncrementalAccounts(accNum int) []sdk.AccAddress {
var addresses []sdk.AccAddress
addresses := make([]sdk.AccAddress, 0, accNum)
var buffer bytes.Buffer

// start at 100 so we can make up to 999 test addresses with valid test addresses
for i := 100; i < (accNum + 100); i++ {
numString := strconv.Itoa(i)
buffer.WriteString("A58856F0FD53BF058B4909A21AEC019107BA6") //base address string
buffer.WriteString("A58856F0FD53BF058B4909A21AEC019107BA6") // base address string

buffer.WriteString(numString) //adding on final two digits to make addresses unique
res, _ := sdk.AccAddressFromHex(buffer.String())
buffer.WriteString(numString) // adding on final two digits to make addresses unique
res, err := sdk.AccAddressFromHex(buffer.String())
if err != nil {
panic(err)
}
bech := res.String()
addr, _ := TestAddr(buffer.String(), bech)
addr, err := TestAddr(buffer.String(), bech)
if err != nil {
panic(err)
}

addresses = append(addresses, addr)
buffer.Reset()
Expand Down Expand Up @@ -409,7 +415,7 @@ func incrementAllSequenceNumbers(initSeqNums []uint64) {

// CreateTestPubKeys returns a total of numPubKeys public keys in ascending order.
func CreateTestPubKeys(numPubKeys int) []cryptotypes.PubKey {
var publicKeys []cryptotypes.PubKey
publicKeys := make([]cryptotypes.PubKey, 0, numPubKeys)
var buffer bytes.Buffer

// start at 10 to avoid changing 1 to 01, 2 to 02, etc
Expand Down
20 changes: 16 additions & 4 deletions cmd/wasmd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
addr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
inBuf := bufio.NewReader(cmd.InOrStdin())
keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
keyringBackend, err := cmd.Flags().GetString(flags.FlagKeyringBackend)
if err != nil {
return err
}

// attempt to lookup address from Keybase if no address was provided
kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf)
Expand All @@ -72,9 +75,18 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
return fmt.Errorf("failed to parse coins: %w", err)
}

vestingStart, _ := cmd.Flags().GetInt64(flagVestingStart)
vestingEnd, _ := cmd.Flags().GetInt64(flagVestingEnd)
vestingAmtStr, _ := cmd.Flags().GetString(flagVestingAmt)
vestingStart, err := cmd.Flags().GetInt64(flagVestingStart)
if err != nil {
return err
}
vestingEnd, err := cmd.Flags().GetInt64(flagVestingEnd)
if err != nil {
return err
}
vestingAmtStr, err := cmd.Flags().GetString(flagVestingAmt)
if err != nil {
return err
}

vestingAmt, err := sdk.ParseCoinsNormalized(vestingAmtStr)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions cmd/wasmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import (
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

"github.com/CosmWasm/wasmd/x/wasm"
clientcodec "github.com/CosmWasm/wasmd/x/wasm/client/codec"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/debug"
Expand All @@ -41,6 +38,8 @@ import (
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"

"github.com/CosmWasm/wasmd/app"
"github.com/CosmWasm/wasmd/x/wasm"
clientcodec "github.com/CosmWasm/wasmd/x/wasm/client/codec"
)

// NewRootCmd creates a new root command for wasmd. It is called once in the
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
github.com/tendermint/tm-db v0.6.4
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71
google.golang.org/grpc v1.40.0
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v2 v2.4.0
)

Expand Down
37 changes: 15 additions & 22 deletions x/wasm/client/cli/genesis_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"crypto/sha256"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
Expand All @@ -21,7 +20,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/crypto"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down Expand Up @@ -214,7 +212,7 @@ func GenesisListCodesCmd(defaultNodeHome string, genReader GenesisReader) *cobra
if err != nil {
return err
}
return printJsonOutput(cmd, all)
return printJSONOutput(cmd, all)

},
}
Expand All @@ -237,7 +235,7 @@ func GenesisListContractsCmd(defaultNodeHome string, genReader GenesisReader) *c
}
state := g.WasmModuleState
all := getAllContracts(state)
return printJsonOutput(cmd, all)
return printJSONOutput(cmd, all)
},
}
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
Expand All @@ -246,7 +244,7 @@ func GenesisListContractsCmd(defaultNodeHome string, genReader GenesisReader) *c
}

// clientCtx marshaller works only with proto or bytes so we marshal the output ourself
func printJsonOutput(cmd *cobra.Command, obj interface{}) error {
func printJSONOutput(cmd *cobra.Command, obj interface{}) error {
clientCtx := client.GetClientContextFromCmd(cmd)
bz, err := json.MarshalIndent(obj, "", " ")
if err != nil {
Expand All @@ -261,12 +259,12 @@ type codeMeta struct {
}

func getAllCodes(state *types.GenesisState) ([]codeMeta, error) {
var all []codeMeta
for _, c := range state.Codes {
all = append(all, codeMeta{
all := make([]codeMeta, len(state.Codes))
for i, c := range state.Codes {
all[i] = codeMeta{
CodeID: c.CodeID,
Info: c.CodeInfo,
})
}
}
// add inflight
seq := codeSeqValue(state)
Expand Down Expand Up @@ -304,12 +302,12 @@ type contractMeta struct {
}

func getAllContracts(state *types.GenesisState) []contractMeta {
var all []contractMeta
for _, c := range state.Contracts {
all = append(all, contractMeta{
all := make([]contractMeta, len(state.Contracts))
for i, c := range state.Contracts {
all[i] = contractMeta{
ContractAddress: c.ContractAddress,
Info: c.ContractInfo,
})
}
}
// add inflight
seq := contractSeqValue(state)
Expand Down Expand Up @@ -494,7 +492,10 @@ func getActorAddress(cmd *cobra.Command) (sdk.AccAddress, error) {
return actorAddr, nil
}
inBuf := bufio.NewReader(cmd.InOrStdin())
keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend)
keyringBackend, err := cmd.Flags().GetString(flags.FlagKeyringBackend)
if err != nil {
return nil, err
}

homeDir := client.GetClientContextFromCmd(cmd).HomeDir
// attempt to lookup address from Keybase if no address was provided
Expand All @@ -509,11 +510,3 @@ func getActorAddress(cmd *cobra.Command) (sdk.AccAddress, error) {
}
return info.GetAddress(), nil
}

// addrFromUint64 is a helper for address generation, copied from keeper
func addrFromUint64(id uint64) sdk.AccAddress {
addr := make([]byte, 20)
addr[0] = 'C'
binary.PutUvarint(addr[1:], id)
return sdk.AccAddress(crypto.AddressHash(addr))
}
6 changes: 6 additions & 0 deletions x/wasm/client/cli/new_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ func MigrateContractCmd() *cobra.Command {
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg, err := parseMigrateContractArgs(args, clientCtx)
if err != nil {
Expand Down Expand Up @@ -63,6 +66,9 @@ func UpdateContractAdminCmd() *cobra.Command {
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg, err := parseUpdateContractAdminArgs(args, clientCtx)
if err != nil {
Expand Down
Loading

0 comments on commit 57517b0

Please sign in to comment.