style: bump golangci-lint (#16667)

This commit is contained in:
Jacob Gadikian 2023-06-23 20:49:34 +08:00 committed by GitHub
parent 59ea0489fa
commit 8d4ff7a19a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 57 additions and 48 deletions

View File

@ -10,7 +10,6 @@ run:
linters:
disable-all: true
enable:
- depguard
- dogsled
- exportloopref
- goconst
@ -51,6 +50,15 @@ issues:
- text: 'SA1019: codec.NewAminoCodec is deprecated' # TODO remove once migration path is set out
linters:
- staticcheck
- text: 'SA1019: legacybech32.MustMarshalPubKey' # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: 'SA1019: legacybech32.MarshalPubKey' # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: 'SA1019: legacybech32.UnmarshalPubKey' # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: 'leading space'
linters:
- nolintlint
@ -66,6 +74,10 @@ linters-settings:
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(cosmossdk.io)
- prefix(github.com/cosmos/cosmos-sdk)
revive:
rules:
- name: redefines-builtin-id
disabled: true
gosec:
# To select a subset of rules to run.

View File

@ -380,7 +380,7 @@ benchmark:
###############################################################################
golangci_lint_cmd=golangci-lint
golangci_version=v1.51.2
golangci_version=v1.53.3
lint:
@echo "--> Running linter"

View File

@ -107,17 +107,17 @@ func getPubKeyFromRawString(pkstr, keytype string) (cryptotypes.PubKey, error) {
}
}
pk, err := legacybech32.UnmarshalPubKey(legacybech32.AccPK, pkstr) //nolint:staticcheck // we do old keys, they're keys after all.
pk, err := legacybech32.UnmarshalPubKey(legacybech32.AccPK, pkstr)
if err == nil {
return pk, nil
}
pk, err = legacybech32.UnmarshalPubKey(legacybech32.ValPK, pkstr) //nolint:staticcheck // we do old keys, they're keys after all.
pk, err = legacybech32.UnmarshalPubKey(legacybech32.ValPK, pkstr)
if err == nil {
return pk, nil
}
pk, err = legacybech32.UnmarshalPubKey(legacybech32.ConsPK, pkstr) //nolint:staticcheck // we do old keys, they're keys after all.
pk, err = legacybech32.UnmarshalPubKey(legacybech32.ConsPK, pkstr)
if err == nil {
return pk, nil
}
@ -155,7 +155,7 @@ $ %s debug pubkey-raw cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
var consensusPub string
edPK, ok := pk.(*ed25519.PubKey)
if ok && pubkeyType == ed {
consensusPub, err = legacybech32.MarshalPubKey(legacybech32.ConsPK, edPK) //nolint:staticcheck // we do old keys, they're keys after all.
consensusPub, err = legacybech32.MarshalPubKey(legacybech32.ConsPK, edPK)
if err != nil {
return err
}
@ -168,11 +168,11 @@ $ %s debug pubkey-raw cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
if err != nil {
return err
}
accPub, err := legacybech32.MarshalPubKey(legacybech32.AccPK, pk) //nolint:staticcheck // we do old keys, they're keys after all.
accPub, err := legacybech32.MarshalPubKey(legacybech32.AccPK, pk)
if err != nil {
return err
}
valPub, err := legacybech32.MarshalPubKey(legacybech32.ValPK, pk) //nolint:staticcheck // we do old keys, they're keys after all.
valPub, err := legacybech32.MarshalPubKey(legacybech32.ValPK, pk)
if err != nil {
return err
}

View File

@ -10,7 +10,6 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// nolint:revive // XXX is reqired for proto compatibility
type Any struct {
// A URL/resource name that uniquely identifies the type of the serialized
// protocol buffer message. This string must contain at least

View File

@ -17,7 +17,7 @@ func (d Dog) Greet() string { return d.Name }
func (d *Dog) Reset() { d.Name = "" }
func (d *Dog) String() string { return d.Name }
func (d *Dog) ProtoMessage() {}
func (d *Dog) XXX_MessageName() string { return "tests/dog" } //nolint:revive // XXX_ prefix is required
func (d *Dog) XXX_MessageName() string { return "tests/dog" }
type Animal interface {
Greet() string

View File

@ -19,7 +19,7 @@ var _ proto.Message = (*errOnMarshal)(nil)
var errAlways = fmt.Errorf("always erroring")
func (eom *errOnMarshal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { //nolint:revive // XXX_ prefix is intentional
func (eom *errOnMarshal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return nil, errAlways
}

View File

@ -44,7 +44,7 @@ var (
func (dog FakeDog) Reset() {}
func (dog FakeDog) String() string { return "fakedog" }
func (dog FakeDog) ProtoMessage() {}
func (dog FakeDog) XXX_MessageName() string { return proto.MessageName(&testdata.Dog{}) } //nolint:revive // XXX_ prefix is intentional
func (dog FakeDog) XXX_MessageName() string { return proto.MessageName(&testdata.Dog{}) }
func (dog FakeDog) Greet() string { return "fakedog" }
func TestRegister(t *testing.T) {

View File

@ -606,7 +606,7 @@ func SignWithLedger(k *Record, msg []byte, signMode signing.SignMode) (sig []byt
priv, err := ledger.NewPrivKeySecp256k1Unsafe(*path)
if err != nil {
return
return nil, nil, err
}
switch signMode {

View File

@ -66,7 +66,7 @@ func tmToProto(tmPk tmMultisig) (*LegacyAminoPubKey, error) {
}
// MarshalAminoJSON overrides amino JSON unmarshaling.
func (m LegacyAminoPubKey) MarshalAminoJSON() (tmMultisig, error) { //nolint:golint,revive // we need to override the default amino JSON marshaling
func (m LegacyAminoPubKey) MarshalAminoJSON() (tmMultisig, error) { //nolint:golint // we need to override the default amino JSON marshaling
return protoToTm(&m)
}

View File

@ -90,7 +90,7 @@ const _vendor = "/vendor/"
func splitFuncName(function string) (pname, fname string) {
if len(function) == 0 {
return
return "", ""
}
// We have something like "path.to/my/pkg.MyFunction". If the function is

View File

@ -45,7 +45,7 @@ func StructInAndOut(_ float32, _ StructIn, _ byte) (int16, StructOut, int32, err
return int16(0), StructOut{}, int32(0), nil
}
func BadErrorPosition() (error, int) { return nil, 0 } //nolint:revive,stylecheck // Deliberately has error as first of multiple arguments.
func BadErrorPosition() (error, int) { return nil, 0 } //nolint:stylecheck // Deliberately has error as first of multiple arguments.
func BadOptionalFn(_ BadOptional) int { return 0 }

View File

@ -244,10 +244,10 @@ func RelativePow(x, n, b Uint) (z Uint) {
if x.IsZero() {
if n.IsZero() {
z = b // 0^0 = 1
return
return z
}
z = ZeroUint() // otherwise 0^a = 0
return
return z
}
z = x

View File

@ -258,7 +258,7 @@ func TestModuleDB(t *testing.T) {
testkv.AssertBackendsEqual(t, backend, backend2)
}
func runSimpleBankTests(t *testing.T, k Keeper, ctx context.Context) { // nolint:revive // test function
func runSimpleBankTests(t *testing.T, k Keeper, ctx context.Context) {
// mint coins
denom := "foo"
acct1 := "bob"

View File

@ -42,7 +42,7 @@ func TestAutoIncrementScenario(t *testing.T) {
checkEncodeDecodeEntries(t, table, store.IndexStoreReader())
}
func runAutoIncrementScenario(t *testing.T, table ormtable.AutoIncrementTable, ctx context.Context) { //nolint:revive // ignore linting on testing function signature
func runAutoIncrementScenario(t *testing.T, table ormtable.AutoIncrementTable, ctx context.Context) {
store, err := testpb.NewExampleAutoIncrementTableTable(table)
assert.NilError(t, err)

View File

@ -68,7 +68,7 @@ func bench(b *testing.B, newBackend func(testing.TB) ormtable.Backend) {
})
}
func benchInsert(b *testing.B, ctx context.Context) { //nolint:revive // ignore for benchmark
func benchInsert(b *testing.B, ctx context.Context) {
balanceTable := initBalanceTable(b)
for i := 0; i < b.N; i++ {
assert.NilError(b, balanceTable.Insert(ctx, &testpb.Balance{
@ -79,7 +79,7 @@ func benchInsert(b *testing.B, ctx context.Context) { //nolint:revive // ignore
}
}
func benchUpdate(b *testing.B, ctx context.Context) { //nolint:revive // ignore for benchmark
func benchUpdate(b *testing.B, ctx context.Context) {
balanceTable := initBalanceTable(b)
for i := 0; i < b.N; i++ {
assert.NilError(b, balanceTable.Update(ctx, &testpb.Balance{
@ -90,7 +90,7 @@ func benchUpdate(b *testing.B, ctx context.Context) { //nolint:revive // ignore
}
}
func benchGet(b *testing.B, ctx context.Context) { //nolint:revive // ignore for benchmark
func benchGet(b *testing.B, ctx context.Context) {
balanceTable := initBalanceTable(b)
for i := 0; i < b.N; i++ {
balance, err := balanceTable.Get(ctx, fmt.Sprintf("acct%d", i), "bar")
@ -99,7 +99,7 @@ func benchGet(b *testing.B, ctx context.Context) { //nolint:revive // ignore for
}
}
func benchDelete(b *testing.B, ctx context.Context) { //nolint:revive // ignore for benchmark
func benchDelete(b *testing.B, ctx context.Context) {
balanceTable := initBalanceTable(b)
for i := 0; i < b.N; i++ {
assert.NilError(b, balanceTable.Delete(ctx, &testpb.Balance{

View File

@ -699,7 +699,7 @@ func TestJSONExportImport(t *testing.T) {
assertTablesEqual(t, table, store, store2)
}
func assertTablesEqual(t assert.TestingT, table ormtable.Table, ctx, ctx2 context.Context) { //nolint:revive // ignore long function name
func assertTablesEqual(t assert.TestingT, table ormtable.Table, ctx, ctx2 context.Context) {
it, err := table.List(ctx, nil)
assert.NilError(t, err)
it2, err := table.List(ctx2, nil)

View File

@ -13,7 +13,6 @@ func IsNotFound(err error) bool {
return errors.IsOf(err, NotFound)
}
// nolint: revive // avoid break API
var (
InvalidTableId = errors.New(codespace, 1, "invalid or missing table or single id, need a non-zero value")
MissingPrimaryKey = errors.New(codespace, 2, "table is missing primary key")

View File

@ -149,7 +149,7 @@ type MsgServerImpl struct {
capKeyMainStore *storetypes.KVStoreKey
}
func MsgTestHandler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { // nolint: revive // refactor this in a followup pr
func MsgTestHandler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(KVStoreTx)
if err := dec(in); err != nil {
return nil, err

View File

@ -78,7 +78,7 @@ func (s *System) MustRun(t TestingT, args ...string) RunResult {
}
// MustRunC calls s.RunWithInput, but also calls t.FailNow if RunResult.Err is not nil.
func (s *System) MustRunC(t TestingT, ctx context.Context, args ...string) RunResult { //nolint:revive // As a variation of MustRun, t is more important than ctx.
func (s *System) MustRunC(t TestingT, ctx context.Context, args ...string) RunResult {
t.Helper()
return s.MustRunWithInputC(t, ctx, bytes.NewReader(nil), args...)
@ -92,7 +92,7 @@ func (s *System) MustRunWithInput(t TestingT, in io.Reader, args ...string) RunR
}
// MustRunWithInputC calls s.RunWithInputC, but also calls t.FailNow if RunResult.Err is not nil.
func (s *System) MustRunWithInputC(t TestingT, ctx context.Context, in io.Reader, args ...string) RunResult { //nolint:revive // As a variation of MustRun, t is more important than ctx.
func (s *System) MustRunWithInputC(t TestingT, ctx context.Context, in io.Reader, args ...string) RunResult {
t.Helper()
res := s.RunWithInputC(ctx, in, args...)

View File

@ -612,7 +612,7 @@ func (c converter) OpsAndSigners(txBytes []byte) (ops []*rosettatypes.Operation,
var signerStr string
signerStr, err = c.ir.SigningContext().AddressCodec().BytesToString(signer)
if err != nil {
return
return nil, nil, crgerrs.WrapError(crgerrs.ErrCodec, err.Error())
}
signers = append(signers, &rosettatypes.AccountIdentifier{

View File

@ -17,7 +17,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32/legacybech32" //nolint:staticcheck // SA1019: legacybech32 is deprecated: use the bech32 package instead.
"github.com/cosmos/cosmos-sdk/types/bech32/legacybech32" //nolint:staticcheck // we do old keys, they're keys after all.
)
type addressTestSuite struct {
@ -308,7 +308,7 @@ func (s *addressTestSuite) TestConfiguredPrefix() {
acc.String(),
prefix+types.PrefixAccount), acc.String())
bech32Pub := legacybech32.MustMarshalPubKey(legacybech32.AccPK, pub) //nolint:staticcheck // SA1019: legacybech32 is deprecated: use the bech32 package instead.
bech32Pub := legacybech32.MustMarshalPubKey(legacybech32.AccPK, pub)
s.Require().True(strings.HasPrefix(
bech32Pub,
prefix+types.PrefixPublic))
@ -322,7 +322,7 @@ func (s *addressTestSuite) TestConfiguredPrefix() {
val.String(),
prefix+types.PrefixValidator+types.PrefixAddress))
bech32ValPub := legacybech32.MustMarshalPubKey(legacybech32.ValPK, pub) //nolint:staticcheck // SA1019: legacybech32 is deprecated: use the bech32 package instead.
bech32ValPub := legacybech32.MustMarshalPubKey(legacybech32.ValPK, pub)
s.Require().True(strings.HasPrefix(
bech32ValPub,
prefix+types.PrefixValidator+types.PrefixPublic))
@ -336,7 +336,7 @@ func (s *addressTestSuite) TestConfiguredPrefix() {
cons.String(),
prefix+types.PrefixConsensus+types.PrefixAddress))
bech32ConsPub := legacybech32.MustMarshalPubKey(legacybech32.ConsPK, pub) //nolint:staticcheck // SA1019: legacybech32 is deprecated: use the bech32 package instead.
bech32ConsPub := legacybech32.MustMarshalPubKey(legacybech32.ConsPK, pub)
s.Require().True(strings.HasPrefix(
bech32ConsPub,
prefix+types.PrefixConsensus+types.PrefixPublic))

View File

@ -5,7 +5,7 @@ import (
)
// TxExtensionOptionI defines the interface for tx extension options
type TxExtensionOptionI interface{} //nolint:revive // to avoid breaking change
type TxExtensionOptionI interface{}
// unpackTxExtensionOptionsI unpacks Any's to TxExtensionOptionI's.
func unpackTxExtensionOptionsI(unpacker types.AnyUnpacker, anys []*types.Any) error {

View File

@ -73,7 +73,7 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) {
}
parsedTx, err := authclient.ReadTxFromFile(clientCtx, args[0])
if err != nil {
return
return err
}
txFactory, err := tx.NewFactoryCLI(clientCtx, cmd.Flags())
@ -183,7 +183,7 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) {
outputDoc, _ := cmd.Flags().GetString(flags.FlagOutputDocument)
if outputDoc == "" {
cmd.Printf("%s\n", json)
return
return nil
}
fp, err := os.OpenFile(outputDoc, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644)
@ -200,7 +200,7 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) {
err = clientCtx.PrintBytes(json)
return
return err
}
}

View File

@ -85,13 +85,13 @@ func (k Keeper) CalculateDelegationRewards(ctx context.Context, val stakingtypes
// fetch starting info for delegation
startingInfo, err := k.DelegatorStartingInfo.Get(ctx, collections.Join(del.GetValidatorAddr(), del.GetDelegatorAddr()))
if err != nil && !errors.Is(err, collections.ErrNotFound) {
return
return sdk.DecCoins{}, err
}
sdkCtx := sdk.UnwrapSDKContext(ctx)
if startingInfo.Height == uint64(sdkCtx.BlockHeight()) {
// started this height, no rewards yet
return
return sdk.DecCoins{}, nil
}
startingPeriod := startingInfo.PreviousPeriod

View File

@ -7,6 +7,6 @@ type ProposalMetadata struct {
Authors []string `json:"authors"`
Summary string `json:"summary"`
Details string `json:"details"`
ProposalForumUrl string `json:"proposal_forum_url"` //nolint:revive // named 'Url' instead of 'URL' for avoiding the camel case split
ProposalForumUrl string `json:"proposal_forum_url"`
VoteOptionContext string `json:"vote_option_context"`
}

View File

@ -558,7 +558,7 @@ func (s *IntegrationTestSuite) TestEndBlockerTallying() {
}
}
func submitProposal(s *IntegrationTestSuite, app *runtime.App, ctx context.Context, msgs []sdk.Msg, proposers []string, groupPolicyAddr sdk.AccAddress) (uint64, error) { //nolint:revive // context-as-argument: context.Context should be the first parameter of a function
func submitProposal(s *IntegrationTestSuite, app *runtime.App, ctx context.Context, msgs []sdk.Msg, proposers []string, groupPolicyAddr sdk.AccAddress) (uint64, error) {
proposalReq := &group.MsgSubmitProposal{
GroupPolicyAddress: groupPolicyAddr.String(),
Proposers: proposers,
@ -577,7 +577,7 @@ func submitProposal(s *IntegrationTestSuite, app *runtime.App, ctx context.Conte
}
func submitProposalAndVote(
s *IntegrationTestSuite, app *runtime.App, ctx context.Context, msgs []sdk.Msg, //nolint:revive // context-as-argument: context.Context should be the first parameter of a function
s *IntegrationTestSuite, app *runtime.App, ctx context.Context, msgs []sdk.Msg,
proposers []string, groupPolicyAddr sdk.AccAddress, voteOption group.VoteOption,
) (uint64, error) {
myProposalID, err := submitProposal(s, app, ctx, msgs, proposers, groupPolicyAddr)

View File

@ -1042,12 +1042,12 @@ func (k Keeper) getBeginInfo(
) (completionTime time.Time, height int64, completeNow bool, err error) {
validator, err := k.GetValidator(ctx, valSrcAddr)
if err != nil && errors.Is(err, types.ErrNoValidatorFound) {
return
return completionTime, height, false, nil
}
sdkCtx := sdk.UnwrapSDKContext(ctx)
unbondingTime, err := k.UnbondingTime(ctx)
if err != nil {
return
return completionTime, height, false, err
}
// TODO: When would the validator not be found?

View File

@ -172,13 +172,13 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx context.Context) (updates
case validator.IsUnbonded():
validator, err = k.unbondedToBonded(ctx, validator)
if err != nil {
return
return nil, err
}
amtFromNotBondedToBonded = amtFromNotBondedToBonded.Add(validator.GetTokens())
case validator.IsUnbonding():
validator, err = k.unbondingToBonded(ctx, validator)
if err != nil {
return
return nil, err
}
amtFromNotBondedToBonded = amtFromNotBondedToBonded.Add(validator.GetTokens())
case validator.IsBonded():

View File

@ -63,7 +63,6 @@ var (
// UnbondingType defines the type of unbonding operation
type UnbondingType int
//nolint:revive // we want these underscores, they make life easier
const (
UnbondingType_Undefined UnbondingType = iota
UnbondingType_UnbondingDelegation