Skip to content

Commit 2edf911

Browse files
authored
Upgrade to golangci-lint v2.2.1 + disable some annoying lints + fix others (#989)
Here, upgrade golangci-lint to v2.2.1, mostly because my local version is upgraded and throwing problems. Some really, really, really-no-good lints have been added (`noinlineerr` and `wsl_v5`) which we disable. Some others have been added which are good, which we keep. One checks that there's a consistent whitespace between embedded structs and other properties on a struct definition. Another makes sure we're using the context form of logging functions, so `WarnContext` instead of `Warn`.
1 parent e771d8d commit 2edf911

29 files changed

Lines changed: 81 additions & 36 deletions

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ jobs:
243243
name: lint
244244
runs-on: ubuntu-latest
245245
env:
246-
GOLANGCI_LINT_VERSION: v2.1.6
246+
GOLANGCI_LINT_VERSION: v2.2.1
247247
permissions:
248248
contents: read
249249
# allow read access to pull request. Use with `only-new-issues` option.

.golangci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ linters:
2323
- maintidx # ANOTHER ANOTHER "cyclomatic complexity" lint (see also "cyclop" and "gocyclo")
2424
- mnd # detects "magic numbers", which it defines as any number; annoying
2525
- nestif # yells when if blocks are nested; what planet do these people come from?
26+
- noinlineerr # disallows `if err := ...`; because why miss an opportunity to leak variables out of scope?
2627
- ireturn # bans returning interfaces; questionable as is, but also buggy as hell; very, very annoying
2728
- lll # restricts maximum line length; annoying
2829
- nlreturn # requires a blank line before returns; annoying
2930
- wsl # a bunch of style/whitespace stuff; annoying
31+
- wsl_v5 # a second version of the first annoying wsl; how nice
3032

3133
settings:
3234
depguard:

client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,10 @@ func (c *Config) validate() error {
471471
// this convention.
472472
maxSchemaLength := 63 - 1 - len(string(notifier.NotificationTopicLongest)) // -1 for the dot in `<schema>.<topic>`
473473
if len(c.Schema) > maxSchemaLength {
474-
return fmt.Errorf("Schema length must be less than or equal to %d characters", maxSchemaLength) //nolint:staticcheck
474+
return fmt.Errorf("Schema length must be less than or equal to %d characters", maxSchemaLength)
475475
}
476476
if c.Schema != "" && !postgresSchemaNameRE.MatchString(c.Schema) {
477-
return errors.New("Schema name can only contain letters, numbers, and underscores, and must start with a letter or underscore") //nolint:staticcheck
477+
return errors.New("Schema name can only contain letters, numbers, and underscores, and must start with a letter or underscore")
478478
}
479479

480480
for queue, queueConfig := range c.Queues {
@@ -492,7 +492,7 @@ func (c *Config) validate() error {
492492
kind := workerInfo.jobArgs.Kind()
493493
if !rivercommon.UserSpecifiedIDOrKindRE.MatchString(kind) {
494494
if c.SkipJobKindValidation {
495-
c.Logger.Warn("job kind should match regex; this will be an error in future versions",
495+
c.Logger.Warn("job kind should match regex; this will be an error in future versions", //nolint:noctx
496496
slog.String("kind", kind),
497497
slog.String("regex", rivercommon.UserSpecifiedIDOrKindRE.String()),
498498
)
@@ -763,7 +763,7 @@ func NewClient[TTx any](driver riverdriver.Driver[TTx], config *Config) (*Client
763763
client.services = append(client.services, client.notifier)
764764
}
765765
} else {
766-
config.Logger.Info("Driver does not support listener; entering poll only mode")
766+
config.Logger.Info("Driver does not support listener; entering poll only mode") //nolint:noctx
767767
}
768768

769769
client.elector = leadership.NewElector(archetype, driver.GetExecutor(), client.notifier, &leadership.Config{

client_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ func Test_Client_Common(t *testing.T) {
10271027

10281028
type JobArgs struct {
10291029
testutil.JobArgsReflectKind[JobArgs]
1030+
10301031
Name string `json:"name"`
10311032
}
10321033

@@ -1452,6 +1453,7 @@ var (
14521453

14531454
type workerWithMiddleware[T JobArgs] struct {
14541455
WorkerDefaults[T]
1456+
14551457
workFunc func(context.Context, *Job[T]) error
14561458
middlewareFunc func(*rivertype.JobRow) []rivertype.WorkerMiddleware
14571459
}
@@ -1890,6 +1892,7 @@ func (callbackWithCustomTimeoutArgs) Kind() string { return "callbackWithCustomT
18901892

18911893
type callbackWorkerWithCustomTimeout struct {
18921894
WorkerDefaults[callbackWithCustomTimeoutArgs]
1895+
18931896
fn func(context.Context, *Job[callbackWithCustomTimeoutArgs]) error
18941897
}
18951898

@@ -5674,6 +5677,7 @@ func Test_Client_Subscribe(t *testing.T) {
56745677

56755678
type JobArgs struct {
56765679
testutil.JobArgsReflectKind[JobArgs]
5680+
56775681
Name string `json:"name"`
56785682
}
56795683

@@ -5948,6 +5952,7 @@ func Test_Client_SubscribeConfig(t *testing.T) {
59485952

59495953
type JobArgs struct {
59505954
testutil.JobArgsReflectKind[JobArgs]
5955+
59515956
Name string `json:"name"`
59525957
}
59535958

@@ -6251,7 +6256,7 @@ func Test_Client_InsertNotificationsAreDeduplicatedAndDebounced(t *testing.T) {
62516256
}
62526257
notifyCh := make(chan notification, 10)
62536258
handleNotification := func(topic notifier.NotificationTopic, payload string) {
6254-
config.Logger.Info("received notification", slog.String("topic", string(topic)), slog.String("payload", payload))
6259+
config.Logger.InfoContext(ctx, "received notification", slog.String("topic", string(topic)), slog.String("payload", payload))
62556260
notif := notification{topic: topic}
62566261
require.NoError(t, json.Unmarshal([]byte(payload), &notif.payload))
62576262
notifyCh <- notif
@@ -6262,7 +6267,7 @@ func Test_Client_InsertNotificationsAreDeduplicatedAndDebounced(t *testing.T) {
62626267

62636268
expectImmediateNotification := func(t *testing.T, queue string) {
62646269
t.Helper()
6265-
config.Logger.Info("inserting " + queue + " job")
6270+
config.Logger.InfoContext(ctx, "inserting "+queue+" job")
62666271
_, err = client.Insert(ctx, JobArgs{}, &InsertOpts{Queue: queue})
62676272
require.NoError(t, err)
62686273
notif := riversharedtest.WaitOrTimeout(t, notifyCh)
@@ -6275,7 +6280,7 @@ func Test_Client_InsertNotificationsAreDeduplicatedAndDebounced(t *testing.T) {
62756280
tNotif1 := time.Now()
62766281

62776282
for range 5 {
6278-
config.Logger.Info("inserting queue1 job")
6283+
config.Logger.InfoContext(ctx, "inserting queue1 job")
62796284
_, err = client.Insert(ctx, JobArgs{}, &InsertOpts{Queue: "queue1"})
62806285
require.NoError(t, err)
62816286
}
@@ -7280,6 +7285,7 @@ type testWorkerDeadline struct {
72807285

72817286
type timeoutTestWorker struct {
72827287
WorkerDefaults[timeoutTestArgs]
7288+
72837289
doneCh chan testWorkerDeadline
72847290
}
72857291

@@ -7548,6 +7554,7 @@ func TestInsertParamsFromJobArgsAndOptions(t *testing.T) {
75487554

75497555
type PartialArgs struct {
75507556
JobArgsStaticKind
7557+
75517558
Included bool `json:"included" river:"unique"`
75527559
Excluded bool `json:"excluded"`
75537560
}

example_complete_job_within_tx_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func (TransactionalArgs) Kind() string { return "transactional_worker" }
2626
// the transaction such as inserting additional jobs or manipulating other data.
2727
type TransactionalWorker struct {
2828
river.WorkerDefaults[TransactionalArgs]
29+
2930
dbPool *pgxpool.Pool
3031
}
3132

example_graceful_shutdown_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func (WaitsForCancelOnlyArgs) Kind() string { return "waits_for_cancel_only" }
2828
// context is cancelled.
2929
type WaitsForCancelOnlyWorker struct {
3030
river.WorkerDefaults[WaitsForCancelOnlyArgs]
31+
3132
jobStarted chan struct{}
3233
}
3334

example_job_cancel_from_client_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func (args SleepingArgs) Kind() string { return "SleepingWorker" }
2222

2323
type SleepingWorker struct {
2424
river.WorkerDefaults[CancellingArgs]
25+
2526
jobChan chan int64
2627
}
2728

example_queue_pause_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func (args ReportingArgs) Kind() string { return "Reporting" }
2222

2323
type ReportingWorker struct {
2424
river.WorkerDefaults[ReportingArgs]
25+
2526
jobWorkedCh chan<- string
2627
}
2728

internal/dbunique/db_unique_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func TestUniqueKey(t *testing.T) {
4343
argsFunc: func() rivertype.JobArgs {
4444
type EmailJobArgs struct {
4545
JobArgsStaticKind
46+
4647
Recipient string `json:"recipient" river:"unique"`
4748
Subject string `json:"subject" river:"unique"`
4849
Body string `json:"body"`
@@ -66,6 +67,7 @@ func TestUniqueKey(t *testing.T) {
6667
argsFunc: func() rivertype.JobArgs {
6768
type SMSJobArgs struct {
6869
JobArgsStaticKind
70+
6971
PhoneNumber string `json:"phone_number" river:"unique"`
7072
Message string `json:"message,omitempty" river:"unique"`
7173
TemplateID int `json:"template_id"`
@@ -85,6 +87,7 @@ func TestUniqueKey(t *testing.T) {
8587
argsFunc: func() rivertype.JobArgs {
8688
type EmailJobArgs struct {
8789
JobArgsStaticKind
90+
8891
Recipient string `river:"unique"`
8992
Subject string `river:"unique"`
9093
TemplateID int
@@ -104,6 +107,7 @@ func TestUniqueKey(t *testing.T) {
104107
argsFunc: func() rivertype.JobArgs {
105108
type EmailJobArgs struct {
106109
JobArgsStaticKind
110+
107111
Recipient string `json:"recipient" river:"unique"`
108112
Subject string `json:"subject" river:"unique"`
109113
Body string `json:"body"`
@@ -123,6 +127,7 @@ func TestUniqueKey(t *testing.T) {
123127
argsFunc: func() rivertype.JobArgs {
124128
type GenericJobArgs struct {
125129
JobArgsStaticKind
130+
126131
Description string `json:"description"`
127132
Count int `json:"count"`
128133
foo string // won't be marshaled in JSON
@@ -158,6 +163,7 @@ func TestUniqueKey(t *testing.T) {
158163
argsFunc: func() rivertype.JobArgs {
159164
type TaskJobArgs struct {
160165
JobArgsStaticKind
166+
161167
TaskID string
162168
}
163169
return TaskJobArgs{
@@ -189,6 +195,7 @@ func TestUniqueKey(t *testing.T) {
189195
argsFunc: func() rivertype.JobArgs {
190196
type TaskJobArgs struct {
191197
JobArgsStaticKind
198+
192199
TaskID string `json:"task_id"`
193200
}
194201
return TaskJobArgs{
@@ -204,6 +211,7 @@ func TestUniqueKey(t *testing.T) {
204211
argsFunc: func() rivertype.JobArgs {
205212
type TaskJobArgs struct {
206213
JobArgsStaticKind
214+
207215
TaskID string `json:"task_id"`
208216
}
209217
return TaskJobArgs{
@@ -219,6 +227,7 @@ func TestUniqueKey(t *testing.T) {
219227
argsFunc: func() rivertype.JobArgs {
220228
type TaskJobArgs struct {
221229
JobArgsStaticKind
230+
222231
TaskID string `json:"task_id"`
223232
}
224233
return TaskJobArgs{

internal/jobcompleter/job_completer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (c *AsyncCompleter) Start(ctx context.Context) error {
225225
<-ctx.Done()
226226

227227
if err := c.errGroup.Wait(); err != nil {
228-
c.Logger.Error("Error waiting on async completer", "err", err)
228+
c.Logger.ErrorContext(ctx, "Error waiting on async completer", "err", err)
229229
}
230230
}()
231231

@@ -316,7 +316,7 @@ func (c *BatchCompleter) Start(ctx context.Context) error {
316316
// Try to insert last batch before leaving. Note we use the
317317
// original context so operations aren't immediately cancelled.
318318
if err := c.handleBatch(ctx); err != nil {
319-
c.Logger.Error(c.Name+": Error completing batch", "err", err)
319+
c.Logger.ErrorContext(ctx, c.Name+": Error completing batch", "err", err)
320320
}
321321
return
322322

@@ -336,7 +336,7 @@ func (c *BatchCompleter) Start(ctx context.Context) error {
336336

337337
for {
338338
if err := c.handleBatch(ctx); err != nil {
339-
c.Logger.Error(c.Name+": Error completing batch", "err", err)
339+
c.Logger.ErrorContext(ctx, c.Name+": Error completing batch", "err", err)
340340
}
341341

342342
// New jobs to complete may have come in while working the batch

0 commit comments

Comments
 (0)