Skip to content

Commit 2c75e9e

Browse files
authored
chore: add stricter linting (#3132)
* add stricterlinting * revert some changes and enable prealloc and predeclared * ci * fix lint * fix comments * fix * remove spec * test stability
1 parent f8fa22e commit 2c75e9e

28 files changed

+279
-149
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- uses: golangci/golangci-lint-action@v9.2.0
3030
with:
3131
version: latest
32-
args: --timeout 10m
32+
args: --timeout 10m ./...
3333
github-token: ${{ secrets.github_token }}
3434
if: env.GIT_DIFF
3535

.golangci.yml

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,57 @@
11
version: "2"
22
run:
33
modules-download-mode: readonly
4+
timeout: 10m
5+
tests: true
46
build-tags:
57
- evm
68
- e2e
79
- docker
810
linters:
911
enable:
12+
- asciicheck
13+
- bidichk
14+
- bodyclose
15+
- contextcheck
16+
- copyloopvar
17+
- durationcheck
18+
- errname
1019
- errorlint
20+
- govet
21+
- ineffassign
22+
- makezero
1123
- gosec
1224
- misspell
25+
- nilerr
26+
- noctx
27+
- prealloc
28+
- predeclared
29+
- reassign
1330
- revive
31+
- rowserrcheck
32+
- sqlclosecheck
33+
- staticcheck
1434
- unconvert
35+
- unused
36+
- usestdlibvars
37+
- wastedassign
1538
settings:
39+
errcheck:
40+
check-type-assertions: true
41+
check-blank: true
42+
govet:
43+
enable-all: true
44+
disable:
45+
- fieldalignment
46+
- shadow
47+
gocritic:
48+
enabled-tags:
49+
- diagnostic
50+
- style
51+
- performance
52+
disabled-checks:
53+
- hugeParam
54+
- rangeValCopy
1655
gosec:
1756
excludes:
1857
- G115
@@ -21,7 +60,7 @@ linters:
2160
- name: package-comments
2261
disabled: true
2362
- name: duplicated-imports
24-
severity: warning
63+
severity: error
2564
- name: exported
2665
arguments:
2766
- disableStutteringCheck
@@ -32,10 +71,28 @@ linters:
3271
- common-false-positives
3372
- legacy
3473
- std-error-handling
74+
rules:
75+
- path: _test\.go
76+
linters:
77+
- prealloc
78+
- noctx
3579
paths:
3680
- third_party$
3781
- builtin$
3882
- examples$
83+
disable:
84+
- containedctx
85+
- errcheck
86+
- gocritic
87+
- nolintlint
88+
- testifylint
89+
- thelper
90+
- tparallel
91+
- unparam
92+
- wrapcheck
93+
issues:
94+
max-issues-per-linter: 0
95+
max-same-issues: 0
3996
formatters:
4097
enable:
4198
- gci

.just/lint.just

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[group('lint')]
33
lint: vet
44
@echo "--> Running golangci-lint"
5-
@golangci-lint run
5+
@golangci-lint run ./...
66
@echo "--> Running markdownlint"
77
@markdownlint --config .markdownlint.yaml '**/*.md'
88
@echo "--> Running hadolint"
@@ -18,7 +18,7 @@ lint: vet
1818
[group('lint')]
1919
lint-fix:
2020
@echo "--> Formatting go"
21-
@golangci-lint run --fix
21+
@golangci-lint run --fix ./...
2222
@echo "--> Formatting markdownlint"
2323
@markdownlint --config .markdownlint.yaml --ignore './changelog.md' '**/*.md' -f
2424

block/internal/da/async_block_retriever_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,6 @@ func TestBlockData_SerializationEmpty(t *testing.T) {
266266
}
267267

268268
assert.Equal(t, uint64(100), decoded.Height)
269+
assert.Equal(t, time.Unix(0, 0).UTC(), decoded.Timestamp)
269270
assert.Equal(t, 0, len(decoded.Blobs))
270271
}

block/internal/executing/executor.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,6 @@ func (e *Executor) executionLoop() {
381381
} else {
382382
delay = time.Until(currentState.LastBlockTime.Add(e.config.Node.BlockTime.Duration))
383383
}
384-
385384
if delay > 0 {
386385
e.logger.Info().Dur("delay", delay).Msg("waiting to start block production")
387386
select {
@@ -591,7 +590,7 @@ func (e *Executor) ProduceBlock(ctx context.Context) error {
591590
LastSubmittedDaHeaderHeight: e.cache.GetLastSubmittedHeaderHeight(),
592591
LastSubmittedDaDataHeight: e.cache.GetLastSubmittedDataHeight(),
593592
}
594-
if err := e.raftNode.Broadcast(e.ctx, raftState); err != nil {
593+
if err := e.raftNode.Broadcast(ctx, raftState); err != nil {
595594
return fmt.Errorf("failed to propose block to raft: %w", err)
596595
}
597596
e.logger.Debug().Uint64("height", newHeight).Msg("proposed block to raft")
@@ -617,12 +616,12 @@ func (e *Executor) ProduceBlock(ctx context.Context) error {
617616
// IMPORTANT: Header MUST be broadcast before data — the P2P layer validates
618617
// incoming data against the current and previous header, so out-of-order
619618
// delivery would cause validation failures on peers.
620-
if err := e.headerBroadcaster.WriteToStoreAndBroadcast(e.ctx, &types.P2PSignedHeader{
619+
if err := e.headerBroadcaster.WriteToStoreAndBroadcast(ctx, &types.P2PSignedHeader{
621620
SignedHeader: header,
622621
}); err != nil {
623622
e.logger.Error().Err(err).Msg("failed to broadcast header")
624623
}
625-
if err := e.dataBroadcaster.WriteToStoreAndBroadcast(e.ctx, &types.P2PData{
624+
if err := e.dataBroadcaster.WriteToStoreAndBroadcast(ctx, &types.P2PData{
626625
Data: data,
627626
}); err != nil {
628627
e.logger.Error().Err(err).Msg("failed to broadcast data")
@@ -637,7 +636,7 @@ func (e *Executor) ProduceBlock(ctx context.Context) error {
637636

638637
// For based sequencer, advance safe/finalized since it comes from DA.
639638
if e.config.Node.BasedSequencer {
640-
if err := e.exec.SetFinal(e.ctx, newHeight); err != nil {
639+
if err := e.exec.SetFinal(ctx, newHeight); err != nil {
641640
e.sendCriticalError(fmt.Errorf("failed to set final height in based sequencer mode: %w", err))
642641
return fmt.Errorf("failed to set final height in based sequencer mode: %w", err)
643642
}

block/internal/submitting/da_submitter.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ func (rs *retryState) Next(reason retryReason, pol retryPolicy) {
9090
}
9191

9292
// clamp constrains a duration between min and max bounds
93-
func clamp(v, min, max time.Duration) time.Duration {
94-
if min > max {
95-
min, max = max, min
93+
func clamp(v, minTime, maxTime time.Duration) time.Duration {
94+
if minTime > maxTime {
95+
minTime, maxTime = maxTime, minTime
9696
}
97-
if v < min {
98-
return min
97+
if v < minTime {
98+
return minTime
9999
}
100-
if v > max {
101-
return max
100+
if v > maxTime {
101+
return maxTime
102102
}
103103
return v
104104
}

block/internal/submitting/da_submitter_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ func TestDASubmitter_SubmitHeaders_Success(t *testing.T) {
145145

146146
// Create test signer
147147
addr, pub, signer := createTestSigner(t)
148-
gen.ProposerAddress = addr
149148

150149
// Create test headers
151150
header1 := &types.SignedHeader{

0 commit comments

Comments
 (0)