Skip to content

Commit b8361aa

Browse files
author
Alex | Interchain Labs
authored
chore: update to golangci-lint v2 (cosmos#202)
* fix * fix-lint * lint-go * fix
1 parent a068a20 commit b8361aa

Some content is hidden

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

48 files changed

+217
-221
lines changed

.github/workflows/lint.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ jobs:
1313
runs-on: ubuntu-latest
1414
timeout-minutes: 10
1515
steps:
16-
# Required: setup-go, for all versions v3.0.0+ of golangci-lint
1716
- uses: actions/setup-go@v5
1817
with:
19-
go-version: '1.22'
18+
go-version: '1.24'
2019
check-latest: true
2120
- uses: actions/checkout@v4
2221
- uses: technote-space/get-diff-action@v6.1.2
@@ -26,14 +25,11 @@ jobs:
2625
go.mod
2726
go.sum
2827
*.toml
29-
- uses: golangci/golangci-lint-action@v6.2.0
30-
with:
31-
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
32-
version: latest
33-
args: --timeout 10m
34-
github-token: ${{ secrets.github_token }}
35-
# Check only if there are differences in the source code
28+
- name: run linting
3629
if: env.GIT_DIFF
30+
id: lint_long
31+
run: |
32+
make lint-go
3733
markdown-lint:
3834
name: Run markdown-lint
3935
runs-on: ubuntu-latest

.golangci.yml

Lines changed: 94 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,117 @@
1+
version: "2"
12
run:
23
tests: true
3-
# timeout for analysis, e.g. 30s, 5m, default is 1m
4-
timeout: 5m
5-
64
linters:
7-
disable-all: true
5+
default: none
86
enable:
7+
- copyloopvar
98
- dogsled
109
- errcheck
11-
- copyloopvar
12-
- gci
1310
- goconst
1411
- gocritic
15-
- gofumpt
1612
- gosec
17-
- gosimple
1813
- govet
1914
- ineffassign
2015
- misspell
2116
- nakedret
2217
- nolintlint
2318
- revive
2419
- staticcheck
25-
- stylecheck
26-
- typecheck
2720
- thelper
2821
- unconvert
2922
- unparam
3023
- unused
31-
24+
settings:
25+
dogsled:
26+
max-blank-identifiers: 3
27+
nolintlint:
28+
require-explanation: false
29+
require-specific: false
30+
allow-unused: false
31+
revive:
32+
severity: warning
33+
rules:
34+
- name: unused-parameter
35+
disabled: true
36+
- name: blank-imports
37+
- name: context-as-argument
38+
- name: context-keys-type
39+
- name: dot-imports
40+
- name: error-return
41+
- name: error-strings
42+
- name: error-naming
43+
- name: exported
44+
- name: if-return
45+
- name: increment-decrement
46+
- name: var-naming
47+
- name: var-declaration
48+
- name: range
49+
- name: receiver-naming
50+
- name: time-naming
51+
- name: unexported-return
52+
- name: indent-error-flow
53+
- name: errorf
54+
- name: empty-block
55+
- name: superfluous-else
56+
- name: unreachable-code
57+
- name: redefines-builtin-id
58+
exclusions:
59+
generated: lax
60+
presets:
61+
- comments
62+
- common-false-positives
63+
- legacy
64+
- std-error-handling
65+
rules:
66+
- linters:
67+
- gosec
68+
text: Use of weak random number generator
69+
- linters:
70+
- golint
71+
text: comment on exported var
72+
- linters:
73+
- golint
74+
text: don't use an underscore in package name
75+
- linters:
76+
- staticcheck
77+
text: 'ST1003:'
78+
- linters:
79+
- staticcheck
80+
text: 'ST1016:'
81+
- linters:
82+
- staticcheck
83+
path: migrations
84+
text: 'SA1019:'
85+
paths:
86+
- x/vm/core
87+
- third_party$
88+
- builtin$
89+
- examples$
3290
issues:
33-
exclude-rules:
34-
- text: 'Use of weak random number generator'
35-
linters:
36-
- gosec
37-
- text: 'comment on exported var'
38-
linters:
39-
- golint
40-
- text: "don't use an underscore in package name"
41-
linters:
42-
- golint
43-
- text: 'ST1003:'
44-
linters:
45-
- stylecheck
46-
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
47-
# https://github.com/dominikh/go-tools/issues/389
48-
- text: 'ST1016:'
49-
linters:
50-
- stylecheck
51-
- path: 'migrations'
52-
text: 'SA1019:'
53-
linters:
54-
- staticcheck
55-
exclude-dirs:
56-
- x/vm/core
57-
5891
max-issues-per-linter: 10000
5992
max-same-issues: 10000
60-
61-
linters-settings:
62-
gci:
63-
custom-order: true
64-
sections:
65-
- standard # Standard section: captures all standard packages.
66-
- default # Default section: contains all imports that could not be matched to another section type.
67-
- blank # blank imports
68-
- dot # dot imports
69-
- prefix(github.com/cometbft/cometbft) # comet
70-
- prefix(github.com/cosmos) # cosmos org
71-
- prefix(cosmossdk.io) # new modules
72-
- prefix(github.com/cosmos/cosmos-sdk) # cosmos sdk
73-
- prefix(github.com/CosmWasm/wasmd) # cosmwasm
74-
- prefix(github.com/cosmos/gaia) # Gaia
75-
dogsled:
76-
max-blank-identifiers: 3
77-
maligned:
78-
# print struct with more effective memory layout or not, false by default
79-
suggest-new: true
80-
nolintlint:
81-
allow-unused: false
82-
allow-leading-space: true
83-
require-explanation: false
84-
require-specific: false
85-
revive:
86-
ignore-generated-header: true
87-
severity: warning
88-
rules:
89-
- name: unused-parameter
90-
disabled: true
91-
- name: blank-imports
92-
- name: context-as-argument
93-
- name: context-keys-type
94-
- name: dot-imports
95-
- name: error-return
96-
- name: error-strings
97-
- name: error-naming
98-
- name: exported
99-
- name: if-return
100-
- name: increment-decrement
101-
- name: var-naming
102-
- name: var-declaration
103-
- name: range
104-
- name: receiver-naming
105-
- name: time-naming
106-
- name: unexported-return
107-
- name: indent-error-flow
108-
- name: errorf
109-
- name: empty-block
110-
- name: superfluous-else
111-
- name: unreachable-code
112-
- name: redefines-builtin-id
93+
formatters:
94+
enable:
95+
- gci
96+
- gofumpt
97+
settings:
98+
gci:
99+
sections:
100+
- standard
101+
- default
102+
- blank
103+
- dot
104+
- prefix(github.com/cometbft/cometbft)
105+
- prefix(github.com/cosmos)
106+
- prefix(cosmossdk.io)
107+
- prefix(github.com/cosmos/cosmos-sdk)
108+
- prefix(github.com/CosmWasm/wasmd)
109+
- prefix(github.com/cosmos/gaia)
110+
custom-order: true
111+
exclusions:
112+
generated: lax
113+
paths:
114+
- x/vm/core
115+
- third_party$
116+
- builtin$
117+
- examples$

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ benchmark:
167167
### Linting ###
168168
###############################################################################
169169
golangci_lint_cmd=golangci-lint
170-
golangci_version=v1.64.8
170+
golangci_version=v2.1.6
171171

172172
lint: lint-go lint-python lint-contracts
173173

174174
lint-go:
175175
@echo "--> Running linter"
176-
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version)
176+
@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(golangci_version)
177177
@$(golangci_lint_cmd) run --timeout=10m
178178

179179
lint-python:
@@ -184,7 +184,7 @@ lint-contracts:
184184
solhint contracts/**/*.sol
185185

186186
lint-fix:
187-
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version)
187+
@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(golangci_version)
188188
@$(golangci_lint_cmd) run --timeout=10m --fix
189189

190190
lint-fix-contracts:

ethereum/eip712/eip712_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ func (suite *EIP712TestSuite) TestTypedDataErrorHandling() {
542542

543543
messagesArr.WriteString("[")
544544
for i := 0; i < maxRecursionDepth; i++ {
545-
messagesArr.WriteString(fmt.Sprintf(`{ "type": "msgType", "value": { "field%v": 10 } }`, i))
545+
fmt.Fprintf(messagesArr, `{ "type": "msgType", "value": { "field%v": 10 } }`, i)
546546
if i != maxRecursionDepth-1 {
547547
messagesArr.WriteString(",")
548548
}

evmd/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,14 +998,14 @@ func (app *EVMD) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfi
998998

999999
// RegisterTxService implements the Application.RegisterTxService method.
10001000
func (app *EVMD) RegisterTxService(clientCtx client.Context) {
1001-
authtx.RegisterTxService(app.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
1001+
authtx.RegisterTxService(app.GRPCQueryRouter(), clientCtx, app.Simulate, app.interfaceRegistry)
10021002
}
10031003

10041004
// RegisterTendermintService implements the Application.RegisterTendermintService method.
10051005
func (app *EVMD) RegisterTendermintService(clientCtx client.Context) {
10061006
cmtservice.RegisterTendermintService(
10071007
clientCtx,
1008-
app.BaseApp.GRPCQueryRouter(),
1008+
app.GRPCQueryRouter(),
10091009
app.interfaceRegistry,
10101010
app.Query,
10111011
)

evmd/export.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (app *EVMD) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddr
4747
AppState: appState,
4848
Validators: validators,
4949
Height: height,
50-
ConsensusParams: app.BaseApp.GetConsensusParams(ctx),
50+
ConsensusParams: app.GetConsensusParams(ctx),
5151
}, err
5252
}
5353

@@ -56,15 +56,10 @@ func (app *EVMD) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddr
5656
//
5757
// in favour of export at a block height
5858
func (app *EVMD) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) error {
59-
applyAllowedAddrs := false
60-
61-
// check if there is a allowed address list
62-
if len(jailAllowedAddrs) > 0 {
63-
applyAllowedAddrs = true
64-
}
59+
applyAllowedAddrs := len(jailAllowedAddrs) > 0
6560

61+
// check if there is an allowed address list
6662
allowedAddrsMap := make(map[string]bool)
67-
6863
for _, addr := range jailAllowedAddrs {
6964
_, err := sdk.ValAddressFromBech32(addr)
7065
if err != nil {

evmd/testutil/abci.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func CommitAndCreateNewCtx(ctx sdk.Context, app *app.EVMD, t time.Duration, vs *
4646
// NewContext function keeps the multistore
4747
// but resets other context fields
4848
// GasMeter is set as InfiniteGasMeter
49-
newCtx := app.BaseApp.NewContextLegacy(false, header)
49+
newCtx := app.NewContextLegacy(false, header)
5050
// set the reseted fields to keep the current ctx settings
5151
newCtx = newCtx.WithMinGasPrices(ctx.MinGasPrices())
5252
newCtx = newCtx.WithEventManager(ctx.EventManager())
@@ -248,7 +248,7 @@ func checkTxBytes(app *app.EVMD, txEncoder sdk.TxEncoder, tx sdk.Tx) (abci.Respo
248248
}
249249

250250
req := abci.RequestCheckTx{Tx: bz}
251-
res, err := app.BaseApp.CheckTx(&req)
251+
res, err := app.CheckTx(&req)
252252
if err != nil {
253253
return abci.ResponseCheckTx{}, err
254254
}

indexer/kv_indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func NewKVIndexer(db dbm.DB, logger log.Logger, clientCtx client.Context) *KVInd
5050
// - Iterates over all the messages of the Tx
5151
// - Builds and stores a indexer.TxResult based on parsed events for every message
5252
func (kv *KVIndexer) IndexBlock(block *cmttypes.Block, txResults []*abci.ExecTxResult) error {
53-
height := block.Header.Height
53+
height := block.Height
5454

5555
batch := kv.db.NewBatch()
5656
defer batch.Close()

indexer/kv_indexer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ func TestKVIndexer(t *testing.T) {
174174
} else {
175175
first, err := idxer.FirstIndexedBlock()
176176
require.NoError(t, err)
177-
require.Equal(t, tc.block.Header.Height, first)
177+
require.Equal(t, tc.block.Height, first)
178178

179179
last, err := idxer.LastIndexedBlock()
180180
require.NoError(t, err)
181-
require.Equal(t, tc.block.Header.Height, last)
181+
require.Equal(t, tc.block.Height, last)
182182

183183
res1, err := idxer.GetByTxHash(txHash)
184184
require.NoError(t, err)

0 commit comments

Comments
 (0)