diff --git a/.github/workflows/tests-template.yml b/.github/workflows/tests-template.yml index 78c842fc1..ed33e01dd 100644 --- a/.github/workflows/tests-template.yml +++ b/.github/workflows/tests-template.yml @@ -52,6 +52,6 @@ jobs: ;; esac - name: golangci-lint - uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0 + uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 with: - version: v1.64.8 + version: v2.4.0 diff --git a/.github/workflows/tests_windows.yml b/.github/workflows/tests_windows.yml index 7f811ed2a..6ce68131e 100644 --- a/.github/workflows/tests_windows.yml +++ b/.github/workflows/tests_windows.yml @@ -40,9 +40,9 @@ jobs: esac shell: bash - name: golangci-lint - uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0 + uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 with: - version: v1.64.8 + version: v2.4.0 coverage: needs: ["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/cmd/bbolt/main.go b/cmd/bbolt/main.go index a9256a699..37324369d 100644 --- a/cmd/bbolt/main.go +++ b/cmd/bbolt/main.go @@ -1768,11 +1768,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) } @@ -1781,7 +1781,7 @@ func CmdKvStringer() bolt.KVStringer { } func findLastBucket(tx *bolt.Tx, bucketNames []string) (*bolt.Bucket, error) { - var lastbucket *bolt.Bucket = tx.Bucket([]byte(bucketNames[0])) + lastbucket := tx.Bucket([]byte(bucketNames[0])) if lastbucket == nil { return nil, berrors.ErrBucketNotFound } diff --git a/cmd/bbolt/main_test.go b/cmd/bbolt/main_test.go index 727b38f55..173d6595f 100644 --- a/cmd/bbolt/main_test.go +++ b/cmd/bbolt/main_test.go @@ -14,14 +14,13 @@ import ( "sync" "testing" - "go.etcd.io/bbolt/internal/btesting" - "go.etcd.io/bbolt/internal/guts_cli" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" bolt "go.etcd.io/bbolt" main "go.etcd.io/bbolt/cmd/bbolt" + "go.etcd.io/bbolt/internal/btesting" + "go.etcd.io/bbolt/internal/guts_cli" ) // Ensure the "info" command can print information about a database. diff --git a/internal/common/page.go b/internal/common/page.go index ee808967c..4453160bb 100644 --- a/internal/common/page.go +++ b/internal/common/page.go @@ -335,16 +335,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/movebucket_test.go b/movebucket_test.go index a04e24c9c..9c09825e6 100644 --- a/movebucket_test.go +++ b/movebucket_test.go @@ -7,11 +7,11 @@ import ( "path/filepath" "testing" + "github.com/stretchr/testify/require" + "go.etcd.io/bbolt" "go.etcd.io/bbolt/errors" "go.etcd.io/bbolt/internal/btesting" - - "github.com/stretchr/testify/require" ) func TestTx_MoveBucket(t *testing.T) { 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 c3ecbb975..59edf3573 100644 --- a/tx_check.go +++ b/tx_check.go @@ -281,10 +281,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) }