Skip to content

Commit a921cc6

Browse files
committed
[release-1.4] chore(CI): add golangci linter rules
Signed-off-by: Mustafa Elbehery <[email protected]>
1 parent 33c790e commit a921cc6

File tree

10 files changed

+57
-24
lines changed

10 files changed

+57
-24
lines changed

.github/workflows/tests-template.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ jobs:
5252
;;
5353
esac
5454
- name: golangci-lint
55-
uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0
55+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
5656
with:
57-
version: v1.64.8
57+
version: v2.4.0

.github/workflows/tests_windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ jobs:
4040
esac
4141
shell: bash
4242
- name: golangci-lint
43-
uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0
43+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
4444
with:
45-
version: v1.64.8
45+
version: v2.4.0
4646

4747
coverage:
4848
needs: ["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"

cmd/bbolt/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,11 +1768,11 @@ Additional options include:
17681768

17691769
type cmdKvStringer struct{}
17701770

1771-
func (_ cmdKvStringer) KeyToString(key []byte) string {
1771+
func (cmdKvStringer) KeyToString(key []byte) string {
17721772
return bytesToAsciiOrHex(key)
17731773
}
17741774

1775-
func (_ cmdKvStringer) ValueToString(value []byte) string {
1775+
func (cmdKvStringer) ValueToString(value []byte) string {
17761776
return bytesToAsciiOrHex(value)
17771777
}
17781778

@@ -1781,7 +1781,7 @@ func CmdKvStringer() bolt.KVStringer {
17811781
}
17821782

17831783
func findLastBucket(tx *bolt.Tx, bucketNames []string) (*bolt.Bucket, error) {
1784-
var lastbucket *bolt.Bucket = tx.Bucket([]byte(bucketNames[0]))
1784+
lastbucket := tx.Bucket([]byte(bucketNames[0]))
17851785
if lastbucket == nil {
17861786
return nil, berrors.ErrBucketNotFound
17871787
}

cmd/bbolt/main_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ import (
1414
"sync"
1515
"testing"
1616

17-
"go.etcd.io/bbolt/internal/btesting"
18-
"go.etcd.io/bbolt/internal/guts_cli"
19-
2017
"github.com/stretchr/testify/assert"
2118
"github.com/stretchr/testify/require"
2219

2320
bolt "go.etcd.io/bbolt"
2421
main "go.etcd.io/bbolt/cmd/bbolt"
22+
"go.etcd.io/bbolt/internal/btesting"
23+
"go.etcd.io/bbolt/internal/guts_cli"
2524
)
2625

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

internal/common/page.go

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

337337
// Merge returns the sorted union of a and b.
338-
func (a Pgids) Merge(b Pgids) Pgids {
338+
func (s Pgids) Merge(b Pgids) Pgids {
339339
// Return the opposite slice if one is nil.
340-
if len(a) == 0 {
340+
if len(s) == 0 {
341341
return b
342342
}
343343
if len(b) == 0 {
344-
return a
344+
return s
345345
}
346-
merged := make(Pgids, len(a)+len(b))
347-
Mergepgids(merged, a, b)
346+
merged := make(Pgids, len(s)+len(b))
347+
Mergepgids(merged, s, b)
348348
return merged
349349
}
350350

movebucket_test.go

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

10+
"github.com/stretchr/testify/require"
11+
1012
"go.etcd.io/bbolt"
1113
"go.etcd.io/bbolt/errors"
1214
"go.etcd.io/bbolt/internal/btesting"
13-
14-
"github.com/stretchr/testify/require"
1515
)
1616

1717
func TestTx_MoveBucket(t *testing.T) {

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
@@ -281,10 +281,10 @@ func HexKVStringer() KVStringer {
281281

282282
type hexKvStringer struct{}
283283

284-
func (_ hexKvStringer) KeyToString(key []byte) string {
284+
func (hexKvStringer) KeyToString(key []byte) string {
285285
return hex.EncodeToString(key)
286286
}
287287

288-
func (_ hexKvStringer) ValueToString(value []byte) string {
288+
func (hexKvStringer) ValueToString(value []byte) string {
289289
return hex.EncodeToString(value)
290290
}

0 commit comments

Comments
 (0)