Skip to content

Commit b7a20b8

Browse files
authored
chore: lint v2 (#24118)
1 parent 9acd771 commit b7a20b8

File tree

87 files changed

+298
-288
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+298
-288
lines changed

.golangci.yml

+117-99
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,144 @@
1+
version: "2"
12
run:
2-
tests: true
3-
timeout: 15m
4-
allow-parallel-runners: true
53
build-tags:
64
- e2e
75
- ledger
86
- test_ledger_mock
97
- sims
10-
8+
tests: true
9+
allow-parallel-runners: true
1110
linters:
12-
disable-all: true
11+
default: none
1312
enable:
13+
- copyloopvar
1414
- dogsled
1515
- errcheck
1616
- errorlint
17-
- copyloopvar
18-
- gci
1917
- goconst
2018
- gocritic
21-
- gofumpt
2219
- gosec
23-
- gosimple
2420
- govet
2521
- ineffassign
2622
- misspell
2723
- nakedret
2824
- nolintlint
2925
- revive
3026
- staticcheck
31-
- stylecheck
3227
- thelper
33-
- typecheck
3428
- unconvert
3529
- unused
36-
30+
settings:
31+
dogsled:
32+
max-blank-identifiers: 6
33+
gocritic:
34+
disabled-checks:
35+
- regexpMust
36+
- appendAssign
37+
- ifElseChain
38+
gosec:
39+
excludes:
40+
- G101
41+
- G107
42+
- G404
43+
confidence: medium
44+
misspell:
45+
locale: US
46+
nolintlint:
47+
require-explanation: true
48+
require-specific: false
49+
allow-unused: false
50+
revive:
51+
rules:
52+
- name: redefines-builtin-id
53+
disabled: true
54+
staticcheck:
55+
checks:
56+
- all
57+
unused:
58+
local-variables-are-used: false
59+
exclusions:
60+
generated: lax
61+
presets:
62+
- comments
63+
- common-false-positives
64+
- legacy
65+
- std-error-handling
66+
rules:
67+
- linters:
68+
- staticcheck
69+
text: 'ST1003:'
70+
- linters:
71+
- staticcheck
72+
text: 'ST1016:'
73+
- linters:
74+
- staticcheck
75+
path: migrations
76+
text: 'SA1019:'
77+
- linters:
78+
- staticcheck
79+
text: 'SA1019: codec.NewAminoCodec is deprecated'
80+
- linters:
81+
- staticcheck
82+
text: 'SA1019: legacybech32.MustMarshalPubKey'
83+
- linters:
84+
- staticcheck
85+
text: 'SA1019: legacybech32.MarshalPubKey'
86+
- linters:
87+
- staticcheck
88+
text: 'SA1019: legacybech32.UnmarshalPubKey'
89+
- linters:
90+
- staticcheck
91+
text: 'SA1019: params.SendEnabled is deprecated'
92+
- linters:
93+
- gosec
94+
text: 'G115: integer overflow conversion'
95+
- linters:
96+
- nolintlint
97+
text: leading space
98+
paths:
99+
- server/grpc/gogoreflection/fix_registration.go
100+
- fix_registration.go
101+
- .*\.pb\.go$
102+
- .*\.pb\.gw\.go$
103+
- .*\.pulsar\.go$
104+
- crypto/keys/secp256k1/internal/*
105+
- types/coin_regex.go
106+
- testutil/testdata
107+
- x/params
108+
- x/crisis
109+
- third_party$
110+
- builtin$
111+
- examples$
37112
issues:
38-
exclude-dirs:
39-
- testutil/testdata
40-
- x/params
41-
- x/crisis
42-
exclude-files:
43-
- server/grpc/gogoreflection/fix_registration.go
44-
- "fix_registration.go"
45-
- ".*\\.pb\\.go$"
46-
- ".*\\.pb\\.gw\\.go$"
47-
- ".*\\.pulsar\\.go$"
48-
- crypto/keys/secp256k1/internal/*
49-
- types/coin_regex.go
50-
exclude-rules:
51-
- text: "ST1003:" # We are fine with our current naming
52-
linters:
53-
- stylecheck
54-
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
55-
# https://github.com/dominikh/go-tools/issues/389
56-
- text: "ST1016:" # Ok with inconsistent receiver names
57-
linters:
58-
- stylecheck
59-
- path: "migrations" # migraitions always use deprecated code
60-
text: "SA1019:"
61-
linters:
62-
- staticcheck
63-
- text: "SA1019: codec.NewAminoCodec is deprecated" # TODO remove once migration path is set out
64-
linters:
65-
- staticcheck
66-
- text: "SA1019: legacybech32.MustMarshalPubKey" # TODO remove once ready to remove from the sdk
67-
linters:
68-
- staticcheck
69-
- text: "SA1019: legacybech32.MarshalPubKey" # TODO remove once ready to remove from the sdk
70-
linters:
71-
- staticcheck
72-
- text: "SA1019: legacybech32.UnmarshalPubKey" # TODO remove once ready to remove from the sdk
73-
linters:
74-
- staticcheck
75-
- text: "SA1019: params.SendEnabled is deprecated" # TODO remove once ready to remove from the sdk
76-
linters:
77-
- staticcheck
78-
- text: "G115: integer overflow conversion" # We are doing this everywhere.
79-
linters:
80-
- gosec
81-
- text: "leading space"
82-
linters:
83-
- nolintlint
84113
max-issues-per-linter: 10000
85114
max-same-issues: 10000
86-
87-
linters-settings:
88-
gci:
89-
custom-order: true
90-
sections:
91-
- standard # Standard section: captures all standard packages.
92-
- default # Default section: contains all imports that could not be matched to another section type.
93-
- prefix(cosmossdk.io)
94-
- prefix(github.com/cosmos/cosmos-sdk)
95-
revive:
96-
rules:
97-
- name: redefines-builtin-id
98-
disabled: true
99-
100-
gosec:
101-
# Available rules: https://github.com/securego/gosec#available-rules
102-
excludes:
103-
- G101 # Potential hardcoded credentials
104-
- G107 # Potential HTTP request made with variable url
105-
- G404 # Use of weak random number generator (math/rand instead of crypto/rand)
106-
exclude-generated: true
107-
confidence: medium
108-
misspell:
109-
locale: US
110-
gofumpt:
111-
extra-rules: true
112-
dogsled:
113-
max-blank-identifiers: 6
114-
nolintlint:
115-
allow-unused: false
116-
require-explanation: true
117-
require-specific: false
118-
gosimple:
119-
checks: ["all"]
120-
gocritic:
121-
disabled-checks:
122-
- regexpMust
123-
- appendAssign
124-
- ifElseChain
125-
unused:
126-
local-variables-are-used: false
115+
formatters:
116+
enable:
117+
- gci
118+
- gofumpt
119+
settings:
120+
gci:
121+
sections:
122+
- standard
123+
- default
124+
- prefix(cosmossdk.io)
125+
- prefix(github.com/cosmos/cosmos-sdk)
126+
custom-order: true
127+
gofumpt:
128+
extra-rules: true
129+
exclusions:
130+
generated: lax
131+
paths:
132+
- server/grpc/gogoreflection/fix_registration.go
133+
- fix_registration.go
134+
- .*\.pb\.go$
135+
- .*\.pb\.gw\.go$
136+
- .*\.pulsar\.go$
137+
- crypto/keys/secp256k1/internal/*
138+
- types/coin_regex.go
139+
- testutil/testdata
140+
- x/params
141+
- x/crisis
142+
- third_party$
143+
- builtin$
144+
- examples$

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,11 @@ benchmark:
382382
### Linting ###
383383
###############################################################################
384384

385-
golangci_version=v1.64.8
385+
golangci_version=v2.0.0
386386

387387
lint-install:
388388
@echo "--> Installing golangci-lint $(golangci_version)"
389-
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version)
389+
@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(golangci_version)
390390

391391
lint:
392392
@echo "--> Running linter on all files"

baseapp/abci.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,11 @@ func (app *BaseApp) ApplySnapshotChunk(req *abci.RequestApplySnapshotChunk) (*ab
340340
func (app *BaseApp) CheckTx(req *abci.RequestCheckTx) (*abci.ResponseCheckTx, error) {
341341
var mode execMode
342342

343-
switch {
344-
case req.Type == abci.CheckTxType_New:
343+
switch req.Type {
344+
case abci.CheckTxType_New:
345345
mode = execModeCheck
346346

347-
case req.Type == abci.CheckTxType_Recheck:
347+
case abci.CheckTxType_Recheck:
348348
mode = execModeReCheck
349349

350350
default:

baseapp/baseapp.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -937,12 +937,13 @@ func (app *BaseApp) runTx(mode execMode, txBytes []byte) (gInfo sdk.GasInfo, res
937937
anteEvents = events.ToABCIEvents()
938938
}
939939

940-
if mode == execModeCheck {
940+
switch mode {
941+
case execModeCheck:
941942
err = app.mempool.Insert(ctx, tx)
942943
if err != nil {
943944
return gInfo, nil, anteEvents, err
944945
}
945-
} else if mode == execModeFinalize {
946+
case execModeFinalize:
946947
err = app.mempool.Remove(tx)
947948
if err != nil && !errors.Is(err, mempool.ErrTxNotFound) {
948949
return gInfo, nil, anteEvents,

baseapp/baseapp_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -829,11 +829,12 @@ var ctxTypes = []ctxType{QueryCtx, CheckTxCtx}
829829

830830
func (c ctxType) GetCtx(t *testing.T, bapp *baseapp.BaseApp) sdk.Context {
831831
t.Helper()
832-
if c == QueryCtx {
832+
switch c {
833+
case QueryCtx:
833834
ctx, err := bapp.CreateQueryContext(1, false)
834835
require.NoError(t, err)
835836
return ctx
836-
} else if c == CheckTxCtx {
837+
case CheckTxCtx:
837838
return getCheckStateCtx(bapp)
838839
}
839840
// TODO: Not supported yet

baseapp/grpcrouter_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestGRPCQueryRouter(t *testing.T) {
5656
func TestGRPCRouterHybridHandlers(t *testing.T) {
5757
assertRouterBehaviour := func(helper *baseapp.QueryServiceTestHelper) {
5858
// test getting the handler by name
59-
handlers := helper.GRPCQueryRouter.HybridHandlerByRequestName("testpb.EchoRequest")
59+
handlers := helper.HybridHandlerByRequestName("testpb.EchoRequest")
6060
require.NotNil(t, handlers)
6161
require.Len(t, handlers, 1)
6262
handler := handlers[0]

baseapp/info.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ type voteInfoWrapper struct {
9898
var _ comet.VoteInfo = (*voteInfoWrapper)(nil)
9999

100100
func (v voteInfoWrapper) GetBlockIDFlag() comet.BlockIDFlag {
101-
return comet.BlockIDFlag(v.VoteInfo.BlockIdFlag)
101+
return comet.BlockIDFlag(v.BlockIdFlag)
102102
}
103103

104104
func (v voteInfoWrapper) Validator() comet.Validator {
@@ -159,11 +159,11 @@ func (r prepareProposalInfo) GetValidatorsHash() []byte {
159159
}
160160

161161
func (r prepareProposalInfo) GetProposerAddress() []byte {
162-
return r.RequestPrepareProposal.ProposerAddress
162+
return r.ProposerAddress
163163
}
164164

165165
func (r prepareProposalInfo) GetLastCommit() comet.CommitInfo {
166-
return extendedCommitInfoWrapper{r.RequestPrepareProposal.LocalLastCommit}
166+
return extendedCommitInfoWrapper{r.LocalLastCommit}
167167
}
168168

169169
var _ comet.BlockInfo = (*prepareProposalInfo)(nil)
@@ -203,7 +203,7 @@ type extendedVoteInfoWrapper struct {
203203
var _ comet.VoteInfo = (*extendedVoteInfoWrapper)(nil)
204204

205205
func (e extendedVoteInfoWrapper) GetBlockIDFlag() comet.BlockIDFlag {
206-
return comet.BlockIDFlag(e.ExtendedVoteInfo.BlockIdFlag)
206+
return comet.BlockIDFlag(e.BlockIdFlag)
207207
}
208208

209209
func (e extendedVoteInfoWrapper) Validator() comet.Validator {

client/grpc_query_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
9999

100100
// end of app init
101101

102-
s.ctx = app.BaseApp.NewContext(false)
102+
s.ctx = app.NewContext(false)
103103
s.cdc = cdc
104104
queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, interfaceRegistry)
105105
types.RegisterQueryServer(queryHelper, bankKeeper)

client/keys/parse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func doParseKey(cmd *cobra.Command, config *sdk.Config, args []string) error {
9999
}
100100

101101
output, _ := cmd.Flags().GetString(flags.FlagOutput)
102-
if !(runFromBech32(outstream, addr, output) || runFromHex(config, outstream, addr, output)) {
102+
if !runFromBech32(outstream, addr, output) && !runFromHex(config, outstream, addr, output) {
103103
return errors.New("couldn't find valid bech32 nor hex data")
104104
}
105105

client/v2/autocli/msg.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor
121121
clientCtx = clientCtx.WithOutput(cmd.OutOrStdout())
122122

123123
fd := input.Descriptor().Fields().ByName(protoreflect.Name(flag.GetSignerFieldName(input.Descriptor())))
124-
addressCodec := b.Builder.AddressCodec
124+
addressCodec := b.AddressCodec
125125

126126
// set signer to signer field if empty
127127
if addr := input.Get(fd).String(); addr == "" {
@@ -130,9 +130,9 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor
130130
// override address codec if validator or consensus address
131131
switch scalarType {
132132
case flag.ValidatorAddressStringScalarType:
133-
addressCodec = b.Builder.ValidatorAddressCodec
133+
addressCodec = b.ValidatorAddressCodec
134134
case flag.ConsensusAddressStringScalarType:
135-
addressCodec = b.Builder.ConsensusAddressCodec
135+
addressCodec = b.ConsensusAddressCodec
136136
}
137137
}
138138

0 commit comments

Comments
 (0)