Skip to content

Commit 38c7c94

Browse files
authored
style: various linting fixes (#15675)
## Description fix various linting issues --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... * [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title * [ ] added `!` to the type prefix if API or client breaking change * [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) * [ ] provided a link to the relevant issue or specification * [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules) * [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) * [ ] added a changelog entry to `CHANGELOG.md` * [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) * [ ] updated the relevant documentation or specification * [ ] reviewed "Files changed" and left comments if necessary * [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... * [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title * [ ] confirmed `!` in the type prefix if API or client breaking change * [ ] confirmed all author checklist items have been addressed * [ ] reviewed state machine logic * [ ] reviewed API design and naming * [ ] reviewed documentation is accurate * [ ] reviewed tests and test coverage * [ ] manually tested (if applicable)
1 parent 448ffbc commit 38c7c94

35 files changed

+94
-123
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ replace github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8
797797
* [#11334](https://github.com/cosmos/cosmos-sdk/pull/11334) Move `x/gov/types/v1beta2` to `x/gov/types/v1`.
798798
* (x/auth/middleware) [#11413](https://github.com/cosmos/cosmos-sdk/pull/11413) Refactor tx middleware to be extensible on tx fee logic. Merged `MempoolFeeMiddleware` and `TxPriorityMiddleware` functionalities into `DeductFeeMiddleware`, make the logic extensible using the `TxFeeChecker` option, the current fee logic is preserved by the default `checkTxFeeWithValidatorMinGasPrices` implementation. Change `RejectExtensionOptionsMiddleware` to `NewExtensionOptionsMiddleware` which is extensible with the `ExtensionOptionChecker` option. Unpack the tx extension options `Any`s to interface `TxExtensionOptionI`.
799799
* (migrations) [#11556](https://github.com/cosmos/cosmos-sdk/pull/11556#issuecomment-1091385011) Remove migration code from 0.42 and below. To use previous migrations, checkout previous versions of the cosmos-sdk.
800+
* (x/authz,consensus,crisis,slashing) [#15675](https://github.com/cosmos/cosmos-sdk/pull/15675) Remove ModuleCdc as `NewAminoCodec` is depreacted.
800801

801802
### Client Breaking Changes
802803

client/tx/tx_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package tx_test
22

33
import (
4-
gocontext "context"
4+
"context"
55
"fmt"
66
"strings"
77
"testing"
@@ -40,7 +40,7 @@ type mockContext struct {
4040
wantErr bool
4141
}
4242

43-
func (m mockContext) Invoke(grpcCtx gocontext.Context, method string, req, reply interface{}, opts ...grpc.CallOption) (err error) {
43+
func (m mockContext) Invoke(grpcCtx context.Context, method string, req, reply interface{}, opts ...grpc.CallOption) (err error) {
4444
if m.wantErr {
4545
return fmt.Errorf("mock err")
4646
}
@@ -53,7 +53,7 @@ func (m mockContext) Invoke(grpcCtx gocontext.Context, method string, req, reply
5353
return nil
5454
}
5555

56-
func (mockContext) NewStream(gocontext.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) {
56+
func (mockContext) NewStream(context.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) {
5757
panic("not implemented")
5858
}
5959

@@ -347,7 +347,7 @@ func TestSign(t *testing.T) {
347347
var prevSigs []signingtypes.SignatureV2
348348
for _, tc := range testCases {
349349
t.Run(tc.name, func(t *testing.T) {
350-
err = tx.Sign(nil, tc.txf, tc.from, tc.txb, tc.overwrite) //nolint:staticcheck
350+
err = tx.Sign(context.TODO(), tc.txf, tc.from, tc.txb, tc.overwrite)
351351
if len(tc.expectedPKs) == 0 {
352352
requireT.Error(err)
353353
} else {
@@ -418,7 +418,7 @@ func TestPreprocessHook(t *testing.T) {
418418
txb, err := txfDirect.BuildUnsignedTx(msg1, msg2)
419419
requireT.NoError(err)
420420

421-
err = tx.Sign(nil, txfDirect, from, txb, false) //nolint:staticcheck
421+
err = tx.Sign(context.TODO(), txfDirect, from, txb, false)
422422
requireT.NoError(err)
423423

424424
// Run preprocessing

codec/proto_codec.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,12 @@ func (pc *ProtoCodec) GetMsgV1Signers(msg gogoproto.Message) ([]string, proto.Me
300300
if msgV2, ok := msg.(proto.Message); ok {
301301
signers, err := pc.getSignersCtx.GetSigners(msgV2)
302302
return signers, msgV2, err
303-
} else {
304-
a, err := types.NewAnyWithValue(msg)
305-
if err != nil {
306-
return nil, nil, err
307-
}
308-
return pc.GetMsgAnySigners(a)
309303
}
304+
a, err := types.NewAnyWithValue(msg)
305+
if err != nil {
306+
return nil, nil, err
307+
}
308+
return pc.GetMsgAnySigners(a)
310309
}
311310

312311
// GRPCCodec returns the gRPC Codec for this specific ProtoCodec

crypto/armor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"io"
88

99
"github.com/cometbft/cometbft/crypto"
10-
"golang.org/x/crypto/openpgp/armor" //nolint:staticcheck
10+
"golang.org/x/crypto/openpgp/armor" //nolint:staticcheck // TODO: remove this dependency
1111

1212
errorsmod "cosmossdk.io/errors"
1313

crypto/ledger/encode_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func checkAminoJSON(t *testing.T, src, dst interface{}, isNil bool) {
2424
require.Nil(t, err, "%+v", err)
2525
}
2626

27-
func ExamplePrintRegisteredTypes() { //nolint:govet
27+
func ExamplePrintRegisteredTypes() {
2828
_ = cdc.PrintTypes(os.Stdout)
2929
// | Type | Name | Prefix | Length | Notes |
3030
// | ---- | ---- | ------ | ----- | ------ |

testutil/rest.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func GetRequestWithHeaders(url string, headers map[string]string) ([]byte, error
4242
// GetRequest defines a wrapper around an HTTP GET request with a provided URL.
4343
// An error is returned if the request or reading the body fails.
4444
func GetRequest(url string) ([]byte, error) {
45-
res, err := http.Get(url) //nolint:gosec
45+
res, err := http.Get(url) //nolint:gosec // only used for testing
4646
if err != nil {
4747
return nil, err
4848
}
@@ -61,7 +61,7 @@ func GetRequest(url string) ([]byte, error) {
6161
// PostRequest defines a wrapper around an HTTP POST request with a provided URL and data.
6262
// An error is returned if the request or reading the body fails.
6363
func PostRequest(url, contentType string, data []byte) ([]byte, error) {
64-
res, err := http.Post(url, contentType, bytes.NewBuffer(data)) //nolint:gosec
64+
res, err := http.Post(url, contentType, bytes.NewBuffer(data)) //nolint:gosec // only used for testing
6565
if err != nil {
6666
return nil, fmt.Errorf("error while sending post request: %w", err)
6767
}

testutil/sims/simulation_helpers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func SimulationOperations(app runtime.AppI, cdc codec.JSONCodec, config simtypes
6868
}
6969
}
7070

71-
simState.LegacyProposalContents = app.SimulationManager().GetProposalContents(simState) //nolint:staticcheck
71+
simState.LegacyProposalContents = app.SimulationManager().GetProposalContents(simState) //nolint:staticcheck // used for legacy testing
7272
simState.ProposalMsgs = app.SimulationManager().GetProposalMsgs(simState)
7373
return app.SimulationManager().WeightedOperations(simState)
7474
}

types/context_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func (s *contextTestSuite) TestUnwrapSDKContext() {
238238
s.Require().Panics(func() { types.UnwrapSDKContext(ctx) })
239239

240240
// test unwrapping when we've used context.WithValue
241-
ctx = context.WithValue(sdkCtx, "foo", "bar") //nolint:golint,staticcheck,revive
241+
ctx = context.WithValue(sdkCtx, struct{}{}, "bar")
242242
sdkCtx2 = types.UnwrapSDKContext(ctx)
243243
s.Require().Equal(sdkCtx, sdkCtx2)
244244
}

x/auth/vesting/module.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,21 @@ func init() {
131131
)
132132
}
133133

134-
//nolint:revive
135-
type VestingInputs struct {
134+
type ModuleInputs struct {
136135
depinject.In
137136

138137
AccountKeeper keeper.AccountKeeper
139138
BankKeeper types.BankKeeper
140139
}
141140

142-
//nolint:revive
143-
type VestingOutputs struct {
141+
type ModuleOutputs struct {
144142
depinject.Out
145143

146144
Module appmodule.AppModule
147145
}
148146

149-
func ProvideModule(in VestingInputs) VestingOutputs {
147+
func ProvideModule(in ModuleInputs) ModuleOutputs {
150148
m := NewAppModule(in.AccountKeeper, in.BankKeeper)
151149

152-
return VestingOutputs{Module: m}
150+
return ModuleOutputs{Module: m}
153151
}

x/authz/codec/cdc.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import (
66
sdk "github.com/cosmos/cosmos-sdk/types"
77
)
88

9-
var (
10-
Amino = codec.NewLegacyAmino()
11-
ModuleCdc = codec.NewAminoCodec(Amino)
12-
)
9+
var Amino = codec.NewLegacyAmino()
1310

1411
func init() {
1512
cryptocodec.RegisterCrypto(Amino)

x/authz/module/module.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config sdkclient.TxEn
8686
}
8787

8888
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the authz module.
89-
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *gwruntime.ServeMux) {
89+
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *gwruntime.ServeMux) {
9090
if err := authz.RegisterQueryHandlerClient(context.Background(), mux, authz.NewQueryClient(clientCtx)); err != nil {
9191
panic(err)
9292
}
@@ -170,8 +170,7 @@ func init() {
170170
)
171171
}
172172

173-
//nolint:revive
174-
type AuthzInputs struct {
173+
type ModuleInputs struct {
175174
depinject.In
176175

177176
Key *store.KVStoreKey
@@ -182,18 +181,17 @@ type AuthzInputs struct {
182181
MsgServiceRouter baseapp.MessageRouter
183182
}
184183

185-
//nolint:revive
186-
type AuthzOutputs struct {
184+
type ModuleOutputs struct {
187185
depinject.Out
188186

189187
AuthzKeeper keeper.Keeper
190188
Module appmodule.AppModule
191189
}
192190

193-
func ProvideModule(in AuthzInputs) AuthzOutputs {
191+
func ProvideModule(in ModuleInputs) ModuleOutputs {
194192
k := keeper.NewKeeper(in.Key, in.Cdc, in.MsgServiceRouter, in.AccountKeeper)
195193
m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.Registry)
196-
return AuthzOutputs{AuthzKeeper: k, Module: m}
194+
return ModuleOutputs{AuthzKeeper: k, Module: m}
197195
}
198196

199197
// ____________________________________________________________________________

x/authz/msgs.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (msg MsgGrant) ValidateBasic() error {
6666

6767
// GetSignBytes implements the LegacyMsg.GetSignBytes method.
6868
func (msg MsgGrant) GetSignBytes() []byte {
69-
return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg))
69+
return sdk.MustSortJSON(authzcodec.Amino.MustMarshalJSON(&msg))
7070
}
7171

7272
// GetAuthorization returns the cache value from the MsgGrant.Authorization if present.
@@ -145,7 +145,7 @@ func (msg MsgRevoke) ValidateBasic() error {
145145

146146
// GetSignBytes implements the LegacyMsg.GetSignBytes method.
147147
func (msg MsgRevoke) GetSignBytes() []byte {
148-
return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg))
148+
return sdk.MustSortJSON(authzcodec.Amino.MustMarshalJSON(&msg))
149149
}
150150

151151
// NewMsgExec creates a new MsgExecAuthorized
@@ -211,5 +211,5 @@ func (msg MsgExec) ValidateBasic() error {
211211

212212
// GetSignBytes implements the LegacyMsg.GetSignBytes method.
213213
func (msg MsgExec) GetSignBytes() []byte {
214-
return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg))
214+
return sdk.MustSortJSON(authzcodec.Amino.MustMarshalJSON(&msg))
215215
}

x/consensus/module.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ func init() {
141141
)
142142
}
143143

144-
//nolint:revive
145-
type ConsensusInputs struct {
144+
type ModuleInputs struct {
146145
depinject.In
147146

148147
Config *modulev1.Module
@@ -151,16 +150,15 @@ type ConsensusInputs struct {
151150
EventManager event.Service
152151
}
153152

154-
//nolint:revive
155-
type ConsensusOutputs struct {
153+
type ModuleOutputs struct {
156154
depinject.Out
157155

158156
Keeper keeper.Keeper
159157
Module appmodule.AppModule
160158
BaseAppOption runtime.BaseAppOption
161159
}
162160

163-
func ProvideModule(in ConsensusInputs) ConsensusOutputs {
161+
func ProvideModule(in ModuleInputs) ModuleOutputs {
164162
// default to governance authority if not provided
165163
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
166164
if in.Config.Authority != "" {
@@ -173,7 +171,7 @@ func ProvideModule(in ConsensusInputs) ConsensusOutputs {
173171
app.SetParamStore(k.ParamsStore)
174172
}
175173

176-
return ConsensusOutputs{
174+
return ModuleOutputs{
177175
Keeper: k,
178176
Module: m,
179177
BaseAppOption: baseappOpt,

x/consensus/types/codec.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
2727
legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "cosmos-sdk/x/consensus/MsgUpdateParams")
2828
}
2929

30-
var (
31-
amino = codec.NewLegacyAmino()
32-
ModuleCdc = codec.NewAminoCodec(amino)
33-
)
30+
var amino = codec.NewLegacyAmino()
3431

3532
func init() {
3633
RegisterLegacyAminoCodec(amino)

x/consensus/types/msgs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress {
2323
// GetSignBytes returns the raw bytes for a MsgUpdateParams message that
2424
// the expected signer needs to sign.
2525
func (msg MsgUpdateParams) GetSignBytes() []byte {
26-
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
26+
return sdk.MustSortJSON(amino.MustMarshalJSON(&msg))
2727
}
2828

2929
// ValidateBasic performs basic MsgUpdateParams message validation.

x/crisis/module.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ func init() {
191191
)
192192
}
193193

194-
//nolint:revive
195-
type CrisisInputs struct {
194+
type ModuleInputs struct {
196195
depinject.In
197196

198197
Config *modulev1.Module
@@ -206,15 +205,14 @@ type CrisisInputs struct {
206205
LegacySubspace exported.Subspace
207206
}
208207

209-
//nolint:revive
210-
type CrisisOutputs struct {
208+
type ModuleOutputs struct {
211209
depinject.Out
212210

213211
Module appmodule.AppModule
214212
CrisisKeeper *keeper.Keeper
215213
}
216214

217-
func ProvideModule(in CrisisInputs) CrisisOutputs {
215+
func ProvideModule(in ModuleInputs) ModuleOutputs {
218216
var invalidCheckPeriod uint
219217
if in.AppOpts != nil {
220218
invalidCheckPeriod = cast.ToUint(in.AppOpts.Get(server.FlagInvCheckPeriod))
@@ -247,5 +245,5 @@ func ProvideModule(in CrisisInputs) CrisisOutputs {
247245

248246
m := NewAppModule(k, skipGenesisInvariants, in.LegacySubspace)
249247

250-
return CrisisOutputs{CrisisKeeper: k, Module: m}
248+
return ModuleOutputs{CrisisKeeper: k, Module: m}
251249
}

x/crisis/types/codec.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
2929
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
3030
}
3131

32-
var (
33-
amino = codec.NewLegacyAmino()
34-
ModuleCdc = codec.NewAminoCodec(amino)
35-
)
32+
var aminoCdc = codec.NewLegacyAmino()
3633

3734
func init() {
38-
RegisterLegacyAminoCodec(amino)
39-
cryptocodec.RegisterCrypto(amino)
40-
sdk.RegisterLegacyAminoCodec(amino)
35+
RegisterLegacyAminoCodec(aminoCdc)
36+
cryptocodec.RegisterCrypto(aminoCdc)
37+
sdk.RegisterLegacyAminoCodec(aminoCdc)
4138

4239
// Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be
4340
// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances

x/crisis/types/msgs.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (msg MsgVerifyInvariant) GetSigners() []sdk.AccAddress {
3131

3232
// GetSignBytes gets the sign bytes for the msg MsgVerifyInvariant
3333
func (msg MsgVerifyInvariant) GetSignBytes() []byte {
34-
bz := ModuleCdc.MustMarshalJSON(&msg)
34+
bz := aminoCdc.MustMarshalJSON(&msg)
3535
return sdk.MustSortJSON(bz)
3636
}
3737

@@ -58,7 +58,7 @@ func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress {
5858
// GetSignBytes returns the raw bytes for a MsgUpdateParams message that
5959
// the expected signer needs to sign.
6060
func (msg MsgUpdateParams) GetSignBytes() []byte {
61-
bz := ModuleCdc.MustMarshalJSON(&msg)
61+
bz := aminoCdc.MustMarshalJSON(&msg)
6262
return sdk.MustSortJSON(bz)
6363
}
6464

0 commit comments

Comments
 (0)