Skip to content

Commit e90ea7c

Browse files
authored
upgrade golangci-lint to v2.12.2 (#1299)
1 parent 465b2a6 commit e90ea7c

6 files changed

Lines changed: 22 additions & 14 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ jobs:
299299
name: lint
300300
runs-on: ubuntu-latest
301301
env:
302-
GOLANGCI_LINT_VERSION: v2.11.4
302+
GOLANGCI_LINT_VERSION: v2.12.2
303303
permissions:
304304
contents: read
305305
# allow read access to pull request. Use with `only-new-issues` option.

.golangci.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ linters:
1111
- exhaustruct # checks that properties in structs are exhaustively defined; may be a good idea
1212
- testpackage # requires tests in test packages like `river_test`
1313

14+
# disabled because it's deprecated, and `default: all` already enables its
15+
# replacement (`gomodguard_v2`)
16+
- gomodguard
17+
1418
# disabled because they're annoying/bad
1519
- cyclop # screams into the void at "cyclomatic complexity"
1620
- funcorder # very particular about where unexported functions can go, lots of churn.
1721
- funlen # screams when functions are more than 60 lines long; what are we even doing here guys
22+
- goconst # wants repeated test strings and other obvious literals to be constants; lots of churn.
1823
- interfacebloat # we do in fact want >10 methods on the Adapter interface or wherever we see fit.
1924
- gocognit # yells that "cognitive complexity" is too high; why
2025
- gocyclo # ANOTHER "cyclomatic complexity" checker (see also "cyclop" and "gocyclo")

client.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"log/slog"
1010
"os"
1111
"regexp"
12+
"slices"
1213
"strings"
1314
"sync"
1415
"sync/atomic"
@@ -2011,9 +2012,9 @@ func (c *Client[TTx]) insertManyShared(
20112012
if len(jobInsertMiddleware) > 0 {
20122013
// Wrap middlewares in reverse order so the one defined first is wrapped
20132014
// as the outermost function and is first to receive the operation.
2014-
for i := len(jobInsertMiddleware) - 1; i >= 0; i-- {
2015-
middlewareItem := jobInsertMiddleware[i].(rivertype.JobInsertMiddleware) //nolint:forcetypeassert // capture the current middleware item
2016-
previousDoInner := doInner // Capture the current doInner function
2015+
for _, v := range slices.Backward(jobInsertMiddleware) {
2016+
middlewareItem := v.(rivertype.JobInsertMiddleware) //nolint:forcetypeassert // capture the current middleware item
2017+
previousDoInner := doInner // Capture the current doInner function
20172018
doInner = func(ctx context.Context) ([]*rivertype.JobInsertResult, error) {
20182019
return middlewareItem.InsertMany(ctx, insertParams, previousDoInner)
20192020
}

internal/execution/execution.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package execution
22

33
import (
44
"context"
5+
"slices"
56

67
"github.com/riverqueue/river/rivertype"
78
)
@@ -22,17 +23,17 @@ func MiddlewareChain(globalMiddleware []rivertype.Middleware, workerMiddleware [
2223

2324
// Wrap middlewares in reverse order so the one defined first is wrapped
2425
// as the outermost function and is first to receive the operation.
25-
for i := len(globalMiddleware) - 1; i >= 0; i-- {
26-
middlewareItem := globalMiddleware[i].(rivertype.WorkerMiddleware) //nolint:forcetypeassert // capture the current middleware item
27-
previousDoInner := doInner // capture the current doInner function
26+
for _, v := range slices.Backward(globalMiddleware) {
27+
middlewareItem := v.(rivertype.WorkerMiddleware) //nolint:forcetypeassert // capture the current middleware item
28+
previousDoInner := doInner // capture the current doInner function
2829
doInner = func(ctx context.Context) error {
2930
return middlewareItem.Work(ctx, jobRow, previousDoInner)
3031
}
3132
}
3233

33-
for i := len(workerMiddleware) - 1; i >= 0; i-- {
34-
middlewareItem := workerMiddleware[i] // capture the current middleware item
35-
previousDoInner := doInner // capture the current doInner function
34+
for _, v := range slices.Backward(workerMiddleware) {
35+
middlewareItem := v // capture the current middleware item
36+
previousDoInner := doInner // capture the current doInner function
3637
doInner = func(ctx context.Context) error {
3738
return middlewareItem.Work(ctx, jobRow, previousDoInner)
3839
}

rivershared/circuitbreaker/circuit_breaker.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package circuitbreaker
22

33
import (
4+
"slices"
45
"time"
56

67
"github.com/riverqueue/river/rivershared/baseservice"
@@ -92,8 +93,8 @@ func (b *CircuitBreaker) Trip() bool {
9293
horizonIndex = -1
9394
now = b.timeGenerator.Now()
9495
)
95-
for i := len(b.trips) - 1; i >= 0; i-- {
96-
if b.trips[i].Before(now.Add(-b.opts.Window)) {
96+
for i, v := range slices.Backward(b.trips) {
97+
if v.Before(now.Add(-b.opts.Window)) {
9798
horizonIndex = i
9899
break
99100
}

rivershared/structtag/struct_tag.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func SortedFieldsWithTag(args rivertype.JobArgs, tagValue string) ([]string, err
8383
// don't cause a stack overflow.
8484
func sortedFieldsWithTagUncached(typ reflect.Type, tagValue string, path []string, typesSeen map[reflect.Type]struct{}) ([]string, error) {
8585
// Handle pointer to struct
86-
if typ.Kind() == reflect.Ptr {
86+
if typ.Kind() == reflect.Pointer {
8787
typ = typ.Elem()
8888
}
8989

@@ -188,7 +188,7 @@ func typeStructOrPointerToStruct(typ reflect.Type) bool {
188188
return true
189189
}
190190

191-
if typ.Kind() == reflect.Ptr && typ.Elem().Kind() == reflect.Struct {
191+
if typ.Kind() == reflect.Pointer && typ.Elem().Kind() == reflect.Struct {
192192
return true
193193
}
194194

0 commit comments

Comments
 (0)