diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 1fa5aa192..f42072ae3 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -47,9 +47,9 @@ jobs: ;; esac - name: golangci-lint - uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0 + uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 with: - version: v1.64.8 + version: v2.1.6 test-windows: strategy: @@ -88,9 +88,9 @@ jobs: esac shell: bash - name: golangci-lint - uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0 + uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 with: - version: v1.64.8 + version: v2.1.6 coverage: needs: ["test-linux", "test-windows"] diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 000000000..68fc13184 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,34 @@ +formatters: + enable: + - gofmt + - goimports + settings: # please keep this alphabetized + goimports: + local-prefixes: + - go.etcd.io # Put imports beginning with prefix after 3rd-party packages. +issues: + max-same-issues: 0 +linters: + default: none + enable: # please keep this alphabetized + - errcheck + - govet + - ineffassign + - staticcheck + - unused + exclusions: + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + settings: # please keep this alphabetized + staticcheck: + checks: + - all + - -QF1003 # Convert if/else-if chain to tagged switch + - -QF1010 # Convert slice of bytes to string when printing it + - -ST1003 # Poorly chosen identifier + - -ST1005 # Incorrectly formatted error string + - -ST1012 # Poorly chosen name for error variable +version: "2" diff --git a/bucket.go b/bucket.go index f3533d344..38fb8ad04 100644 --- a/bucket.go +++ b/bucket.go @@ -343,7 +343,7 @@ func (b *Bucket) Delete(key []byte) error { } // Sequence returns the current integer for the bucket without incrementing it. -func (b *Bucket) Sequence() uint64 { return b.bucket.sequence } +func (b *Bucket) Sequence() uint64 { return b.sequence } // SetSequence updates the sequence number for the bucket. func (b *Bucket) SetSequence(v uint64) error { @@ -360,7 +360,7 @@ func (b *Bucket) SetSequence(v uint64) error { } // Set the sequence. - b.bucket.sequence = v + b.sequence = v return nil } @@ -379,8 +379,8 @@ func (b *Bucket) NextSequence() (uint64, error) { } // Increment and return the sequence. - b.bucket.sequence++ - return b.bucket.sequence, nil + b.sequence++ + return b.sequence, nil } // ForEach executes a function for each key/value pair in a bucket. diff --git a/cmd/bbolt/main.go b/cmd/bbolt/main.go index 12ce35a53..4a3d1f258 100644 --- a/cmd/bbolt/main.go +++ b/cmd/bbolt/main.go @@ -21,9 +21,8 @@ import ( "unicode/utf8" "unsafe" - "go.etcd.io/bbolt/internal/guts_cli" - bolt "go.etcd.io/bbolt" + "go.etcd.io/bbolt/internal/guts_cli" ) var ( @@ -934,7 +933,7 @@ func (cmd *keysCommand) Run(args ...string) error { // Print keys. return db.View(func(tx *bolt.Tx) error { // Find bucket. - var lastbucket *bolt.Bucket = tx.Bucket([]byte(buckets[0])) + lastbucket := tx.Bucket([]byte(buckets[0])) if lastbucket == nil { return ErrBucketNotFound } @@ -1028,7 +1027,7 @@ func (cmd *getCommand) Run(args ...string) error { // Print value. return db.View(func(tx *bolt.Tx) error { // Find bucket. - var lastbucket *bolt.Bucket = tx.Bucket([]byte(buckets[0])) + lastbucket := tx.Bucket([]byte(buckets[0])) if lastbucket == nil { return ErrBucketNotFound } @@ -1692,11 +1691,11 @@ Additional options include: type cmdKvStringer struct{} -func (_ cmdKvStringer) KeyToString(key []byte) string { +func (cmdKvStringer) KeyToString(key []byte) string { return bytesToAsciiOrHex(key) } -func (_ cmdKvStringer) ValueToString(value []byte) string { +func (cmdKvStringer) ValueToString(value []byte) string { return bytesToAsciiOrHex(value) } diff --git a/cmd/bbolt/main_test.go b/cmd/bbolt/main_test.go index dac574104..48945bd9b 100644 --- a/cmd/bbolt/main_test.go +++ b/cmd/bbolt/main_test.go @@ -10,12 +10,11 @@ import ( "strconv" "testing" - "go.etcd.io/bbolt/internal/btesting" - "github.com/stretchr/testify/require" bolt "go.etcd.io/bbolt" main "go.etcd.io/bbolt/cmd/bbolt" + "go.etcd.io/bbolt/internal/btesting" ) // Ensure the "info" command can print information about a database. diff --git a/internal/surgeon/surgeon.go b/internal/surgeon/surgeon.go index 763583705..644e16b51 100644 --- a/internal/surgeon/surgeon.go +++ b/internal/surgeon/surgeon.go @@ -2,6 +2,7 @@ package surgeon import ( "fmt" + "go.etcd.io/bbolt/internal/guts_cli" ) diff --git a/page.go b/page.go index bb081b031..05bfeed1e 100644 --- a/page.go +++ b/page.go @@ -156,16 +156,16 @@ func (s pgids) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s pgids) Less(i, j int) bool { return s[i] < s[j] } // merge returns the sorted union of a and b. -func (a pgids) merge(b pgids) pgids { +func (s pgids) merge(b pgids) pgids { // Return the opposite slice if one is nil. - if len(a) == 0 { + if len(s) == 0 { return b } if len(b) == 0 { - return a + return s } - merged := make(pgids, len(a)+len(b)) - mergepgids(merged, a, b) + merged := make(pgids, len(s)+len(b)) + mergepgids(merged, s, b) return merged } diff --git a/tests/dmflakey/dmflakey_test.go b/tests/dmflakey/dmflakey_test.go index 99e2de062..9e4229534 100644 --- a/tests/dmflakey/dmflakey_test.go +++ b/tests/dmflakey/dmflakey_test.go @@ -12,11 +12,11 @@ import ( "testing" "time" - testutils "go.etcd.io/bbolt/tests/utils" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/sys/unix" + + testutils "go.etcd.io/bbolt/tests/utils" ) func TestMain(m *testing.M) { diff --git a/tests/robustness/powerfailure_test.go b/tests/robustness/powerfailure_test.go index d8c497e0a..54c611cbf 100644 --- a/tests/robustness/powerfailure_test.go +++ b/tests/robustness/powerfailure_test.go @@ -19,11 +19,11 @@ import ( "testing" "time" - "go.etcd.io/bbolt/tests/dmflakey" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/sys/unix" + + "go.etcd.io/bbolt/tests/dmflakey" ) var panicFailpoints = []string{ @@ -140,7 +140,7 @@ func TestRestartFromPowerFailureXFS(t *testing.T) { } func doPowerFailure(t *testing.T, du time.Duration, fsType dmflakey.FSType, mkfsOpt string, fsMountOpt string, useFailpoint bool) { - flakey := initFlakeyDevice(t, strings.Replace(t.Name(), "/", "_", -1), fsType, mkfsOpt, fsMountOpt) + flakey := initFlakeyDevice(t, strings.ReplaceAll(t.Name(), "/", "_"), fsType, mkfsOpt, fsMountOpt) root := flakey.RootFS() dbPath := filepath.Join(root, "boltdb") diff --git a/tx_check.go b/tx_check.go index 75c7c0843..e46f9d1ff 100644 --- a/tx_check.go +++ b/tx_check.go @@ -217,10 +217,10 @@ func HexKVStringer() KVStringer { type hexKvStringer struct{} -func (_ hexKvStringer) KeyToString(key []byte) string { +func (hexKvStringer) KeyToString(key []byte) string { return hex.EncodeToString(key) } -func (_ hexKvStringer) ValueToString(value []byte) string { +func (hexKvStringer) ValueToString(value []byte) string { return hex.EncodeToString(value) }