Skip to content

Commit 3038a52

Browse files
ci: update code analysis configuration and add GolangCI-Lint settings
1 parent 7dc9f2c commit 3038a52

2 files changed

Lines changed: 252 additions & 5 deletions

File tree

.github/workflows/analysis.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
name: "Code Analysis"
2-
on: ["push", "pull_request"]
2+
3+
on:
4+
pull_request:
5+
push:
6+
paths:
7+
- '**.go'
8+
- 'go.mod'
9+
- 'go.sum'
10+
11+
permissions:
12+
contents: read
313

414
jobs:
515
basic:
616
name: "Run Basic Code Analysis"
7-
runs-on: ubuntu-latest
17+
runs-on: self-hosted
818
steps:
919
- uses: actions/checkout@v4
1020
- uses: actions/setup-go@v5
1121
with:
1222
go-version: 'stable'
1323
- run: "go test ./..."
14-
- run: "go vet ./..."
1524
golangci-lint:
1625
name: "Run GolangCI-Lint Code Analysis"
17-
runs-on: ubuntu-latest
26+
runs-on: self-hosted
1827
steps:
1928
- uses: actions/checkout@v4
2029
- uses: actions/setup-go@v5
2130
with:
2231
go-version: 'stable'
2332
- name: golangci-lint
24-
uses: golangci/golangci-lint-action@v6
33+
uses: golangci/golangci-lint-action@v7
2534
with:
2635
version: latest

.golangci.yml

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
version: "2"
2+
run:
3+
relative-path-mode: gomod
4+
linters:
5+
default: none
6+
enable:
7+
- asasalint
8+
- asciicheck
9+
- bidichk
10+
- bodyclose
11+
- canonicalheader
12+
- copyloopvar
13+
- cyclop
14+
- depguard
15+
# - dupl
16+
- durationcheck
17+
- errcheck
18+
- errname
19+
- errorlint
20+
- exhaustive
21+
- exptostd
22+
- fatcontext
23+
- forbidigo
24+
# - funlen
25+
- gocheckcompilerdirectives
26+
- gochecknoinits
27+
- gochecksumtype
28+
# - gocognit
29+
- goconst
30+
- gocritic
31+
# - gocyclo
32+
- gomoddirectives
33+
- goprintffuncname
34+
- gosec
35+
- govet
36+
- iface
37+
- ineffassign
38+
- intrange
39+
- lll
40+
- loggercheck
41+
- makezero
42+
- mirror
43+
- musttag
44+
- nakedret
45+
- nestif
46+
- nilerr
47+
- nilnesserr
48+
- noctx
49+
- nolintlint
50+
- nosprintfhostport
51+
- perfsprint
52+
- predeclared
53+
- promlinter
54+
- protogetter
55+
- reassign
56+
- recvcheck
57+
- revive
58+
- rowserrcheck
59+
- sloglint
60+
- spancheck
61+
- sqlclosecheck
62+
- staticcheck
63+
- testableexamples
64+
- testifylint
65+
- testpackage
66+
- tparallel
67+
- unconvert
68+
- unparam
69+
- unused
70+
- usestdlibvars
71+
- usetesting
72+
- wastedassign
73+
- whitespace
74+
- zerologlint
75+
settings:
76+
cyclop:
77+
max-complexity: 30
78+
package-average: 10
79+
depguard:
80+
rules:
81+
deprecated:
82+
files:
83+
- $all
84+
deny:
85+
- pkg: github.com/golang/protobuf
86+
desc: Use google.golang.org/protobuf instead, see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules
87+
- pkg: github.com/satori/go.uuid
88+
desc: Use github.com/google/uuid instead, satori's package is not maintained
89+
- pkg: github.com/gofrs/uuid$
90+
desc: Use github.com/gofrs/uuid/v5 or later, it was not a go module before v5
91+
non-main files:
92+
files:
93+
- '!**/main.go'
94+
deny:
95+
- pkg: log$
96+
desc: Use log/slog instead, see https://go.dev/blog/slog
97+
non-test files:
98+
files:
99+
- '!$test'
100+
deny:
101+
- pkg: math/rand$
102+
desc: Use math/rand/v2 instead, see https://go.dev/blog/randv2
103+
errcheck:
104+
check-type-assertions: true
105+
exhaustive:
106+
check:
107+
- switch
108+
- map
109+
exhaustruct:
110+
exclude:
111+
- ^net/http.Client$
112+
- ^net/http.Cookie$
113+
- ^net/http.Request$
114+
- ^net/http.Response$
115+
- ^net/http.Server$
116+
- ^net/http.Transport$
117+
- ^net/url.URL$
118+
- ^os/exec.Cmd$
119+
- ^reflect.StructField$
120+
- ^github.com/Shopify/sarama.Config$
121+
- ^github.com/Shopify/sarama.ProducerMessage$
122+
- ^github.com/mitchellh/mapstructure.DecoderConfig$
123+
- ^github.com/prometheus/client_golang/.+Opts$
124+
- ^github.com/spf13/cobra.Command$
125+
- ^github.com/spf13/cobra.CompletionOptions$
126+
- ^github.com/stretchr/testify/mock.Mock$
127+
- ^github.com/testcontainers/testcontainers-go.+Request$
128+
- ^github.com/testcontainers/testcontainers-go.FromDockerfile$
129+
- ^golang.org/x/tools/go/analysis.Analyzer$
130+
- ^google.golang.org/protobuf/.+Options$
131+
- ^gopkg.in/yaml.v3.Node$
132+
funlen:
133+
lines: 100
134+
statements: 50
135+
ignore-comments: true
136+
gocognit:
137+
min-complexity: 20
138+
gochecksumtype:
139+
default-signifies-exhaustive: false
140+
gocritic:
141+
settings:
142+
captLocal:
143+
paramsOnly: false
144+
underef:
145+
skipRecvDeref: false
146+
govet:
147+
disable:
148+
- fieldalignment
149+
enable-all: true
150+
settings:
151+
shadow:
152+
strict: false
153+
inamedparam:
154+
skip-single-param: true
155+
lll:
156+
line-length: 200
157+
mnd:
158+
ignored-functions:
159+
- args.Error
160+
- flag.Arg
161+
- flag.Duration.*
162+
- flag.Float.*
163+
- flag.Int.*
164+
- flag.Uint.*
165+
- os.Chmod
166+
- os.Mkdir.*
167+
- os.OpenFile
168+
- os.WriteFile
169+
- prometheus.ExponentialBuckets.*
170+
- prometheus.LinearBuckets
171+
nolintlint:
172+
require-explanation: true
173+
require-specific: true
174+
allow-no-explanation:
175+
- funlen
176+
- gocognit
177+
- lll
178+
- dupl
179+
- nestif
180+
perfsprint:
181+
strconcat: false
182+
reassign:
183+
patterns:
184+
- .*
185+
rowserrcheck:
186+
packages:
187+
- github.com/jmoiron/sqlx
188+
sloglint:
189+
no-global: all
190+
context: scope
191+
usetesting:
192+
os-temp-dir: true
193+
recvcheck:
194+
disable-builtin: true
195+
exclusions:
196+
generated: lax
197+
presets:
198+
- comments
199+
- common-false-positives
200+
- legacy
201+
- std-error-handling
202+
rules:
203+
- linters:
204+
- godot
205+
source: (noinspection|TODO)
206+
- linters:
207+
- gocritic
208+
source: //noinspection
209+
- linters:
210+
- bodyclose
211+
- dupl
212+
- errcheck
213+
- funlen
214+
- goconst
215+
- gosec
216+
- noctx
217+
- wrapcheck
218+
path: _test\.go
219+
- path: (.+)\.go$
220+
text: 'shadow: declaration of .err. shadows declaration'
221+
- path: (.+)\.go$
222+
text: 'shadow: declaration of .ok. shadows declaration'
223+
paths:
224+
- third_party$
225+
- builtin$
226+
- examples$
227+
- server/server.go
228+
issues:
229+
max-same-issues: 50
230+
formatters:
231+
enable:
232+
- goimports
233+
exclusions:
234+
generated: lax
235+
paths:
236+
- third_party$
237+
- builtin$
238+
- examples$

0 commit comments

Comments
 (0)