Skip to content

Commit c2c7216

Browse files
committed
[release-1.3] chore(CI): add golangci linter rules
Signed-off-by: Mustafa Elbehery <[email protected]>
1 parent 6f6e1c5 commit c2c7216

File tree

10 files changed

+61
-28
lines changed

10 files changed

+61
-28
lines changed

.github/workflows/tests.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ jobs:
4747
;;
4848
esac
4949
- name: golangci-lint
50-
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
50+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
5151
with:
52-
version: v1.64.8
52+
version: v2.1.6
5353

5454
test-windows:
5555
strategy:
@@ -88,9 +88,9 @@ jobs:
8888
esac
8989
shell: bash
9090
- name: golangci-lint
91-
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
91+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
9292
with:
93-
version: v1.64.8
93+
version: v2.1.6
9494

9595
coverage:
9696
needs: ["test-linux", "test-windows"]

.golangci.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
formatters:
2+
enable:
3+
- gofmt
4+
- goimports
5+
settings: # please keep this alphabetized
6+
goimports:
7+
local-prefixes:
8+
- go.etcd.io # Put imports beginning with prefix after 3rd-party packages.
9+
issues:
10+
max-same-issues: 0
11+
linters:
12+
default: none
13+
enable: # please keep this alphabetized
14+
- errcheck
15+
- govet
16+
- ineffassign
17+
- staticcheck
18+
- unused
19+
exclusions:
20+
presets:
21+
- comments
22+
- common-false-positives
23+
- legacy
24+
- std-error-handling
25+
settings: # please keep this alphabetized
26+
staticcheck:
27+
checks:
28+
- all
29+
- -QF1003 # Convert if/else-if chain to tagged switch
30+
- -QF1010 # Convert slice of bytes to string when printing it
31+
- -ST1003 # Poorly chosen identifier
32+
- -ST1005 # Incorrectly formatted error string
33+
- -ST1012 # Poorly chosen name for error variable
34+
version: "2"

bucket.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ func (b *Bucket) Delete(key []byte) error {
343343
}
344344

345345
// Sequence returns the current integer for the bucket without incrementing it.
346-
func (b *Bucket) Sequence() uint64 { return b.bucket.sequence }
346+
func (b *Bucket) Sequence() uint64 { return b.sequence }
347347

348348
// SetSequence updates the sequence number for the bucket.
349349
func (b *Bucket) SetSequence(v uint64) error {
@@ -360,7 +360,7 @@ func (b *Bucket) SetSequence(v uint64) error {
360360
}
361361

362362
// Set the sequence.
363-
b.bucket.sequence = v
363+
b.sequence = v
364364
return nil
365365
}
366366

@@ -379,8 +379,8 @@ func (b *Bucket) NextSequence() (uint64, error) {
379379
}
380380

381381
// Increment and return the sequence.
382-
b.bucket.sequence++
383-
return b.bucket.sequence, nil
382+
b.sequence++
383+
return b.sequence, nil
384384
}
385385

386386
// ForEach executes a function for each key/value pair in a bucket.

cmd/bbolt/main.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ import (
2121
"unicode/utf8"
2222
"unsafe"
2323

24-
"go.etcd.io/bbolt/internal/guts_cli"
25-
2624
bolt "go.etcd.io/bbolt"
25+
"go.etcd.io/bbolt/internal/guts_cli"
2726
)
2827

2928
var (
@@ -934,7 +933,7 @@ func (cmd *keysCommand) Run(args ...string) error {
934933
// Print keys.
935934
return db.View(func(tx *bolt.Tx) error {
936935
// Find bucket.
937-
var lastbucket *bolt.Bucket = tx.Bucket([]byte(buckets[0]))
936+
lastbucket := tx.Bucket([]byte(buckets[0]))
938937
if lastbucket == nil {
939938
return ErrBucketNotFound
940939
}
@@ -1028,7 +1027,7 @@ func (cmd *getCommand) Run(args ...string) error {
10281027
// Print value.
10291028
return db.View(func(tx *bolt.Tx) error {
10301029
// Find bucket.
1031-
var lastbucket *bolt.Bucket = tx.Bucket([]byte(buckets[0]))
1030+
lastbucket := tx.Bucket([]byte(buckets[0]))
10321031
if lastbucket == nil {
10331032
return ErrBucketNotFound
10341033
}
@@ -1692,11 +1691,11 @@ Additional options include:
16921691

16931692
type cmdKvStringer struct{}
16941693

1695-
func (_ cmdKvStringer) KeyToString(key []byte) string {
1694+
func (cmdKvStringer) KeyToString(key []byte) string {
16961695
return bytesToAsciiOrHex(key)
16971696
}
16981697

1699-
func (_ cmdKvStringer) ValueToString(value []byte) string {
1698+
func (cmdKvStringer) ValueToString(value []byte) string {
17001699
return bytesToAsciiOrHex(value)
17011700
}
17021701

cmd/bbolt/main_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ import (
1010
"strconv"
1111
"testing"
1212

13-
"go.etcd.io/bbolt/internal/btesting"
14-
1513
"github.com/stretchr/testify/require"
1614

1715
bolt "go.etcd.io/bbolt"
1816
main "go.etcd.io/bbolt/cmd/bbolt"
17+
"go.etcd.io/bbolt/internal/btesting"
1918
)
2019

2120
// Ensure the "info" command can print information about a database.

internal/surgeon/surgeon.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package surgeon
22

33
import (
44
"fmt"
5+
56
"go.etcd.io/bbolt/internal/guts_cli"
67
)
78

page.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ func (s pgids) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
156156
func (s pgids) Less(i, j int) bool { return s[i] < s[j] }
157157

158158
// merge returns the sorted union of a and b.
159-
func (a pgids) merge(b pgids) pgids {
159+
func (s pgids) merge(b pgids) pgids {
160160
// Return the opposite slice if one is nil.
161-
if len(a) == 0 {
161+
if len(s) == 0 {
162162
return b
163163
}
164164
if len(b) == 0 {
165-
return a
165+
return s
166166
}
167-
merged := make(pgids, len(a)+len(b))
168-
mergepgids(merged, a, b)
167+
merged := make(pgids, len(s)+len(b))
168+
mergepgids(merged, s, b)
169169
return merged
170170
}
171171

tests/dmflakey/dmflakey_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import (
1212
"testing"
1313
"time"
1414

15-
testutils "go.etcd.io/bbolt/tests/utils"
16-
1715
"github.com/stretchr/testify/assert"
1816
"github.com/stretchr/testify/require"
1917
"golang.org/x/sys/unix"
18+
19+
testutils "go.etcd.io/bbolt/tests/utils"
2020
)
2121

2222
func TestMain(m *testing.M) {

tests/robustness/powerfailure_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import (
1919
"testing"
2020
"time"
2121

22-
"go.etcd.io/bbolt/tests/dmflakey"
23-
2422
"github.com/stretchr/testify/assert"
2523
"github.com/stretchr/testify/require"
2624
"golang.org/x/sys/unix"
25+
26+
"go.etcd.io/bbolt/tests/dmflakey"
2727
)
2828

2929
var panicFailpoints = []string{
@@ -140,7 +140,7 @@ func TestRestartFromPowerFailureXFS(t *testing.T) {
140140
}
141141

142142
func doPowerFailure(t *testing.T, du time.Duration, fsType dmflakey.FSType, mkfsOpt string, fsMountOpt string, useFailpoint bool) {
143-
flakey := initFlakeyDevice(t, strings.Replace(t.Name(), "/", "_", -1), fsType, mkfsOpt, fsMountOpt)
143+
flakey := initFlakeyDevice(t, strings.ReplaceAll(t.Name(), "/", "_"), fsType, mkfsOpt, fsMountOpt)
144144
root := flakey.RootFS()
145145

146146
dbPath := filepath.Join(root, "boltdb")

tx_check.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ func HexKVStringer() KVStringer {
217217

218218
type hexKvStringer struct{}
219219

220-
func (_ hexKvStringer) KeyToString(key []byte) string {
220+
func (hexKvStringer) KeyToString(key []byte) string {
221221
return hex.EncodeToString(key)
222222
}
223223

224-
func (_ hexKvStringer) ValueToString(value []byte) string {
224+
func (hexKvStringer) ValueToString(value []byte) string {
225225
return hex.EncodeToString(value)
226226
}

0 commit comments

Comments
 (0)