Skip to content

Commit

Permalink
style: bump golangci-lint (#16667)
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat authored Jun 23, 2023
1 parent 59ea048 commit 8d4ff7a
Show file tree
Hide file tree
Showing 29 changed files with 57 additions and 48 deletions.
14 changes: 13 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ run:
linters:
disable-all: true
enable:
- depguard
- dogsled
- exportloopref
- goconst
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ benchmark:
###############################################################################

golangci_lint_cmd=golangci-lint
golangci_version=v1.51.2
golangci_version=v1.53.3

lint:
@echo "--> Running linter"
Expand Down
12 changes: 6 additions & 6 deletions client/debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion codec/types/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion codec/types/any_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion codec/types/any_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion codec/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion crypto/keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crypto/keys/multisig/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion depinject/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion depinject/provider_desc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
4 changes: 2 additions & 2 deletions math/uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion orm/model/ormdb/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion orm/model/ormtable/auto_increment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions orm/model/ormtable/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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")
Expand All @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion orm/model/ormtable/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion orm/types/ormerrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion server/mock/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testutil/cmdtest/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -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...)
Expand Down
2 changes: 1 addition & 1 deletion tools/rosetta/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions types/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion types/tx/ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions x/auth/client/cli/tx_multisign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand All @@ -200,7 +200,7 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) {

err = clientCtx.PrintBytes(json)

return
return err
}
}

Expand Down
4 changes: 2 additions & 2 deletions x/distribution/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/gov/types/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
4 changes: 2 additions & 2 deletions x/group/module/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 8d4ff7a

Please sign in to comment.