Skip to content

Commit 97fc800

Browse files
committed
CI: add linter and formatter
1 parent fd3b37c commit 97fc800

File tree

4 files changed

+1384
-0
lines changed

4 files changed

+1384
-0
lines changed

.golangci.yml

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
version: "2"
2+
run:
3+
# If you change this please run `make lint` to see where else it needs to be
4+
# updated as well.
5+
go: "1.24.6"
6+
7+
# timeout for analysis
8+
timeout: 10m
9+
10+
linters:
11+
default: all
12+
disable:
13+
# Global variables are used in many places throughout the code base.
14+
- gochecknoglobals
15+
16+
# We want to allow short variable names.
17+
- varnamelen
18+
19+
# We want to allow TODOs.
20+
- godox
21+
22+
# Init functions are used by loggers throughout the codebase.
23+
- gochecknoinits
24+
25+
# Allow using default empty values.
26+
- exhaustruct
27+
28+
# Allow tests to be put in the same package.
29+
- testpackage
30+
31+
# Disable tagalign.
32+
- tagalign
33+
34+
# TODO(yy): create a list of allowed packages to import before enabling
35+
# this linter.
36+
- depguard
37+
38+
# Deprecated - this is replaced by wsl_v5.
39+
- wsl
40+
41+
# All available settings of specific linters.
42+
settings:
43+
nlreturn:
44+
# Size of the block (including return statement that is still "OK")
45+
# so no return split required.
46+
block-size: 3
47+
48+
funlen:
49+
# Checks the number of lines in a function.
50+
# If lower than 0, disable the check.
51+
lines: 100
52+
# Checks the number of statements in a function.
53+
statements: 50
54+
55+
wsl_v5:
56+
# We adopt a more relaxed cuddling rule by enabling
57+
# `allow-whole-block`. This allows a variable declaration to be
58+
# "cuddled" with a following block if the variable is used anywhere
59+
# within that block, not just as the first statement.
60+
allow-whole-block: true
61+
allow-first-in-block: false
62+
63+
# Disable the leading-whitespace check to resolve a conflict with the
64+
# whitespace linter, which requires a blank line after a function
65+
# signature. This is the standard Go style.
66+
disable:
67+
- leading-whitespace
68+
69+
lll:
70+
# Max line length, lines longer will be reported.
71+
# '\t' is counted as 1 character by default, and can be changed with the
72+
# tab-width option.
73+
# Default: 120.
74+
line-length: 80
75+
# Tab width in spaces.
76+
# Default: 1
77+
tab-width: 8
78+
79+
whitespace:
80+
multi-func: true
81+
multi-if: true
82+
83+
# Defines a set of rules to ignore issues.
84+
# It does not skip the analysis, and so does not ignore "typecheck" errors.
85+
exclusions:
86+
# Mode of the generated files analysis.
87+
#
88+
# - `strict`: sources are excluded by strictly following the Go generated file convention.
89+
# Source files that have lines matching only the following regular expression will be excluded: `^// Code generated .* DO NOT EDIT\.$`
90+
# This line must appear before the first non-comment, non-blank text in the file.
91+
# https://go.dev/s/generatedcode
92+
# - `lax`: sources are excluded if they contain lines like `autogenerated file`, `code generated`, `do not edit`, etc.
93+
# - `disable`: disable the generated files exclusion.
94+
#
95+
# Default: strict
96+
generated: lax
97+
98+
# Which file paths to exclude: they will be analyzed, but issues from them won't be reported.
99+
# "/" will be replaced by the current OS file path separator to properly work on Windows.
100+
# Default: []
101+
paths:
102+
- rpc/legacyrpc/
103+
- wallet/deprecated.go
104+
105+
rules:
106+
# Exclude gosec from running for tests so that tests with weak randomness
107+
# (math/rand) will pass the linter.
108+
- path: _test\.go
109+
linters:
110+
- gosec
111+
- funlen
112+
- revive
113+
# Allow duplications in tests so it's easier to follow a single unit
114+
# test.
115+
- dupl
116+
# Allow returning unwrapped errors in tests.
117+
- wrapcheck
118+
119+
- path: mock*
120+
linters:
121+
- revive
122+
# forcetypeassert is skipped for the mock because the test would fail if
123+
# the returned value doesn't match the type, so there's no need to check
124+
# the convert.
125+
- forcetypeassert
126+
127+
# Allow fmt.Printf() in commands.
128+
- path: cmd/commands/*
129+
linters:
130+
- forbidigo
131+
132+
# Allow fmt.Printf() in config parsing.
133+
- path: config\.go
134+
linters:
135+
- forbidigo
136+
137+
issues:
138+
# Show only new issues created after git revision `REV`.
139+
# Default: ""
140+
new-from-rev: 49d94f09c3382dcc9e5c0f61089109d54213b7c5
141+
# Maximum issues count per one linter.
142+
# Set to 0 to disable.
143+
# Default: 50
144+
max-issues-per-linter: 0
145+
# Maximum count of issues with the same text.
146+
# Set to 0 to disable.
147+
# Default: 3
148+
max-same-issues: 0
149+
# Make issues output unique by line.
150+
# Default: true
151+
uniq-by-line: false

tools/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM golang:1.24.6-alpine
2+
3+
ENV GOFLAGS="-buildvcs=false"
4+
5+
RUN apk update && apk add --no-cache git
6+
7+
WORKDIR /build
8+
9+
COPY tools/go.mod tools/go.sum ./
10+
11+
RUN go install -trimpath \
12+
github.com/golangci/golangci-lint/v2/cmd/golangci-lint \
13+
github.com/rinchsan/gosimports/cmd/gosimports \
14+
&& rm -rf /go/pkg/mod \
15+
&& rm -rf /root/.cache/go-build \
16+
&& rm -rf /go/src \
17+
&& rm -rf /tmp/*
18+
19+
RUN chmod -R 777 /build \
20+
&& git config --global --add safe.directory /build

tools/go.mod

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
module tools
2+
3+
go 1.24.6
4+
5+
tool (
6+
github.com/golangci/golangci-lint/v2/cmd/golangci-lint
7+
github.com/rinchsan/gosimports/cmd/gosimports
8+
)
9+
10+
require (
11+
4d63.com/gocheckcompilerdirectives v1.3.0 // indirect
12+
4d63.com/gochecknoglobals v0.2.2 // indirect
13+
codeberg.org/chavacava/garif v0.2.0 // indirect
14+
dev.gaijin.team/go/exhaustruct/v4 v4.0.0 // indirect
15+
dev.gaijin.team/go/golib v0.6.0 // indirect
16+
github.com/4meepo/tagalign v1.4.3 // indirect
17+
github.com/Abirdcfly/dupword v0.1.6 // indirect
18+
github.com/AlwxSin/noinlineerr v1.0.5 // indirect
19+
github.com/Antonboom/errname v1.1.0 // indirect
20+
github.com/Antonboom/nilnil v1.1.0 // indirect
21+
github.com/Antonboom/testifylint v1.6.1 // indirect
22+
github.com/BurntSushi/toml v1.5.0 // indirect
23+
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect
24+
github.com/Masterminds/semver/v3 v3.3.1 // indirect
25+
github.com/OpenPeeDeeP/depguard/v2 v2.2.1 // indirect
26+
github.com/alecthomas/chroma/v2 v2.20.0 // indirect
27+
github.com/alecthomas/go-check-sumtype v0.3.1 // indirect
28+
github.com/alexkohler/nakedret/v2 v2.0.6 // indirect
29+
github.com/alexkohler/prealloc v1.0.0 // indirect
30+
github.com/alfatraining/structtag v1.0.0 // indirect
31+
github.com/alingse/asasalint v0.0.11 // indirect
32+
github.com/alingse/nilnesserr v0.2.0 // indirect
33+
github.com/ashanbrown/forbidigo/v2 v2.1.0 // indirect
34+
github.com/ashanbrown/makezero/v2 v2.0.1 // indirect
35+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
36+
github.com/beorn7/perks v1.0.1 // indirect
37+
github.com/bkielbasa/cyclop v1.2.3 // indirect
38+
github.com/blizzy78/varnamelen v0.8.0 // indirect
39+
github.com/bombsimon/wsl/v4 v4.7.0 // indirect
40+
github.com/bombsimon/wsl/v5 v5.1.1 // indirect
41+
github.com/breml/bidichk v0.3.3 // indirect
42+
github.com/breml/errchkjson v0.4.1 // indirect
43+
github.com/butuzov/ireturn v0.4.0 // indirect
44+
github.com/butuzov/mirror v1.3.0 // indirect
45+
github.com/catenacyber/perfsprint v0.9.1 // indirect
46+
github.com/ccojocar/zxcvbn-go v1.0.4 // indirect
47+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
48+
github.com/charithe/durationcheck v0.0.10 // indirect
49+
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
50+
github.com/charmbracelet/lipgloss v1.1.0 // indirect
51+
github.com/charmbracelet/x/ansi v0.8.0 // indirect
52+
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
53+
github.com/charmbracelet/x/term v0.2.1 // indirect
54+
github.com/ckaznocha/intrange v0.3.1 // indirect
55+
github.com/curioswitch/go-reassign v0.3.0 // indirect
56+
github.com/daixiang0/gci v0.13.7 // indirect
57+
github.com/dave/dst v0.27.3 // indirect
58+
github.com/davecgh/go-spew v1.1.1 // indirect
59+
github.com/denis-tingaikin/go-header v0.5.0 // indirect
60+
github.com/dlclark/regexp2 v1.11.5 // indirect
61+
github.com/ettle/strcase v0.2.0 // indirect
62+
github.com/fatih/color v1.18.0 // indirect
63+
github.com/fatih/structtag v1.2.0 // indirect
64+
github.com/firefart/nonamedreturns v1.0.6 // indirect
65+
github.com/fsnotify/fsnotify v1.5.4 // indirect
66+
github.com/fzipp/gocyclo v0.6.0 // indirect
67+
github.com/ghostiam/protogetter v0.3.15 // indirect
68+
github.com/go-critic/go-critic v0.13.0 // indirect
69+
github.com/go-toolsmith/astcast v1.1.0 // indirect
70+
github.com/go-toolsmith/astcopy v1.1.0 // indirect
71+
github.com/go-toolsmith/astequal v1.2.0 // indirect
72+
github.com/go-toolsmith/astfmt v1.1.0 // indirect
73+
github.com/go-toolsmith/astp v1.1.0 // indirect
74+
github.com/go-toolsmith/strparse v1.1.0 // indirect
75+
github.com/go-toolsmith/typep v1.1.0 // indirect
76+
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
77+
github.com/go-xmlfmt/xmlfmt v1.1.3 // indirect
78+
github.com/gobwas/glob v0.2.3 // indirect
79+
github.com/gofrs/flock v0.12.1 // indirect
80+
github.com/golang/protobuf v1.5.3 // indirect
81+
github.com/golangci/asciicheck v0.5.0 // indirect
82+
github.com/golangci/dupl v0.0.0-20250308024227-f665c8d69b32 // indirect
83+
github.com/golangci/go-printf-func-name v0.1.0 // indirect
84+
github.com/golangci/gofmt v0.0.0-20250106114630-d62b90e6713d // indirect
85+
github.com/golangci/golangci-lint/v2 v2.4.1-0.20250818164121-838684c5bc0c // indirect
86+
github.com/golangci/golines v0.0.0-20250217134842-442fd0091d95 // indirect
87+
github.com/golangci/misspell v0.7.0 // indirect
88+
github.com/golangci/plugin-module-register v0.1.2 // indirect
89+
github.com/golangci/revgrep v0.8.0 // indirect
90+
github.com/golangci/swaggoswag v0.0.0-20250504205917-77f2aca3143e // indirect
91+
github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e // indirect
92+
github.com/google/go-cmp v0.7.0 // indirect
93+
github.com/gordonklaus/ineffassign v0.1.0 // indirect
94+
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
95+
github.com/gostaticanalysis/comment v1.5.0 // indirect
96+
github.com/gostaticanalysis/forcetypeassert v0.2.0 // indirect
97+
github.com/gostaticanalysis/nilerr v0.1.1 // indirect
98+
github.com/hashicorp/go-immutable-radix/v2 v2.1.0 // indirect
99+
github.com/hashicorp/go-version v1.7.0 // indirect
100+
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
101+
github.com/hashicorp/hcl v1.0.0 // indirect
102+
github.com/hexops/gotextdiff v1.0.3 // indirect
103+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
104+
github.com/jgautheron/goconst v1.8.2 // indirect
105+
github.com/jingyugao/rowserrcheck v1.1.1 // indirect
106+
github.com/jjti/go-spancheck v0.6.5 // indirect
107+
github.com/julz/importas v0.2.0 // indirect
108+
github.com/karamaru-alpha/copyloopvar v1.2.1 // indirect
109+
github.com/kisielk/errcheck v1.9.0 // indirect
110+
github.com/kkHAIKE/contextcheck v1.1.6 // indirect
111+
github.com/kulti/thelper v0.6.3 // indirect
112+
github.com/kunwardeep/paralleltest v1.0.14 // indirect
113+
github.com/lasiar/canonicalheader v1.1.2 // indirect
114+
github.com/ldez/exptostd v0.4.4 // indirect
115+
github.com/ldez/gomoddirectives v0.7.0 // indirect
116+
github.com/ldez/grignotin v0.10.0 // indirect
117+
github.com/ldez/tagliatelle v0.7.1 // indirect
118+
github.com/ldez/usetesting v0.5.0 // indirect
119+
github.com/leonklingele/grouper v1.1.2 // indirect
120+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
121+
github.com/macabu/inamedparam v0.2.0 // indirect
122+
github.com/magiconair/properties v1.8.6 // indirect
123+
github.com/manuelarte/embeddedstructfieldcheck v0.4.0 // indirect
124+
github.com/manuelarte/funcorder v0.5.0 // indirect
125+
github.com/maratori/testableexamples v1.0.0 // indirect
126+
github.com/maratori/testpackage v1.1.1 // indirect
127+
github.com/matoous/godox v1.1.0 // indirect
128+
github.com/mattn/go-colorable v0.1.14 // indirect
129+
github.com/mattn/go-isatty v0.0.20 // indirect
130+
github.com/mattn/go-runewidth v0.0.16 // indirect
131+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
132+
github.com/mgechev/revive v1.11.0 // indirect
133+
github.com/mitchellh/go-homedir v1.1.0 // indirect
134+
github.com/mitchellh/mapstructure v1.5.0 // indirect
135+
github.com/moricho/tparallel v0.3.2 // indirect
136+
github.com/muesli/termenv v0.16.0 // indirect
137+
github.com/nakabonne/nestif v0.3.1 // indirect
138+
github.com/nishanths/exhaustive v0.12.0 // indirect
139+
github.com/nishanths/predeclared v0.2.2 // indirect
140+
github.com/nunnatsa/ginkgolinter v0.20.0 // indirect
141+
github.com/pelletier/go-toml v1.9.5 // indirect
142+
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
143+
github.com/pmezard/go-difflib v1.0.0 // indirect
144+
github.com/polyfloyd/go-errorlint v1.8.0 // indirect
145+
github.com/prometheus/client_golang v1.12.1 // indirect
146+
github.com/prometheus/client_model v0.2.0 // indirect
147+
github.com/prometheus/common v0.32.1 // indirect
148+
github.com/prometheus/procfs v0.7.3 // indirect
149+
github.com/quasilyte/go-ruleguard v0.4.4 // indirect
150+
github.com/quasilyte/go-ruleguard/dsl v0.3.22 // indirect
151+
github.com/quasilyte/gogrep v0.5.0 // indirect
152+
github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect
153+
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
154+
github.com/raeperd/recvcheck v0.2.0 // indirect
155+
github.com/rinchsan/gosimports v0.3.8 // indirect
156+
github.com/rivo/uniseg v0.4.7 // indirect
157+
github.com/rogpeppe/go-internal v1.14.1 // indirect
158+
github.com/ryancurrah/gomodguard v1.4.1 // indirect
159+
github.com/ryanrolds/sqlclosecheck v0.5.1 // indirect
160+
github.com/sanposhiho/wastedassign/v2 v2.1.0 // indirect
161+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 // indirect
162+
github.com/sashamelentyev/interfacebloat v1.1.0 // indirect
163+
github.com/sashamelentyev/usestdlibvars v1.29.0 // indirect
164+
github.com/securego/gosec/v2 v2.22.8 // indirect
165+
github.com/sirupsen/logrus v1.9.3 // indirect
166+
github.com/sivchari/containedctx v1.0.3 // indirect
167+
github.com/sonatard/noctx v0.4.0 // indirect
168+
github.com/sourcegraph/go-diff v0.7.0 // indirect
169+
github.com/spf13/afero v1.14.0 // indirect
170+
github.com/spf13/cast v1.5.0 // indirect
171+
github.com/spf13/cobra v1.9.1 // indirect
172+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
173+
github.com/spf13/pflag v1.0.7 // indirect
174+
github.com/spf13/viper v1.12.0 // indirect
175+
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
176+
github.com/stbenjam/no-sprintf-host-port v0.2.0 // indirect
177+
github.com/stretchr/objx v0.5.2 // indirect
178+
github.com/stretchr/testify v1.10.0 // indirect
179+
github.com/subosito/gotenv v1.4.1 // indirect
180+
github.com/tetafro/godot v1.5.1 // indirect
181+
github.com/timakin/bodyclose v0.0.0-20241222091800-1db5c5ca4d67 // indirect
182+
github.com/timonwong/loggercheck v0.11.0 // indirect
183+
github.com/tomarrell/wrapcheck/v2 v2.11.0 // indirect
184+
github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect
185+
github.com/ultraware/funlen v0.2.0 // indirect
186+
github.com/ultraware/whitespace v0.2.0 // indirect
187+
github.com/uudashr/gocognit v1.2.0 // indirect
188+
github.com/uudashr/iface v1.4.1 // indirect
189+
github.com/xen0n/gosmopolitan v1.3.0 // indirect
190+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
191+
github.com/yagipy/maintidx v1.0.0 // indirect
192+
github.com/yeya24/promlinter v0.3.0 // indirect
193+
github.com/ykadowak/zerologlint v0.1.5 // indirect
194+
gitlab.com/bosi/decorder v0.4.2 // indirect
195+
go-simpler.org/musttag v0.14.0 // indirect
196+
go-simpler.org/sloglint v0.11.1 // indirect
197+
go.augendre.info/arangolint v0.2.0 // indirect
198+
go.augendre.info/fatcontext v0.8.1 // indirect
199+
go.uber.org/automaxprocs v1.6.0 // indirect
200+
go.uber.org/multierr v1.10.0 // indirect
201+
go.uber.org/zap v1.27.0 // indirect
202+
golang.org/x/exp/typeparams v0.0.0-20250620022241-b7579e27df2b // indirect
203+
golang.org/x/mod v0.27.0 // indirect
204+
golang.org/x/sync v0.16.0 // indirect
205+
golang.org/x/sys v0.35.0 // indirect
206+
golang.org/x/text v0.28.0 // indirect
207+
golang.org/x/tools v0.36.0 // indirect
208+
google.golang.org/protobuf v1.36.6 // indirect
209+
gopkg.in/ini.v1 v1.67.0 // indirect
210+
gopkg.in/yaml.v2 v2.4.0 // indirect
211+
gopkg.in/yaml.v3 v3.0.1 // indirect
212+
honnef.co/go/tools v0.6.1 // indirect
213+
mvdan.cc/gofumpt v0.8.0 // indirect
214+
mvdan.cc/unparam v0.0.0-20250301125049-0df0534333a4 // indirect
215+
)

0 commit comments

Comments
 (0)