Skip to content

Commit da1ff41

Browse files
committed
bumps; migrate golangci-lint v2
1 parent 931f9fc commit da1ff41

File tree

8 files changed

+353
-318
lines changed

8 files changed

+353
-318
lines changed

.golangci.yml

Lines changed: 98 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,115 @@
1-
# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/golangci.jsonschema.json
1+
# yaml-language-server: https://raw.githubusercontent.com/golangci/golangci-lint/refs/heads/main/jsonschema/golangci.jsonschema.json
22

33
# https://golangci-lint.run/usage/configuration/
44
# https://golangci-lint.run/usage/linters/
5+
# https://ldez.github.io/blog/2025/03/23/golangci-lint-v2/
56

7+
version: "2"
68
run:
7-
go: '1.24'
8-
timeout: 10m
9-
issues-exit-code: 1
10-
tests: true
9+
go: "1.24"
1110
build-tags:
1211
- integration
1312
modules-download-mode: readonly
14-
13+
issues-exit-code: 1
14+
tests: true
1515
output:
1616
formats:
17-
- format: colored-line-number
17+
text:
1818
path: stderr
19-
print-issued-lines: true
20-
print-linter-name: true
21-
19+
print-linter-name: true
20+
print-issued-lines: true
21+
colors: true
2222
linters:
23-
enable-all: true
23+
default: all
24+
2425
disable:
25-
- tenv # deprecated
26-
- exhaustruct # TODO: reconsider
27-
- depguard # TODO: reconsider
28-
- funlen # TODO: reconsider
29-
- wsl
26+
- cyclop
27+
- depguard
28+
- dupl
29+
- exhaustive
30+
- exhaustruct
31+
- funlen
32+
- gochecknoglobals
33+
- gocognit
34+
- godot
35+
- godox
3036
- lll
31-
- wrapcheck
32-
- varnamelen
37+
- mnd
38+
- nlreturn
3339
- nonamedreturns
40+
- perfsprint
41+
- tagliatelle
3442
- testpackage
35-
- godox
36-
- godot
37-
- gochecknoglobals
38-
- mnd
39-
40-
issues:
41-
# https://golangci-lint.run/usage/false-positives/#default-exclusions
42-
exclude-use-default: true
43-
include:
44-
- EXC0004
45-
- EXC0005
46-
- EXC0006
47-
exclude-rules:
48-
- path: '(.+)_test\.go'
49-
linters: [gochecknoglobals, goconst, goerr113, dupl, maintidx]
50-
- path: '(.+)_test\.go'
51-
linters: [govet]
52-
text: 'fieldalignment:'
53-
54-
linters-settings:
55-
# https://golangci-lint.run/usage/linters/#unused
56-
unused:
57-
field-writes-are-uses: false
58-
post-statements-are-reads: false
59-
exported-fields-are-used: true
60-
parameters-are-used: true
61-
local-variables-are-used: false
62-
generated-is-used: true
63-
64-
# https://golangci-lint.run/usage/linters/#tagliatelle
65-
tagliatelle:
66-
case:
67-
use-field-name: true
43+
- unparam
44+
- varnamelen
45+
- wrapcheck
46+
- wsl
47+
- funcorder
48+
49+
settings:
50+
staticcheck:
51+
checks: ["all", "-QF1008"]
52+
nlreturn:
53+
block-size: 3
54+
nolintlint:
55+
allow-unused: true
56+
paralleltest:
57+
ignore-missing: true
58+
ignore-missing-subtests: true
59+
revive:
60+
severity: error
61+
enable-all-rules: false
6862
rules:
69-
# Any struct tag type can be used.
70-
# Support string case: `camel`, `pascal`, `kebab`, `snake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower`
71-
json: snake
72-
yaml: camel
73-
xml: camel
74-
bson: camel
75-
avro: snake
76-
mapstructure: kebab
77-
78-
# https://golangci-lint.run/usage/linters/#paralleltest
79-
paralleltest:
80-
ignore-missing: true
81-
ignore-missing-subtests: true
82-
83-
# https://golangci-lint.run/usage/linters/#nolintlint
84-
nolintlint:
85-
# Disable to ensure that all nolint directives actually have an effect.
86-
# Default: false
87-
allow-unused: true
88-
89-
# https://golangci-lint.run/usage/linters/#nlreturn
90-
nlreturn:
91-
block-size: 3
92-
93-
# https://golangci-lint.run/usage/linters/#cyclop
94-
cyclop:
95-
max-complexity: 20
96-
package-average: 0.0
97-
skip-tests: true
98-
99-
# https://golangci-lint.run/usage/linters/#gocyclo
100-
gocyclo:
101-
min-complexity: 40
102-
103-
# https://golangci-lint.run/usage/linters/#maintidx
104-
maintidx:
105-
under: 10
106-
107-
# https://golangci-lint.run/usage/linters/#govet
108-
govet:
109-
enable-all: true
110-
settings:
111-
shadow:
112-
strict: false
113-
#disable:
114-
# - fieldalignment
115-
116-
# https://golangci-lint.run/usage/linters/#prealloc
117-
prealloc:
118-
simple: true
119-
range-loops: true
120-
for-loops: true
121-
122-
sloglint:
123-
attr-only: true
124-
no-global: "all"
125-
context: "scope" # report only if a context exists in the scope of the outermost function
126-
static-msg: true
127-
key-naming-case: snake # Values: snake, kebab, camel, pascal
128-
forbidden-keys:
129-
- msg
63+
- name: unused-parameter
64+
disabled: true
65+
tagliatelle:
66+
case:
67+
rules:
68+
avro: snake
69+
bson: camel
70+
json: snake
71+
mapstructure: kebab
72+
xml: camel
73+
yaml: camel
74+
use-field-name: true
75+
76+
exclusions:
77+
generated: lax
78+
presets:
79+
- comments
80+
- std-error-handling
81+
rules:
82+
- linters:
83+
- dupl
84+
- err113
85+
- gochecknoglobals
86+
- goconst
87+
- maintidx
88+
path: (.+)_test\.go
89+
- linters:
90+
- govet
91+
path: (.+)_test\.go
92+
text: 'fieldalignment:'
93+
- linters:
94+
- dupl
95+
- err113
96+
- gochecknoglobals
97+
- goconst
98+
- maintidx
99+
path: internal/tesatingx/testdata
100+
paths:
101+
- third_party$
102+
- builtin$
103+
- examples$
104+
105+
# https://golangci-lint.run/usage/formatters/
106+
# https://golangci-lint.run/usage/configuration/#formatters-configuration
107+
formatters:
108+
enable:
109+
- gci
110+
- gofmt
111+
- gofumpt
112+
- goimports
113+
#- golines
114+
exclusions:
115+
generated: lax
File renamed without changes.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ env:
5858
checks: vet staticcheck gofumpt goimports golangci-lint
5959

6060
.PHONY: ci-gen-n-format
61-
ci-gen-n-format: mockery goimports gofumpt
61+
ci-gen-n-format: mockery goimports gofumpt golangci-lint-fmt
6262
./scripts/git-check-dirty
6363

6464
.PHONY: ci-mod

internal/httpx/router_test.go

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

33
import (
4-
"context"
54
"encoding/json"
65
"net/http"
76
"net/http/httptest"
@@ -13,7 +12,7 @@ import (
1312

1413
func TestAPI_AboutRouteHandler(t *testing.T) {
1514
resp := httptest.NewRecorder()
16-
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "/", nil)
15+
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/", nil)
1716
if err != nil {
1817
t.Fatal(err)
1918
}

scripts/tools.mk

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html
2+
## in order for
3+
#.SECONDEXPANSION:
4+
## https://www.gnu.org/software/make/manual/html_node/Special-Targets.html#index-not-intermediate-targets_002c-explicit
5+
## NOTINTERMEDIATE requires make >=4.4
6+
.NOTINTERMEDIATE:
7+
18
# https://www.gnu.org/software/make/manual/make.html#Automatic-Variables
29
# https://www.gnu.org/software/make/manual/make.html#Prerequisite-Types
310

@@ -15,7 +22,8 @@ tools: \
1522
$(TOOLS_BIN)/gofumpt \
1623
$(TOOLS_BIN)/gojq \
1724
$(TOOLS_BIN)/shfmt \
18-
$(TOOLS_BIN)/shellcheck
25+
$(TOOLS_BIN)/shellcheck \
26+
$(TOOLS_BIN)/mockery
1927

2028
.PHONY: clean-tools
2129
clean-tools:
@@ -35,14 +43,14 @@ $(TOOLS_DB)/%.ver: | $(TOOLS_DB)
3543

3644
define go_install
3745
@echo -e "Installing \e[1;36m$(1)\e[0m@\e[1;36m$(3)\e[0m using \e[1;36m$(GO_VER)\e[0m"
38-
GOBIN="$(TOOLS_BIN)" CGO_ENABLED=0 go install -trimpath -ldflags '-s -w -extldflags "-static"' "$(2)@$(3)"
46+
GOBIN="$(TOOLS_BIN)" CGO_ENABLED=0 go install -tags='$(4)' -trimpath -ldflags '-s -w -extldflags "-static"' "$(2)@$(3)"
3947
@echo ""
4048
endef
4149

4250
# export GOMOD=$(shell pwd)/go_tools.mod
4351
# go get -modfile='go_tools.mod' -u ...
4452
define go_mod_ver
45-
$(shell go list -modfile='./tools/go.mod' -m $(1) | cut -d ' ' -f2)
53+
$(shell (cd tools && go list -modfile='go.mod' -m $(1) | cut -d ' ' -f2) )
4654
endef
4755

4856

@@ -66,14 +74,20 @@ staticcheck: $(TOOLS_BIN)/staticcheck
6674

6775
## <golangci-lint>
6876
# https://github.com/golangci/golangci-lint/releases
69-
GOLANGCI-LINT_MOD:=github.com/golangci/golangci-lint
77+
GOLANGCI-LINT_MOD:=github.com/golangci/golangci-lint/v2
7078
GOLANGCI-LINT_VER:=$(call go_mod_ver,$(GOLANGCI-LINT_MOD))
7179
$(TOOLS_BIN)/golangci-lint: $(TOOLS_DB)/golangci-lint.$(GOLANGCI-LINT_VER).$(GO_VER).ver
72-
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLS_BIN) $(GOLANGCI-LINT_VER)
80+
$(call go_install,golangci-lint,$(GOLANGCI-LINT_MOD)/cmd/golangci-lint,$(GOLANGCI-LINT_VER))
81+
#@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLS_BIN) $(GOLANGCI-LINT_VER)
7382

7483
.PHONY: golangci-lint
7584
golangci-lint: $(TOOLS_BIN)/golangci-lint
76-
golangci-lint run --out-format colored-line-number
85+
golangci-lint run
86+
@echo ''
87+
88+
.PHONY: golangci-lint-fmt
89+
golangci-lint-fmt: $(TOOLS_BIN)/golangci-lint
90+
golangci-lint fmt
7791
@echo ''
7892
## </golangci-lint>
7993

@@ -152,7 +166,7 @@ $(TOOLS_BIN)/mockery: $(TOOLS_DB)/mockery.$(MOCKERY_VER).$(GO_VER).ver
152166
.PHONY: mockery
153167
mockery: $(TOOLS_BIN)/mockery
154168
grep --recursive --files-with-matches '// Code generated by mockery' . | grep -v 'scripts/tools.mk' | grep -v 'bin/mockery' | xargs rm || true
155-
mockery --config=.mockery.yml
169+
mockery --config ./.mockery.yaml
156170
## </mockery>
157171

158172
## <protobuf>

0 commit comments

Comments
 (0)