Skip to content

Commit

Permalink
Merge PR cosmos#5192: golangcI-lint updates & set static version to 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle authored and alexanderbez committed Oct 14, 2019
1 parent fbd551d commit 9f37891
Show file tree
Hide file tree
Showing 35 changed files with 77 additions and 91 deletions.
48 changes: 32 additions & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
run:
deadline: 1m
# run:
# # timeout for analysis, e.g. 30s, 5m, default is 1m
# timeout: 5m

linters:
enable-all: true
disable:
- gocyclo
- gochecknoinits
- gochecknoglobals
- dupl
- interfacer
- unparam
- lll
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- goconst
- gocritic
- gofmt
- goimports
- golint
- gosec
- gosimple
- govet
- ineffassign
- maligned
- misspell
- nakedret
- prealloc
- staticcheck
- structcheck
- typecheck
- unconvert
- unused
disable:
- errcheck
- scopelint
- varcheck
- godox
- funlen
- whitespace

issues:
exclude-rules:
Expand All @@ -37,3 +47,9 @@ issues:
linters-settings:
dogsled:
max-blank-identifiers: 3
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true

service:
golangci-lint-version: 1.19.x
3 changes: 1 addition & 2 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type (
)

// BaseApp reflects the ABCI application implementation.
type BaseApp struct {
type BaseApp struct { // nolint: maligned
// initialized on creation
logger log.Logger
name string // application name from abci.Info
Expand Down Expand Up @@ -631,7 +631,6 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (result sdk
}

// runMsgs iterates through all the messages and executes them.
// nolint: gocyclo
func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (result sdk.Result) {
msgLogs := make(sdk.ABCIMessageLogs, 0, len(msgs))

Expand Down
5 changes: 2 additions & 3 deletions baseapp/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ import (

var isAlphaNumeric = regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString

// nolint - Mostly for testing
// Mostly for testing
func (app *BaseApp) Check(tx sdk.Tx) (result sdk.Result) {
return app.runTx(runTxModeCheck, nil, tx)
}

// nolint - full tx execution
// full tx execution
func (app *BaseApp) Simulate(txBytes []byte, tx sdk.Tx) (result sdk.Result) {
return app.runTx(runTxModeSimulate, txBytes, tx)
}

// nolint
func (app *BaseApp) Deliver(tx sdk.Tx) (result sdk.Result) {
return app.runTx(runTxModeDeliver, nil, tx)
}
Expand Down
10 changes: 5 additions & 5 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// CLIContext implements a typical CLI context created in SDK modules for
// transaction handling and queries.
type CLIContext struct {
Codec *codec.Codec
FromAddress sdk.AccAddress
Client rpcclient.Client
ChainID string
Keybase cryptokeys.Keybase
Expand All @@ -33,14 +33,14 @@ type CLIContext struct {
HomeDir string
NodeURI string
From string
TrustNode bool
UseLedger bool
BroadcastMode string
Verifier tmlite.Verifier
FromName string
Codec *codec.Codec
TrustNode bool
UseLedger bool
Simulate bool
GenerateOnly bool
FromAddress sdk.AccAddress
FromName string
Indent bool
SkipConfirm bool
}
Expand Down
2 changes: 1 addition & 1 deletion client/keys/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type testCases struct {

func getTestCases() testCases {
return testCases{
// nolint: govet
// nolint:govet
[]keys.KeyOutput{
{"A", "B", "C", "D", "E", 0, nil},
{"A", "B", "C", "D", "", 0, nil},
Expand Down
2 changes: 1 addition & 1 deletion crypto/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func checkAminoJSON(t *testing.T, src interface{}, dst interface{}, isNil bool)
require.Nil(t, err, "%+v", err)
}

// nolint: vet
// nolint: govet
func ExamplePrintRegisteredTypes() {
cdc.PrintTypes(os.Stdout)
// Output: | Type | Name | Prefix | Length | Notes |
Expand Down
1 change: 0 additions & 1 deletion crypto/keys/hd/hdpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func NewParams(purpose, coinType, account uint32, change bool, addressIdx uint32
}

// Parse the BIP44 path and unmarshal into the struct.
// nolint: gocyclo
func NewParamsFromPath(path string) (*BIP44Params, error) {
spl := strings.Split(path, "/")
if len(spl) != 5 {
Expand Down
4 changes: 2 additions & 2 deletions crypto/keys/hd/hdpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func mnemonicToSeed(mnemonic string) []byte {
return bip39.NewSeed(mnemonic, defaultBIP39Passphrase)
}

// nolint: vet
// nolint:govet
func ExampleStringifyPathParams() {
path := NewParams(44, 0, 0, false, 0)
fmt.Println(path.String())
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestParamsFromPath(t *testing.T) {

}

// nolint: vet
// nolint:govet
func ExampleSomeBIP32TestVecs() {

seed := mnemonicToSeed("barrel original fuel morning among eternal " +
Expand Down
4 changes: 2 additions & 2 deletions crypto/keys/keybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ var (
//
// NOTE: dbKeybase will be deprecated in favor of keyringKeybase.
type dbKeybase struct {
db dbm.DB
base baseKeybase
db dbm.DB
}

// newDBKeybase creates a new dbKeybase instance using the provided DB for
// reading and writing keys.
func newDBKeybase(db dbm.DB) Keybase {
return dbKeybase{
db: db,
base: baseKeybase{},
db: db,
}
}

Expand Down
3 changes: 1 addition & 2 deletions crypto/keys/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ var _ Keybase = keyringKeybase{}
// keyringKeybase implements the Keybase interface by using the Keyring library
// for account key persistence.
type keyringKeybase struct {
db keyring.Keyring
base baseKeybase
db keyring.Keyring
}

var maxPassphraseEntryAttempts = 3
Expand Down Expand Up @@ -453,7 +453,6 @@ func (kb keyringKeybase) writeInfo(name string, info Info) {
}
}

//nolint: funlen
func lkbToKeyringConfig(name, dir string, buf io.Reader, test bool) keyring.Config {
if test {
return keyring.Config{
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ github.com/tendermint/btcd v0.1.1/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrn
github.com/tendermint/crypto v0.0.0-20190823183015-45b1026d81ae h1:AOXNM7c2Vvo45SjAgeWF8Wy+NS7/NCqzRNpUc+HPAec=
github.com/tendermint/crypto v0.0.0-20190823183015-45b1026d81ae/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk=
github.com/tendermint/go-amino v0.14.1/go.mod h1:i/UKE5Uocn+argJJBb12qTZsCDBcAYMbR92AaJVmKso=
github.com/tendermint/go-amino v0.15.0 h1:TC4e66P59W7ML9+bxio17CPKnxW3nKIRAYskntMAoRk=
github.com/tendermint/go-amino v0.15.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
github.com/tendermint/go-amino v0.15.1 h1:D2uk35eT4iTsvJd9jWIetzthE5C0/k2QmMFkCN+4JgQ=
github.com/tendermint/go-amino v0.15.1/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
github.com/tendermint/iavl v0.12.4 h1:hd1woxUGISKkfUWBA4mmmTwOua6PQZTJM/F0FDrmMV8=
Expand Down
3 changes: 0 additions & 3 deletions store/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// nolint - reexport
const (
CodeOK = sdk.CodeOK
CodeInternal = sdk.CodeInternal
Expand All @@ -14,10 +13,8 @@ const (
CodespaceRoot = sdk.CodespaceRoot
)

// nolint - reexport
type Error = sdk.Error

// nolint - reexport
func ErrInternal(msg string) Error {
return sdk.ErrInternal(msg)
}
Expand Down
18 changes: 8 additions & 10 deletions store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,14 @@ func (st *Store) Query(req abci.RequestQuery) (res abci.ResponseQuery) {

// Implements types.Iterator.
type iavlIterator struct {
// Underlying store
tree *iavl.ImmutableTree

// Domain
start, end []byte

// Iteration order
ascending bool
key []byte // The current key (mutable)
value []byte // The current value (mutable)

// Underlying store
tree *iavl.ImmutableTree

// Channel to push iteration values.
iterCh chan cmn.KVPair
Expand All @@ -325,13 +325,11 @@ type iavlIterator struct {
// Close this to signal that state is initialized.
initCh chan struct{}

//----------------------------------------
// What follows are mutable state.
mtx sync.Mutex

invalid bool // True once, true forever
key []byte // The current key
value []byte // The current value
ascending bool // Iteration order

invalid bool // True once, true forever (mutable)
}

var _ types.Iterator = (*iavlIterator)(nil)
Expand Down
1 change: 0 additions & 1 deletion store/tracekv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func (tkv *Store) CacheWrapWithTrace(_ io.Writer, _ types.TraceContext) types.Ca

// writeOperation writes a KVStore operation to the underlying io.Writer as
// JSON-encoded data where the key/value pair is base64 encoded.
// nolint: errcheck
func writeOperation(w io.Writer, op operation, tc types.TraceContext, key, value []byte) {
traceOp := traceOperation{
Operation: op,
Expand Down
1 change: 0 additions & 1 deletion tests/gobash.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

// ExecuteT executes the command, pipes any input to STDIN and return STDOUT,
// logging STDOUT/STDERR to t.
// nolint: errcheck
func ExecuteT(t *testing.T, cmd, input string) (stdout, stderr string) {
t.Log("Running", cmd)

Expand Down
4 changes: 2 additions & 2 deletions tests/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func waitForHeight(height int64, url string) {

for {
// Since this is in a testing file we are accepting nolint to be passed
res, err = http.Get(url) //nolint:gosec
res, err = http.Get(url) // nolint:gosec
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func WaitForStart(url string) {
time.Sleep(time.Millisecond * 100)

var res *http.Response
res, err = http.Get(url) //nolint:gosec Error is arising in testing files, accepting nolint
res, err = http.Get(url) // nolint:gosec
if err != nil || res == nil {
continue
}
Expand Down
10 changes: 5 additions & 5 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ const DefaultKeyringServiceName = "cosmos"
// Config is the structure that holds the SDK configuration parameters.
// This could be used to initialize certain configuration parameters for the SDK.
type Config struct {
mtx sync.RWMutex
sealed bool
bech32AddressPrefix map[string]string
coinType uint32
fullFundraiserPath string
keyringServiceName string
bech32AddressPrefix map[string]string
txEncoder TxEncoder
addressVerifier func([]byte) error
keyringServiceName string
mtx sync.RWMutex
coinType uint32
sealed bool
}

// cosmos-sdk wide global singleton
Expand Down
2 changes: 1 addition & 1 deletion types/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestLogContext(t *testing.T) {
require.Equal(t, *logger.logs, []string{"debug", "info", "error"})
}

type dummy int64 //nolint: unused
type dummy int64 //nolint:unused

func (d dummy) Clone() interface{} {
return d
Expand Down
2 changes: 0 additions & 2 deletions types/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func precisionInt() *big.Int {
return new(big.Int).Set(precisionReuse)
}

// nolint - common values
func ZeroDec() Dec { return Dec{new(big.Int).Set(zeroInt)} }
func OneDec() Dec { return Dec{precisionInt()} }
func SmallestDec() Dec { return Dec{new(big.Int).Set(oneInt)} }
Expand Down Expand Up @@ -394,7 +393,6 @@ func (d Dec) String() string {
// |_____: / | $$$ |
// |________|

// nolint - go-cyclo
// Remove a Precision amount of rightmost digits and perform bankers rounding
// on the remainder (gaussian rounding) on the digits which have been removed.
//
Expand Down
2 changes: 1 addition & 1 deletion types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func AppendMsgToErr(msg string, err string) string {
}

// returns the index of the message in the ABCI Log
// nolint: deadcode unused
// nolint:deadcode,unused
func mustGetMsgIndex(abciLog string) int {
msgIdx := strings.Index(abciLog, "message\":\"")
if msgIdx == -1 {
Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/cli/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ <appcli> tx broadcast ./mytxn.json
}

res, err := cliCtx.BroadcastTx(txBytes)
cliCtx.PrintOutput(res) // nolint:errcheck
cliCtx.PrintOutput(res)

return err
},
Expand Down
5 changes: 0 additions & 5 deletions x/auth/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/exported"
)

var (
stakeDenom = "stake"
feeDenom = "fee"
)

func TestBaseAddressPubKey(t *testing.T) {
_, pub1, addr1 := KeyTestPubAddr()
_, pub2, addr2 := KeyTestPubAddr()
Expand Down
1 change: 0 additions & 1 deletion x/bank/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ func (keeper BaseSendKeeper) SetCoins(ctx sdk.Context, addr sdk.AccAddress, amt
}

// GetSendEnabled returns the current SendEnabled
// nolint: errcheck
func (keeper BaseSendKeeper) GetSendEnabled(ctx sdk.Context) bool {
var enabled bool
keeper.paramSpace.Get(ctx, types.ParamStoreKeySendEnabled, &enabled)
Expand Down
Loading

0 comments on commit 9f37891

Please sign in to comment.