Skip to content

Commit 85d234a

Browse files
author
Alex | Interchain Labs
authored
chore: clean for new tag (#131)
* initial-lint-fix * initial-lint-fix * linted * use one test lib * cast * fixington * cl * include-rocks * version * version * fix * attempt * fix * attempt * update-lock * fix * fix-plz * fix-plz * fix wow sad * take20
1 parent ddfad04 commit 85d234a

29 files changed

+393
-251
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: DeterminateSystems/flakehub-cache-action@main
1515
- uses: actions/setup-go@v5
1616
with:
17-
go-version: "1.20"
17+
go-version: "1.23"
1818
check-latest: true
1919
- name: run lint
2020
run: nix develop -c make lint

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: DeterminateSystems/flakehub-cache-action@main
1414
- uses: actions/setup-go@v5
1515
with:
16-
go-version: "1.20"
16+
go-version: "1.23"
1717
check-latest: true
1818
cache: true
1919
cache-dependency-path: store/go.sum

.gitpod.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.golangci.yml

Lines changed: 132 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,150 @@
1+
version: "2"
12
run:
23
build-tags:
34
- rocksdb
4-
concurrency: 4
5-
sort-results: true
6-
allow-parallel-runners: true
75
tests: true
8-
6+
allow-parallel-runners: true
97
linters:
10-
disable-all: true
8+
default: none
119
enable:
10+
- copyloopvar
1211
- dogsled
13-
- dupl
1412
- errcheck
15-
- exportloopref
13+
- errorlint
1614
- goconst
1715
- gocritic
18-
- gofumpt
19-
- revive
2016
- gosec
21-
- gosimple
2217
- govet
2318
- ineffassign
24-
- lll
2519
- misspell
2620
- nakedret
27-
- prealloc
28-
- staticcheck
29-
- stylecheck
30-
- typecheck
21+
- nolintlint
3122
- revive
23+
- staticcheck
24+
- thelper
3225
- unconvert
3326
- unused
34-
- nolintlint
27+
settings:
28+
dogsled:
29+
max-blank-identifiers: 6
30+
gocritic:
31+
disabled-checks:
32+
- regexpMust
33+
- appendAssign
34+
- ifElseChain
35+
gosec:
36+
excludes:
37+
- G101
38+
- G107
39+
- G404
40+
confidence: medium
41+
misspell:
42+
locale: US
43+
nolintlint:
44+
require-explanation: true
45+
require-specific: false
46+
allow-unused: false
47+
revive:
48+
rules:
49+
- name: redefines-builtin-id
50+
disabled: true
51+
- name: exported
52+
severity: error
53+
disabled: false
54+
staticcheck:
55+
checks:
56+
- all
57+
unused:
58+
local-variables-are-used: false
59+
exclusions:
60+
generated: lax
61+
presets:
62+
- common-false-positives
63+
- legacy
64+
- std-error-handling
65+
rules:
66+
- linters:
67+
- staticcheck
68+
text: 'ST1000:'
69+
- linters:
70+
- revive
71+
text: 'or be unexported' # don't report types that have no comments at all. there are way too many of these.
72+
- linters:
73+
- staticcheck
74+
text: 'ST1003:'
75+
- linters:
76+
- staticcheck
77+
text: 'ST1016:'
78+
- linters:
79+
- staticcheck
80+
path: migrations
81+
text: 'SA1019:'
82+
- linters:
83+
- staticcheck
84+
text: 'SA1019: codec.NewAminoCodec is deprecated'
85+
- linters:
86+
- staticcheck
87+
text: 'SA1019: legacybech32.MustMarshalPubKey'
88+
- linters:
89+
- staticcheck
90+
text: 'SA1019: legacybech32.MarshalPubKey'
91+
- linters:
92+
- staticcheck
93+
text: 'SA1019: legacybech32.UnmarshalPubKey'
94+
- linters:
95+
- staticcheck
96+
text: 'SA1019: params.SendEnabled is deprecated'
97+
- linters:
98+
- gosec
99+
text: 'G115: integer overflow conversion'
100+
- linters:
101+
- nolintlint
102+
text: leading space
103+
paths:
104+
- server/grpc/gogoreflection/fix_registration.go
105+
- fix_registration.go
106+
- .*\.pb\.go$
107+
- .*\.pb\.gw\.go$
108+
- .*\.pulsar\.go$
109+
- crypto/keys/secp256k1/internal/*
110+
- types/coin_regex.go
111+
- testutil/testdata
112+
- x/params
113+
- x/crisis
114+
- third_party$
115+
- builtin$
116+
- examples$
117+
issues:
118+
max-issues-per-linter: 10000
119+
max-same-issues: 10000
120+
formatters:
121+
enable:
122+
- gci
123+
- gofumpt
124+
settings:
125+
gci:
126+
sections:
127+
- standard
128+
- default
129+
- prefix(cosmossdk.io)
130+
- prefix(github.com/cosmos/cosmos-sdk)
131+
custom-order: true
132+
gofumpt:
133+
extra-rules: true
134+
exclusions:
135+
136+
generated: lax
137+
paths:
138+
- server/grpc/gogoreflection/fix_registration.go
139+
- fix_registration.go
140+
- .*\.pb\.go$
141+
- .*\.pb\.gw\.go$
142+
- .*\.pulsar\.go$
143+
- crypto/keys/secp256k1/internal/*
144+
- types/coin_regex.go
145+
- testutil/testdata
146+
- x/params
147+
- x/crisis
148+
- third_party$
149+
- builtin$
150+
- examples$

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
# Changelog
22

3+
## [v1.1.2] - 2025-05-28
4+
5+
* Make `Iterator` and `Batch` interfaces more flexible by a type alias
6+
* Update deps to the latest versions
7+
* Update linter for general code cleanup
8+
39
## [v1.1.1] - 2024-12-19
410

511
* [#120](https://github.com/cosmos/cosmos-db/pull/120) Skip unwanted logs from PebbleDB
612

713
## [v1.1.0] - 2024-11-22
814

915
* Allow full control in rocksdb opening
10-
* Make `Iteractor` and `Batch` interfaces more flexible by a type alias
1116
* Remove build tag for PebbleDB
1217

1318
## [v1.0.2] - 2024-02-26
1419

15-
* Downgrade Go version in go.mod to 1.19
20+
* Downgrade Go version in `go.mod` to 1.19
1621

1722
## [v1.0.1] - 2024-02-25
1823

Makefile

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,20 @@ test-rocksdb:
1010
@echo "--> Running go test"
1111
@go test $(PACKAGES) -tags rocksdb -v
1212

13-
golangci_version=v1.55.0
13+
golangci_version=v2.1.6
1414

1515
#? lint-install: Install golangci-lint
1616
lint-install:
1717
@echo "--> Installing golangci-lint $(golangci_version)"
18-
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version)
18+
@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(golangci_version)
1919
.PHONY: lint-install
2020

21-
lint:
21+
lint: lint-install
2222
@echo "--> Running linter"
23-
$(MAKE) lint-install
2423
@golangci-lint run
25-
@go mod verify
26-
.PHONY: lint
2724

28-
format:
29-
find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs gofumpt -w -l .
30-
find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs golangci-lint run --fix .
31-
.PHONY: format
25+
lint-fix: lint-install
26+
@echo "--> Running linter"
27+
@golangci-lint run --fix
28+
.PHONY: lint lint-fix
29+

backend_test.go

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ import (
77
"path/filepath"
88
"testing"
99

10-
"github.com/stretchr/testify/assert"
1110
"github.com/stretchr/testify/require"
1211
)
1312

1413
// Register a test backend for PrefixDB as well, with some unrelated junk data
1514
func init() {
1615
registerDBCreator("prefixdb", func(name, dir string, opts Options) (DB, error) {
1716
mdb := NewMemDB()
18-
mdb.Set([]byte("a"), []byte{1}) //nolint:errcheck
19-
mdb.Set([]byte("b"), []byte{2}) //nolint:errcheck
20-
mdb.Set([]byte("t"), []byte{20}) //nolint:errcheck
21-
mdb.Set([]byte("test"), []byte{0}) //nolint:errcheck
22-
mdb.Set([]byte("u"), []byte{21}) //nolint:errcheck
23-
mdb.Set([]byte("z"), []byte{26}) //nolint:errcheck
17+
_ = mdb.Set([]byte("a"), []byte{1})
18+
_ = mdb.Set([]byte("b"), []byte{2})
19+
_ = mdb.Set([]byte("t"), []byte{20})
20+
_ = mdb.Set([]byte("test"), []byte{0})
21+
_ = mdb.Set([]byte("u"), []byte{21})
22+
_ = mdb.Set([]byte("z"), []byte{26})
2423
return NewPrefixDB(mdb, []byte("test/")), nil
2524
}, false)
2625
}
@@ -33,6 +32,8 @@ func cleanupDBDir(dir, name string) {
3332
}
3433

3534
func testBackendGetSetDelete(t *testing.T, backend BackendType) {
35+
t.Helper()
36+
3637
// Default
3738
dirname, err := os.MkdirTemp("", fmt.Sprintf("test_backend_%s_", backend))
3839
require.Nil(t, err)
@@ -149,7 +150,7 @@ func TestGoLevelDBBackend(t *testing.T) {
149150
defer cleanupDBDir("", name)
150151

151152
_, ok := db.(*GoLevelDB)
152-
assert.True(t, ok)
153+
require.True(t, ok)
153154
}
154155

155156
func TestDBIterator(t *testing.T) {
@@ -161,6 +162,8 @@ func TestDBIterator(t *testing.T) {
161162
}
162163

163164
func testDBIterator(t *testing.T, backend BackendType) {
165+
t.Helper()
166+
164167
name := fmt.Sprintf("test_%x", randStr(12))
165168
dir := os.TempDir()
166169
db, err := NewDB(name, backend, dir)
@@ -317,13 +320,15 @@ func testDBIterator(t *testing.T, backend BackendType) {
317320
}
318321

319322
func verifyIterator(t *testing.T, itr Iterator, expected []int64, msg string) {
323+
t.Helper()
324+
320325
var list []int64
321326
for itr.Valid() {
322327
key := itr.Key()
323328
list = append(list, bytes2Int64(key))
324329
itr.Next()
325330
}
326-
assert.Equal(t, expected, list, msg)
331+
require.Equal(t, expected, list, msg)
327332
}
328333

329334
func TestDBBatchGetByteSize(t *testing.T) {
@@ -335,6 +340,8 @@ func TestDBBatchGetByteSize(t *testing.T) {
335340
}
336341

337342
func testDBBatchGetByteSize(t *testing.T, backend BackendType) {
343+
t.Helper()
344+
338345
name := fmt.Sprintf("test_%x", randStr(12))
339346
dir := os.TempDir()
340347
db, err := NewDB(name, backend, dir)
@@ -346,15 +353,15 @@ func testDBBatchGetByteSize(t *testing.T, backend BackendType) {
346353
batchSize, err := batch.GetByteSize()
347354
require.NoError(t, err)
348355
// size of newly created batch should be 0 or negligible because of the metadata in the batch,
349-
// for example peppble's batchHeaderLen is 12 so
350-
// peppble's batch size will always be equal or greater than 12 even for empty batch
356+
// for example, pebble's batchHeaderLen is 12, so
357+
// pebble's batch size will always be equal or greater than 12 even for empty batches
351358
require.LessOrEqual(t, batchSize, 32)
352359

353360
totalSizeOfKeyAndValue := 0
354361
// set 100 random keys and values
355362
for i := 0; i < 100; i++ {
356-
keySize := rand.Intn(32) + 1 //nolint:gosec
357-
valueSize := rand.Intn(32) + 1 //nolint:gosec
363+
keySize := rand.Intn(32) + 1
364+
valueSize := rand.Intn(32) + 1
358365
totalSizeOfKeyAndValue += keySize + valueSize
359366
require.NoError(t, batch.Set([]byte(randStr(keySize)), []byte(randStr(valueSize))))
360367
}
@@ -382,6 +389,8 @@ func TestDBBatchOperations(t *testing.T) {
382389
}
383390

384391
func testDBBatchOperations(t *testing.T, backend BackendType) {
392+
t.Helper()
393+
385394
name := fmt.Sprintf("test_%x", randStr(12))
386395
dir := os.TempDir()
387396
db, err := NewDB(name, backend, dir)
@@ -441,10 +450,10 @@ func testDBBatchOperations(t *testing.T, backend BackendType) {
441450
require.NoError(t, err)
442451
assertKeyValues(t, db, map[string][]byte{"a": {1}, "b": {2}})
443452

444-
// it should be possible to close an empty batch, and to re-close a closed batch
453+
// it should be possible to close an empty batch and to re-close a closed batch
445454
batch = db.NewBatch()
446-
batch.Close()
447-
batch.Close()
455+
require.NoError(t, batch.Close())
456+
require.NoError(t, batch.Close())
448457

449458
// all other operations on a closed batch should error
450459
require.Error(t, batch.Set([]byte("a"), []byte{9}))
@@ -454,6 +463,8 @@ func testDBBatchOperations(t *testing.T, backend BackendType) {
454463
}
455464

456465
func assertKeyValues(t *testing.T, db DB, expect map[string][]byte) {
466+
t.Helper()
467+
457468
iter, err := db.Iterator(nil, nil)
458469
require.NoError(t, err)
459470
defer iter.Close()
@@ -464,5 +475,5 @@ func assertKeyValues(t *testing.T, db DB, expect map[string][]byte) {
464475
actual[string(iter.Key())] = iter.Value()
465476
}
466477

467-
assert.Equal(t, expect, actual)
478+
require.Equal(t, expect, actual)
468479
}

0 commit comments

Comments
 (0)