Skip to content

Commit 7b07eb4

Browse files
authored
Add lints for unclosed files and fix numerous lints in tests (#18998)
Add the temp file lints needed to catch the locked file issue I had on Windows tests here #18197. Also fixes a bunch of other lints that were masked for tests.
1 parent d6eea8c commit 7b07eb4

File tree

67 files changed

+910
-597
lines changed

Some content is hidden

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

67 files changed

+910
-597
lines changed

.claude/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(make test-all:*)",
5+
"Bash(go test:*)",
6+
"Bash(go get:*)",
7+
"Bash(GOEXPERIMENT=synctest go vet:*)",
8+
"Bash(make lint:*)",
9+
"Bash(git fetch:*)",
10+
"Bash(go mod tidy:*)"
11+
]
12+
}
13+
}

.github/workflows/lint.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,4 @@ jobs:
4848
with:
4949
go-version: '1.25'
5050

51-
- name: Install golangci-lint
52-
uses: golangci/golangci-lint-action@v9
53-
with:
54-
version: 'v2.8.0'
55-
5651
- run: make lint

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ linters:
113113
- staticcheck
114114
text: ST1019|ST1029|ST5011|QF1003|SA1019|QF1008|S1021|QF1001|SA6005|S1002|QF1002|QF1012|QF1006|ST1005|SA5011|ST1023|ST1012|QF1011|S1019|S1000|S1000|S1009|ST1008|S1016|S1016|ST1017|SA4009|QF1007|SA6002|QF1010|SA9003
115115
- linters:
116-
- gocritic
117116
- gosec
118117
- perfsprint
119118
- unused

Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,6 @@ kurtosis-cleanup:
345345
@echo "-----------------------------------\n"
346346
kurtosis enclave rm -f makefile-kurtosis-testnet
347347

348-
## lint-deps: install lint dependencies
349-
lint-deps:
350-
@./tools/golangci_lint.sh --install-deps
351-
352348
## lintci: run golangci-lint linters
353349
lintci:
354350
@CGO_CXXFLAGS="$(CGO_CXXFLAGS)" ./tools/golangci_lint.sh

agents.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,17 @@ Erigon is a high-performance Ethereum execution client with embedded consensus l
5555
Commit messages: prefix with package(s) modified, e.g., `eth, rpc: make trace configs optional`
5656

5757
**Important**: Always run `make lint` after making code changes and before committing. Fix any linter errors before proceeding.
58+
59+
## Lint Notes
60+
61+
The linter (`make lint`) is non-deterministic in which files it scans — new issues may appear on subsequent runs. Run lint repeatedly until clean.
62+
63+
Common lint categories and fixes:
64+
- **ruleguard (defer tx.Rollback/cursor.Close):** The error check must come *before* `defer tx.Rollback()`. Never remove an explicit `.Close()` or `.Rollback()` — add `defer` as a safety net alongside it, since the timing of the explicit call may matter.
65+
- **prealloc:** Pre-allocate slices when the length is known from a range.
66+
- **unslice:** Remove redundant `[:]` on variables that are already slices.
67+
- **newDeref:** Replace `*new(T)` with `T{}`.
68+
- **appendCombine:** Combine consecutive `append` calls into one.
69+
- **rangeExprCopy:** Use `&x` in `range` to avoid copying large arrays.
70+
- **dupArg:** For intentional `x.Equal(x)` self-equality tests, suppress with `//nolint:gocritic`.
71+
- **Loop ruleguard in benchmarks:** For `BeginRw`/`BeginRo` inside loops where `defer` doesn't apply, suppress with `//nolint:gocritic`.

cl/cltypes/solid/sync_committee_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestSyncCommittee(t *testing.T) {
7979
// Test Equal
8080
otherSyncCommittee := &SyncCommittee{}
8181
assert.False(t, syncCommittee.Equal(otherSyncCommittee))
82-
assert.True(t, syncCommittee.Equal(syncCommittee))
82+
assert.True(t, syncCommittee.Equal(syncCommittee)) //nolint:gocritic
8383

8484
// Test HashSSZ
8585
expectedRoot := common.HexToHash("28628f3f10fa1070f2a42aeeeae792cd6ded1ef81030104e765e1498a1cfcfbd") // Example expected root

cl/persistence/beacon_indicies/indicies_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func setupTestDB(t *testing.T) kv.RwDB {
3939
func TestWriteBlockRoot(t *testing.T) {
4040
db := setupTestDB(t)
4141
defer db.Close()
42-
tx, _ := db.BeginRw(context.Background())
42+
tx, err := db.BeginRw(context.Background())
43+
require.NoError(t, err)
4344
defer tx.Rollback()
4445

4546
// Mock a block
@@ -72,7 +73,8 @@ func TestWriteBlockRoot(t *testing.T) {
7273
func TestReadParentBlockRoot(t *testing.T) {
7374
db := setupTestDB(t)
7475
defer db.Close()
75-
tx, _ := db.BeginRw(context.Background())
76+
tx, err := db.BeginRw(context.Background())
77+
require.NoError(t, err)
7678
defer tx.Rollback()
7779

7880
mockParentRoot := common.Hash{1}
@@ -96,7 +98,8 @@ func TestReadParentBlockRoot(t *testing.T) {
9698
func TestTruncateCanonicalChain(t *testing.T) {
9799
db := setupTestDB(t)
98100
defer db.Close()
99-
tx, _ := db.BeginRw(context.Background())
101+
tx, err := db.BeginRw(context.Background())
102+
require.NoError(t, err)
100103
defer tx.Rollback()
101104

102105
mockParentRoot := common.Hash{1}
@@ -126,7 +129,8 @@ func TestTruncateCanonicalChain(t *testing.T) {
126129
func TestReadBeaconBlockHeader(t *testing.T) {
127130
db := setupTestDB(t)
128131
defer db.Close()
129-
tx, _ := db.BeginRw(context.Background())
132+
tx, err := db.BeginRw(context.Background())
133+
require.NoError(t, err)
130134
defer tx.Rollback()
131135

132136
mockParentRoot := common.Hash{1}
@@ -162,7 +166,8 @@ func TestReadBeaconBlockHeader(t *testing.T) {
162166
func TestWriteExecutionBlockNumber(t *testing.T) {
163167
db := setupTestDB(t)
164168
defer db.Close()
165-
tx, _ := db.BeginRw(context.Background())
169+
tx, err := db.BeginRw(context.Background())
170+
require.NoError(t, err)
166171
defer tx.Rollback()
167172

168173
tHash := common.HexToHash("0x2")
@@ -179,7 +184,8 @@ func TestWriteExecutionBlockNumber(t *testing.T) {
179184
func TestWriteExecutionBlockHash(t *testing.T) {
180185
db := setupTestDB(t)
181186
defer db.Close()
182-
tx, _ := db.BeginRw(context.Background())
187+
tx, err := db.BeginRw(context.Background())
188+
require.NoError(t, err)
183189
defer tx.Rollback()
184190

185191
tHash := common.HexToHash("0x2")

cl/sentinel/handlers/blobs_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ func TestBlobsByRangeHandler(t *testing.T) {
8686
_, indiciesDB := setupStore(t)
8787
store := tests.NewMockBlockReader()
8888

89-
tx, _ := indiciesDB.BeginRw(ctx)
89+
tx, err := indiciesDB.BeginRw(ctx)
90+
require.NoError(t, err)
91+
defer tx.Rollback()
9092

9193
startSlot := uint64(100)
9294
count := uint64(10)
@@ -99,7 +101,7 @@ func TestBlobsByRangeHandler(t *testing.T) {
99101
r, _ := h.Header.HashSSZ()
100102
require.NoError(t, blobStorage.WriteBlobSidecars(ctx, r, sidecars))
101103

102-
tx.Commit()
104+
require.NoError(t, tx.Commit())
103105

104106
ethClock := getEthClock(t)
105107
c := NewConsensusHandlers(
@@ -207,7 +209,9 @@ func TestBlobsByIdentifiersHandler(t *testing.T) {
207209
_, indiciesDB := setupStore(t)
208210
store := tests.NewMockBlockReader()
209211

210-
tx, _ := indiciesDB.BeginRw(ctx)
212+
tx, err := indiciesDB.BeginRw(ctx)
213+
require.NoError(t, err)
214+
defer tx.Rollback()
211215

212216
startSlot := uint64(100)
213217
count := uint64(10)
@@ -221,7 +225,7 @@ func TestBlobsByIdentifiersHandler(t *testing.T) {
221225
r, _ := h.Header.HashSSZ()
222226
require.NoError(t, blobStorage.WriteBlobSidecars(ctx, r, sidecars))
223227

224-
tx.Commit()
228+
require.NoError(t, tx.Commit())
225229

226230
c := NewConsensusHandlers(
227231
ctx,

cl/sentinel/handlers/blocks_by_range_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,16 @@ func TestBlocksByRootHandler(t *testing.T) {
6262
_, indiciesDB := setupStore(t)
6363
store := tests.NewMockBlockReader()
6464

65-
tx, _ := indiciesDB.BeginRw(ctx)
65+
tx, err := indiciesDB.BeginRw(ctx)
66+
require.NoError(t, err)
67+
defer tx.Rollback()
6668

6769
startSlot := uint64(100)
6870
count := uint64(10)
6971
step := uint64(1)
7072

7173
expBlocks := populateDatabaseWithBlocks(t, store, tx, startSlot, count)
72-
tx.Commit()
74+
require.NoError(t, tx.Commit())
7375

7476
ethClock := getEthClock(t)
7577
_, beaconCfg := clparams.GetConfigsByNetwork(1)

cl/sentinel/handlers/blocks_by_root_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ func TestBlocksByRangeHandler(t *testing.T) {
6464
_, indiciesDB := setupStore(t)
6565
store := tests.NewMockBlockReader()
6666

67-
tx, _ := indiciesDB.BeginRw(ctx)
67+
tx, err := indiciesDB.BeginRw(ctx)
68+
require.NoError(t, err)
69+
defer tx.Rollback()
6870

6971
startSlot := uint64(100)
7072
count := uint64(10)
@@ -161,5 +163,4 @@ func TestBlocksByRangeHandler(t *testing.T) {
161163
}
162164

163165
defer indiciesDB.Close()
164-
defer tx.Rollback()
165166
}

0 commit comments

Comments
 (0)