Skip to content

Commit 82da9b0

Browse files
committed
fix: upgrade golangci-lint
1 parent c7040d3 commit 82da9b0

File tree

4 files changed

+82
-20
lines changed

4 files changed

+82
-20
lines changed

.golangci.yml

Lines changed: 78 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1-
# Based on https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322
2-
# This code is licensed under the terms of the MIT license https://opensource.org/license/mit
3-
# Copyright (c) 2021 Marat Reymers
1+
# This file is licensed under the terms of the MIT license https://opensource.org/license/mit
2+
# Copyright (c) 2021-2025 Marat Reymers
43

5-
## Golden config for golangci-lint v1.62.2
4+
## Golden config for golangci-lint v1.64.6
65
#
76
# This is the best config for golangci-lint based on my experience and opinion.
87
# It is very strict, but not extremely strict.
9-
# Feel free to adapt and change it for your needs.
8+
# Feel free to adapt it to suit your needs.
9+
# If this config helps you, please consider keeping a link to this file (see the next comment).
10+
11+
# Based on https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322
1012

1113
run:
1214
# Timeout for analysis, e.g. 30s, 5m.
1315
# Default: 1m
1416
timeout: 5m
1517

18+
# The mode used to evaluate relative paths.
19+
# It's used by exclusions, Go plugins, and some linters.
20+
# The value can be:
21+
# - `gomod`: the paths will be relative to the directory of the `go.mod` file.
22+
# - `gitroot`: the paths will be relative to the git root (the parent directory of `.git`).
23+
# - `cfg`: the paths will be relative to the configuration file.
24+
# - `wd` (NOT recommended): the paths will be relative to the place where golangci-lint is run.
25+
# Default: wd
26+
relative-path-mode: gomod
27+
1628

1729
# This file contains only configs which differ from defaults.
18-
# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
30+
# All possible options can be found here https://github.com/golangci/golangci-lint/blob/HEAD/.golangci.reference.yml
1931
linters-settings:
2032
cyclop:
2133
# The maximal code complexity to report.
@@ -26,6 +38,51 @@ linters-settings:
2638
# Default: 0.0
2739
package-average: 10.0
2840

41+
depguard:
42+
# Rules to apply.
43+
#
44+
# Variables:
45+
# - File Variables
46+
# Use an exclamation mark `!` to negate a variable.
47+
# Example: `!$test` matches any file that is not a go test file.
48+
#
49+
# `$all` - matches all go files
50+
# `$test` - matches all go test files
51+
#
52+
# - Package Variables
53+
#
54+
# `$gostd` - matches all of go's standard library (Pulled from `GOROOT`)
55+
#
56+
# Default (applies if no custom rules are defined): Only allow $gostd in all files.
57+
rules:
58+
"deprecated":
59+
# List of file globs that will match this list of settings to compare against.
60+
# Default: $all
61+
files:
62+
- "$all"
63+
# List of packages that are not allowed.
64+
# Entries can be a variable (starting with $), a string prefix, or an exact match (if ending with $).
65+
# Default: []
66+
deny:
67+
- pkg: "github.com/golang/protobuf"
68+
desc: "Use google.golang.org/protobuf instead, see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules"
69+
- pkg: "github.com/satori/go.uuid"
70+
desc: "Use github.com/google/uuid instead, satori's package is not maintained"
71+
- pkg: "github.com/gofrs/uuid$"
72+
desc: "Use github.com/gofrs/uuid/v5 or later, it was not a go module before v5"
73+
"non-test files":
74+
files:
75+
- "!$test"
76+
deny:
77+
- pkg: "math/rand$"
78+
desc: "Use math/rand/v2 instead, see https://go.dev/blog/randv2"
79+
"non-main files":
80+
files:
81+
- "!**/main.go"
82+
deny:
83+
- pkg: "log$"
84+
desc: "Use log/slog instead, see https://go.dev/blog/slog"
85+
2986
errcheck:
3087
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
3188
# Such cases aren't reported by default.
@@ -85,6 +142,11 @@ linters-settings:
85142
# Default false
86143
ignore-comments: true
87144

145+
gochecksumtype:
146+
# Presence of `default` case in switch statements satisfies exhaustiveness, if all members are not listed.
147+
# Default: true
148+
default-signifies-exhaustive: false
149+
88150
gocognit:
89151
# Minimal code complexity to report.
90152
# Default: 30 (but we recommend 10-20)
@@ -217,11 +279,10 @@ linters-settings:
217279
# Default: ""
218280
context: "scope"
219281

220-
tenv:
221-
# The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
222-
# Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
282+
usetesting:
283+
# Enable/disable `os.TempDir()` detections.
223284
# Default: false
224-
all: true
285+
os-temp-dir: true
225286

226287
gci:
227288
# Section configuration to compare against.
@@ -280,11 +341,13 @@ linters:
280341
- canonicalheader # checks whether net/http.Header uses canonical header
281342
- copyloopvar # detects places where loop variables are copied (Go 1.22+)
282343
- cyclop # checks function and package cyclomatic complexity
344+
- depguard # checks if package imports are in a list of acceptable packages
283345
- dupl # tool for code clone detection
284346
- durationcheck # checks for two durations multiplied together
285347
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
286348
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
287349
- exhaustive # checks exhaustiveness of enum switch statements
350+
- exptostd # detects functions from golang.org/x/exp/ that can be replaced by std functions
288351
- fatcontext # detects nested contexts in loops
289352
- forbidigo # forbids identifiers
290353
- funlen # tool for detection of long functions
@@ -299,7 +362,6 @@ linters:
299362
- godot # checks if comments end in a period
300363
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
301364
- gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
302-
- gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
303365
- goprintffuncname # checks that printf-like functions are named with f at the end
304366
- gosec # inspects source code for security problems
305367
- iface # checks the incorrect use of interfaces, helping developers avoid interface pollution
@@ -313,6 +375,7 @@ linters:
313375
- nakedret # finds naked returns in functions greater than a specified function length
314376
- nestif # reports deeply nested if statements
315377
- nilerr # finds the code that returns nil even if it checks that the error is not nil
378+
- nilnesserr # reports that it checks for err != nil, but it returns a different nil value error (powered by nilness and nilerr)
316379
- nilnil # checks that there is no simultaneous return of nil error and an invalid value
317380
- noctx # finds sending http request without context.Context
318381
- nolintlint # reports ill-formed or insufficient nolint directives
@@ -330,14 +393,14 @@ linters:
330393
- spancheck # checks for mistakes with OpenTelemetry/Census spans
331394
- sqlclosecheck # checks that sql.Rows and sql.Stmt are closed
332395
- stylecheck # is a replacement for golint
333-
- tenv # detects using os.Setenv instead of t.Setenv since Go1.17
334396
- testableexamples # checks if examples are testable (have an expected output)
335397
- testifylint # checks usage of github.com/stretchr/testify
336398
- testpackage # makes you use a separate _test package
337399
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
338400
- unconvert # removes unnecessary type conversions
339401
- unparam # reports unused function parameters
340402
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library
403+
- usetesting # reports uses of functions with replacement inside the testing package
341404
- wastedassign # finds wasted assignment statements
342405
- whitespace # detects leading and trailing whitespace
343406

@@ -346,7 +409,7 @@ linters:
346409
- exhaustruct # [highly recommend to enable] checks if all structure fields are initialized
347410
- gci # controls golang package import order and makes it always deterministic
348411
#- ginkgolinter # [if you use ginkgo/gomega] enforces standards of using ginkgo and gomega
349-
#- godox # detects FIXME, TODO and other comment keywords
412+
#- godox # detects usage of FIXME, TODO and other keywords inside comments
350413
#- goheader # checks is file header matches to pattern
351414
#- inamedparam # [great idea, but too strict, need to ignore a lot of cases by default] reports interfaces with unnamed method parameters
352415
#- interfacebloat # checks the number of methods inside an interface
@@ -360,15 +423,14 @@ linters:
360423
## disabled
361424
#- containedctx # detects struct contained context.Context field
362425
#- contextcheck # [too many false positives] checks the function whether use a non-inherited context
363-
#- depguard # [replaced by gomodguard] checks if package imports are in a list of acceptable packages
364426
#- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
365427
#- dupword # [useless without config] checks for duplicate words in the source code
366428
#- err113 # [too strict] checks the errors handling expressions
367429
#- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/errchkjson] checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted
368-
#- exportloopref # [not necessary from Go 1.22] checks for pointers to enclosing loop variables
369430
#- forcetypeassert # [replaced by errcheck] finds forced type assertions
370431
#- gofmt # [replaced by goimports] checks whether code was gofmt-ed
371432
#- gofumpt # [replaced by goimports, gofumports is not available yet] checks whether code was gofumpt-ed
433+
#- gomodguard # [use more powerful depguard] allow and block lists linter for direct Go module dependencies
372434
#- gosmopolitan # reports certain i18n/l10n anti-patterns in your Go codebase
373435
#- grouper # analyzes expression groups
374436
#- importas # enforces consistent import aliases
@@ -377,6 +439,7 @@ linters:
377439
#- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity
378440
#- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test
379441
#- tagliatelle # checks the struct tags
442+
#- tenv # [deprecated, replaced by usetesting] detects using os.Setenv instead of t.Setenv since Go1.17
380443
#- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers
381444
#- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines
382445

app/sephirah/internal/biz/bizangela/feed.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package bizangela
33
import (
44
"context"
55
"fmt"
6+
"slices"
67
"sort"
78
"time"
89

@@ -14,8 +15,6 @@ import (
1415
"github.com/tuihub/librarian/internal/lib/libmq"
1516
"github.com/tuihub/librarian/internal/model/modelfeed"
1617
porter "github.com/tuihub/protos/pkg/librarian/porter/v1"
17-
18-
"golang.org/x/exp/slices"
1918
)
2019

2120
func NewPullFeedTopic( //nolint:gocognit // TODO

app/sephirah/internal/data/data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"path"
8+
"slices"
89

910
"github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent"
1011
"github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/migrate"
@@ -14,7 +15,6 @@ import (
1415

1516
"entgo.io/ent/dialect/sql"
1617
"github.com/google/wire"
17-
"golang.org/x/exp/slices"
1818

1919
_ "github.com/lib/pq" // required by ent
2020
_ "github.com/mattn/go-sqlite3" // required by ent

internal/lib/libtype/slice.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package libtype
22

33
import (
4-
"math/rand"
4+
"math/rand/v2"
55
)
66

77
func ShuffleSlice[T any](ss []T) {
88
for i := range ss {
9-
j := rand.Intn(i + 1) //nolint:gosec // not critical
9+
j := rand.IntN(i + 1) //nolint:gosec // not critical
1010
ss[i], ss[j] = ss[j], ss[i]
1111
}
1212
}

0 commit comments

Comments
 (0)