Skip to content

Commit 99d73b7

Browse files
authored
Upgrade golangci-lint (#928)
1 parent ed6d53e commit 99d73b7

File tree

10 files changed

+41
-22
lines changed

10 files changed

+41
-22
lines changed

.github/workflows/lint.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
with:
2222
go-version: "stable"
2323
- name: golangci-lint
24-
uses: golangci/golangci-lint-action@v6
24+
uses: golangci/golangci-lint-action@v7
2525
with:
2626
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
2727
version: latest

.golangci.yaml

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1+
version: "2"
12
linters:
2-
disable-all: true
3+
default: none
34
enable:
4-
# Default
55
- errcheck
6-
- gosimple
76
- govet
87
- ineffassign
8+
- misspell
99
- staticcheck
10+
- testifylint
1011
- unused
12+
exclusions:
13+
generated: lax
14+
presets:
15+
- comments
16+
- common-false-positives
17+
- legacy
18+
- std-error-handling
19+
paths:
20+
- third_party$
21+
- builtin$
22+
- examples$
23+
formatters:
24+
enable:
1125
- gofmt
12-
# Added
13-
- testifylint
14-
- misspell
26+
exclusions:
27+
generated: lax
28+
paths:
29+
- third_party$
30+
- builtin$
31+
- examples$

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ lint: tools
3737

3838
.PHONY: tools
3939
tools:
40-
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
40+
@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
4141
@go install github.com/mfridman/tparse@main
4242

4343
test-packages:

examples/go-migrations/main.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ var (
1818
)
1919

2020
func main() {
21-
flags.Parse(os.Args[1:])
21+
if err := flags.Parse(os.Args[1:]); err != nil {
22+
log.Fatalf("goose: failed to parse flags: %v", err)
23+
}
2224
args := flags.Args()
2325

2426
if len(args) < 3 {

globals_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestNewGoMigration(t *testing.T) {
1717
require.True(t, m.Registered)
1818
require.EqualValues(t, -1, m.Next)
1919
require.EqualValues(t, -1, m.Previous)
20-
require.Equal(t, "", m.Source)
20+
require.Empty(t, m.Source)
2121
require.Nil(t, m.UpFnNoTxContext)
2222
require.Nil(t, m.DownFnNoTxContext)
2323
require.Nil(t, m.UpFnContext)
@@ -136,7 +136,7 @@ func TestLegacyFunctions(t *testing.T) {
136136
require.True(t, m.Registered)
137137
require.EqualValues(t, -1, m.Next)
138138
require.EqualValues(t, -1, m.Previous)
139-
require.Equal(t, "", m.Source)
139+
require.Empty(t, m.Source)
140140
}
141141

142142
t.Run("all_tx", func(t *testing.T) {

lock/postgres.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ func NewPostgresSessionLocker(opts ...SessionLockerOption) (SessionLocker, error
2525
cfg := sessionLockerConfig{
2626
lockID: DefaultLockID,
2727
lockProbe: probe{
28-
periodSeconds: 5 * time.Second,
28+
intervalDuration: 5 * time.Second,
2929
failureThreshold: 60,
3030
},
3131
unlockProbe: probe{
32-
periodSeconds: 2 * time.Second,
32+
intervalDuration: 2 * time.Second,
3333
failureThreshold: 30,
3434
},
3535
}
@@ -42,11 +42,11 @@ func NewPostgresSessionLocker(opts ...SessionLockerOption) (SessionLocker, error
4242
lockID: cfg.lockID,
4343
retryLock: retry.WithMaxRetries(
4444
cfg.lockProbe.failureThreshold,
45-
retry.NewConstant(cfg.lockProbe.periodSeconds),
45+
retry.NewConstant(cfg.lockProbe.intervalDuration),
4646
),
4747
retryUnlock: retry.WithMaxRetries(
4848
cfg.unlockProbe.failureThreshold,
49-
retry.NewConstant(cfg.unlockProbe.periodSeconds),
49+
retry.NewConstant(cfg.unlockProbe.intervalDuration),
5050
),
5151
}, nil
5252
}

lock/session_locker_options.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func WithLockTimeout(period, failureThreshold uint64) SessionLockerOption {
4444
return errors.New("failure threshold must be greater than 0, minimum is 1")
4545
}
4646
c.lockProbe = probe{
47-
periodSeconds: time.Duration(period) * time.Second,
47+
intervalDuration: time.Duration(period) * time.Second,
4848
failureThreshold: failureThreshold,
4949
}
5050
return nil
@@ -67,7 +67,7 @@ func WithUnlockTimeout(period, failureThreshold uint64) SessionLockerOption {
6767
return errors.New("failure threshold must be greater than 0, minimum is 1")
6868
}
6969
c.unlockProbe = probe{
70-
periodSeconds: time.Duration(period) * time.Second,
70+
intervalDuration: time.Duration(period) * time.Second,
7171
failureThreshold: failureThreshold,
7272
}
7373
return nil
@@ -84,7 +84,7 @@ type sessionLockerConfig struct {
8484
// total timeout will be the period times the failure threshold.
8585
type probe struct {
8686
// How often (in seconds) to perform the probe.
87-
periodSeconds time.Duration
87+
intervalDuration time.Duration
8888
// Number of times to retry the probe.
8989
failureThreshold uint64
9090
}

provider_collect_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func TestCollectFileSources(t *testing.T) {
160160
require.NoError(t, err)
161161
got, err := collectFilesystemSources(f, false, nil, nil)
162162
require.NoError(t, err)
163-
require.Equal(t, len(got.sqlSources), len(sqlSources))
163+
require.Len(t, sqlSources, len(got.sqlSources))
164164
require.Empty(t, got.goSources)
165165
for i := 0; i < len(got.sqlSources); i++ {
166166
require.Equal(t, got.sqlSources[i], sqlSources[i])

provider_run_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func TestProviderRun(t *testing.T) {
187187
// Apply all up migrations
188188
upResult, err := p.Up(ctx)
189189
require.NoError(t, err)
190-
require.Equal(t, len(upResult), len(sources))
190+
require.Len(t, sources, len(upResult))
191191
currentVersion, err := p.GetDBVersion(ctx)
192192
require.NoError(t, err)
193193
require.Equal(t, currentVersion, p.ListSources()[len(sources)-1].Version)
@@ -207,7 +207,7 @@ func TestProviderRun(t *testing.T) {
207207
// Apply all down migrations
208208
downResult, err := p.DownTo(ctx, 0)
209209
require.NoError(t, err)
210-
require.Equal(t, len(downResult), len(sources))
210+
require.Len(t, sources, len(downResult))
211211
gotVersion, err := getMaxVersionID(db, goose.DefaultTablename)
212212
require.NoError(t, err)
213213
require.EqualValues(t, 0, gotVersion)

tests/gomigrations/error/gomigrations_error_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ func TestGoMigrationByOne(t *testing.T) {
6868
// running within a tx we expect none of the inserts to persist.
6969
err = db.QueryRow("SELECT COUNT(*) FROM foo").Scan(&count)
7070
require.NoError(t, err)
71-
require.EqualValues(t, 0, count)
71+
require.Equal(t, 0, count)
7272

7373
}

0 commit comments

Comments
 (0)