diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index e5812a8..5d5f94d 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -21,7 +21,7 @@ jobs: with: go-version: "stable" - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version version: latest diff --git a/.golangci.yaml b/.golangci.yaml index 1807836..93913f3 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,14 +1,31 @@ +version: "2" linters: - disable-all: true + default: none enable: - # Default - errcheck - - gosimple - govet - ineffassign - - staticcheck - - unused - - gofmt - # Added - - testifylint - misspell + - staticcheck + - testifylint + - unused + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index e4b2a7c..e57ad99 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ lint: tools .PHONY: tools tools: - @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin + @go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest @go install github.com/mfridman/tparse@main test-packages: diff --git a/examples/go-migrations/main.go b/examples/go-migrations/main.go index 5a41e53..4693b3b 100644 --- a/examples/go-migrations/main.go +++ b/examples/go-migrations/main.go @@ -18,7 +18,9 @@ var ( ) func main() { - flags.Parse(os.Args[1:]) + if err := flags.Parse(os.Args[1:]); err != nil { + log.Fatalf("goose: failed to parse flags: %v", err) + } args := flags.Args() if len(args) < 3 { diff --git a/globals_test.go b/globals_test.go index 230708a..8dd64f2 100644 --- a/globals_test.go +++ b/globals_test.go @@ -17,7 +17,7 @@ func TestNewGoMigration(t *testing.T) { require.True(t, m.Registered) require.EqualValues(t, -1, m.Next) require.EqualValues(t, -1, m.Previous) - require.Equal(t, "", m.Source) + require.Empty(t, m.Source) require.Nil(t, m.UpFnNoTxContext) require.Nil(t, m.DownFnNoTxContext) require.Nil(t, m.UpFnContext) @@ -136,7 +136,7 @@ func TestLegacyFunctions(t *testing.T) { require.True(t, m.Registered) require.EqualValues(t, -1, m.Next) require.EqualValues(t, -1, m.Previous) - require.Equal(t, "", m.Source) + require.Empty(t, m.Source) } t.Run("all_tx", func(t *testing.T) { diff --git a/lock/postgres.go b/lock/postgres.go index 97b7bae..adfa3fe 100644 --- a/lock/postgres.go +++ b/lock/postgres.go @@ -25,11 +25,11 @@ func NewPostgresSessionLocker(opts ...SessionLockerOption) (SessionLocker, error cfg := sessionLockerConfig{ lockID: DefaultLockID, lockProbe: probe{ - periodSeconds: 5 * time.Second, + intervalDuration: 5 * time.Second, failureThreshold: 60, }, unlockProbe: probe{ - periodSeconds: 2 * time.Second, + intervalDuration: 2 * time.Second, failureThreshold: 30, }, } @@ -42,11 +42,11 @@ func NewPostgresSessionLocker(opts ...SessionLockerOption) (SessionLocker, error lockID: cfg.lockID, retryLock: retry.WithMaxRetries( cfg.lockProbe.failureThreshold, - retry.NewConstant(cfg.lockProbe.periodSeconds), + retry.NewConstant(cfg.lockProbe.intervalDuration), ), retryUnlock: retry.WithMaxRetries( cfg.unlockProbe.failureThreshold, - retry.NewConstant(cfg.unlockProbe.periodSeconds), + retry.NewConstant(cfg.unlockProbe.intervalDuration), ), }, nil } diff --git a/lock/session_locker_options.go b/lock/session_locker_options.go index 4f1efe8..4954caa 100644 --- a/lock/session_locker_options.go +++ b/lock/session_locker_options.go @@ -44,7 +44,7 @@ func WithLockTimeout(period, failureThreshold uint64) SessionLockerOption { return errors.New("failure threshold must be greater than 0, minimum is 1") } c.lockProbe = probe{ - periodSeconds: time.Duration(period) * time.Second, + intervalDuration: time.Duration(period) * time.Second, failureThreshold: failureThreshold, } return nil @@ -67,7 +67,7 @@ func WithUnlockTimeout(period, failureThreshold uint64) SessionLockerOption { return errors.New("failure threshold must be greater than 0, minimum is 1") } c.unlockProbe = probe{ - periodSeconds: time.Duration(period) * time.Second, + intervalDuration: time.Duration(period) * time.Second, failureThreshold: failureThreshold, } return nil @@ -84,7 +84,7 @@ type sessionLockerConfig struct { // total timeout will be the period times the failure threshold. type probe struct { // How often (in seconds) to perform the probe. - periodSeconds time.Duration + intervalDuration time.Duration // Number of times to retry the probe. failureThreshold uint64 } diff --git a/provider_collect_test.go b/provider_collect_test.go index 46dcbd4..5d45a99 100644 --- a/provider_collect_test.go +++ b/provider_collect_test.go @@ -160,7 +160,7 @@ func TestCollectFileSources(t *testing.T) { require.NoError(t, err) got, err := collectFilesystemSources(f, false, nil, nil) require.NoError(t, err) - require.Equal(t, len(got.sqlSources), len(sqlSources)) + require.Len(t, sqlSources, len(got.sqlSources)) require.Empty(t, got.goSources) for i := 0; i < len(got.sqlSources); i++ { require.Equal(t, got.sqlSources[i], sqlSources[i]) diff --git a/provider_run_test.go b/provider_run_test.go index aedfa7f..017c4e9 100644 --- a/provider_run_test.go +++ b/provider_run_test.go @@ -187,7 +187,7 @@ func TestProviderRun(t *testing.T) { // Apply all up migrations upResult, err := p.Up(ctx) require.NoError(t, err) - require.Equal(t, len(upResult), len(sources)) + require.Len(t, sources, len(upResult)) currentVersion, err := p.GetDBVersion(ctx) require.NoError(t, err) require.Equal(t, currentVersion, p.ListSources()[len(sources)-1].Version) @@ -207,7 +207,7 @@ func TestProviderRun(t *testing.T) { // Apply all down migrations downResult, err := p.DownTo(ctx, 0) require.NoError(t, err) - require.Equal(t, len(downResult), len(sources)) + require.Len(t, sources, len(downResult)) gotVersion, err := getMaxVersionID(db, goose.DefaultTablename) require.NoError(t, err) require.EqualValues(t, 0, gotVersion) diff --git a/tests/gomigrations/error/gomigrations_error_test.go b/tests/gomigrations/error/gomigrations_error_test.go index 7cfaeff..cee5441 100644 --- a/tests/gomigrations/error/gomigrations_error_test.go +++ b/tests/gomigrations/error/gomigrations_error_test.go @@ -68,6 +68,6 @@ func TestGoMigrationByOne(t *testing.T) { // running within a tx we expect none of the inserts to persist. err = db.QueryRow("SELECT COUNT(*) FROM foo").Scan(&count) require.NoError(t, err) - require.EqualValues(t, 0, count) + require.Equal(t, 0, count) }