Skip to content

Commit f66e613

Browse files
refactor: linters
1 parent 73e81db commit f66e613

File tree

6 files changed

+247
-10
lines changed

6 files changed

+247
-10
lines changed

.github/workflows/lint.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ jobs:
3131
with:
3232
version: v1.52.0
3333
working-directory: tests/slo
34-
args: -c ../../.golangci.yml
3534
autoformatter:
3635
name: autoformat check
3736
concurrency:

tests/slo/.golangci.yml

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
# options for analysis running
2+
run:
3+
# default concurrency is a available CPU number
4+
concurrency: 4
5+
6+
# timeout for analysis, e.g. 30s, 5m, default is 1m
7+
deadline: 5m
8+
9+
# exit code when at least one issue was found, default is 1
10+
issues-exit-code: 1
11+
12+
# include test files or not, default is true
13+
tests: true
14+
15+
# list of build tags, all linters use it. Default is empty list.
16+
#build-tags:
17+
# - mytag
18+
19+
# which dirs to skip: they won't be analyzed;
20+
# can use regexp here: generated.*, regexp is applied on full path;
21+
# default value is empty list, but next dirs are always skipped independently
22+
# from this option's value:
23+
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
24+
# skip-dirs:
25+
26+
# which files to skip: they will be analyzed, but issues from them
27+
# won't be reported. Default value is empty list, but there is
28+
# no need to include all autogenerated files, we confidently recognize
29+
# autogenerated files. If it's not please let us know.
30+
# skip-files:
31+
# - ".*\\.my\\.go$"
32+
# - lib/bad.go
33+
34+
35+
# output configuration options
36+
output:
37+
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
38+
format: colored-line-number
39+
40+
# print lines of code with issue, default is true
41+
print-issued-lines: true
42+
43+
# print linter name in the end of issue text, default is true
44+
print-linter-name: true
45+
46+
47+
# all available settings of specific linters
48+
linters-settings:
49+
errcheck:
50+
# report about not checking of errors in types assetions: `a := b.(MyStruct)`;
51+
# default is false: such cases aren't reported by default.
52+
check-type-assertions: false
53+
54+
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
55+
# default is false: such cases aren't reported by default.
56+
check-blank: false
57+
govet:
58+
# report about shadowed variables
59+
check-shadowing: true
60+
fieldalignment: true
61+
golint:
62+
# minimal confidence for issues, default is 0.8
63+
min-confidence: 0.8
64+
gofmt:
65+
# simplify code: gofmt with `-s` option, true by default
66+
simplify: true
67+
gofumpt:
68+
module-path: slo
69+
goimports:
70+
# put imports beginning with prefix after 3rd-party packages;
71+
# it's a comma-separated list of prefixes
72+
local-prefixes: slo
73+
goconst:
74+
# minimal length of string constant, 3 by default
75+
min-len: 2
76+
# minimal occurrences count to trigger, 3 by default
77+
min-occurrences: 2
78+
fieldalignment:
79+
# print struct with more effective memory layout or not, false by default
80+
suggest-new: true
81+
misspell:
82+
# Correct spellings using locale preferences for US or UK.
83+
# Default is to use a neutral variety of English.
84+
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
85+
locale: US
86+
ignore-words:
87+
- cancelled
88+
revive:
89+
rules:
90+
- name: blank-imports
91+
- name: context-as-argument
92+
- name: context-keys-type
93+
- name: dot-imports
94+
- name: error-return
95+
- name: error-strings
96+
- name: error-naming
97+
- name: exported
98+
- name: if-return
99+
- name: increment-decrement
100+
- name: var-naming
101+
- name: var-declaration
102+
- name: package-comments
103+
- name: range
104+
- name: receiver-naming
105+
- name: time-naming
106+
- name: indent-error-flow
107+
- name: errorf
108+
- name: empty-block
109+
- name: superfluous-else
110+
- name: unreachable-code
111+
unused:
112+
# treat code as a program (not a library) and report unused exported identifiers; default is false.
113+
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
114+
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
115+
# with golangci-lint call it on a directory with the changed file.
116+
check-exported: false
117+
unparam:
118+
# call graph construction algorithm (cha, rta). In general, use cha for libraries,
119+
# and rta for programs with main packages. Default is cha.
120+
algo: cha
121+
122+
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
123+
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
124+
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
125+
# with golangci-lint call it on a directory with the changed file.
126+
check-exported: false
127+
128+
linters:
129+
disable-all: true
130+
enable:
131+
# - cyclop
132+
- depguard
133+
- dogsled
134+
# - dupl
135+
- errcheck
136+
- errorlint
137+
# - exhaustive
138+
# - exhaustivestruct
139+
# - forbidigo
140+
# - funlen
141+
# - gci
142+
# - gocognit
143+
- goconst
144+
- gocritic
145+
- gocyclo
146+
# - godot
147+
- godox
148+
- gofmt # On why gofmt when goimports is enabled - https://github.com/golang/go/issues/21476
149+
- gofumpt
150+
- goheader
151+
- goimports
152+
# - gomnd
153+
# - gomoddirectives
154+
# - gomodguard
155+
- gosec
156+
- gosimple
157+
- govet
158+
- depguard
159+
# - ifshort
160+
# - ireturn
161+
- lll
162+
- makezero
163+
- misspell
164+
- ineffassign
165+
- misspell
166+
- nakedret
167+
- nestif
168+
# - nilnil
169+
# - nlreturn
170+
- nolintlint
171+
- prealloc
172+
- predeclared
173+
- rowserrcheck
174+
- revive
175+
- staticcheck
176+
- stylecheck
177+
# - tagliatelle
178+
# - testpackage
179+
# - thelper
180+
# - tenv
181+
- typecheck
182+
- unconvert
183+
- unparam
184+
- unused
185+
# - varnamelen
186+
- whitespace
187+
# - wrapcheck
188+
# - wsl
189+
190+
issues:
191+
# List of regexps of issue texts to exclude, empty list by default.
192+
# But independently from this option we use default exclude patterns,
193+
# it can be disabled by `exclude-use-default: false`. To list all
194+
# excluded by default patterns execute `golangci-lint run --help`
195+
# exclude:
196+
197+
# List of regexps of issue texts to exclude.
198+
#
199+
# But independently of this option we use default exclude patterns,
200+
# it can be disabled by `exclude-use-default: false`.
201+
# To list all excluded by default patterns execute `golangci-lint run --help`
202+
#
203+
# Default: []
204+
exclude:
205+
- "has been deprecated since Go 1.16"
206+
207+
# Independently from option `exclude` we use default exclude patterns,
208+
# it can be disabled by this option. To list all
209+
# excluded by default patterns execute `golangci-lint run --help`.
210+
# Default value for this option is true.
211+
exclude-use-default: true
212+
213+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
214+
max-per-linter: 0
215+
216+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
217+
max-same-issues: 0
218+
219+
# Show only new issues: if there are unstaged changes or untracked files,
220+
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
221+
# It's a super-useful option for integration of golangci-lint into existing
222+
# large codebase. It's not practical to fix all existing issues at the moment
223+
# of integration: much better don't allow issues in new code.
224+
# Default is false.
225+
new: false
226+
227+
# Show only new issues created after git revision `REV`
228+
# new-from-rev: REV
229+
230+
# Show only new issues created in git patch with set file path.
231+
# new-from-patch: path/to/patch/file
232+
exclude-rules:
233+
- path: internal/xatomic/type.go
234+
linters:
235+
- predeclared
236+
- path: _test\.go
237+
linters:
238+
- unused
239+
- unparam
240+
- path: _test\.go
241+
text: "ydb.Connection is deprecated"

tests/slo/internal/generator/generator.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ func (g *Generator) Generate() (Row, error) {
2929
id := g.currentID
3030
g.currentID++
3131
g.mu.Unlock()
32-
3332
e := Row{
3433
ID: id,
35-
PayloadDouble: func(a float64) *float64 { return &a }(rand.Float64()),
34+
PayloadDouble: func(a float64) *float64 { return &a }(rand.Float64()), //nolint:gosec // speed more important
3635
PayloadTimestamp: func(a uint64) *uint64 { return &a }(uint64(time.Now().UnixMicro())),
3736
}
3837

@@ -46,7 +45,7 @@ func (g *Generator) Generate() (Row, error) {
4645
}
4746

4847
func (g *Generator) genPayloadString() (*string, error) {
49-
l := MinLength + rand.Intn(MaxLength-MinLength+1)
48+
l := MinLength + rand.Intn(MaxLength-MinLength+1) //nolint:gosec // speed more important
5049

5150
sl := make([]byte, l)
5251

tests/slo/internal/workers/read.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (w *Workers) Read(ctx context.Context, wg *sync.WaitGroup, rl *rate.Limiter
2424
}
2525

2626
func (w *Workers) read(ctx context.Context) (err error) {
27-
id := uint64(rand.Intn(int(w.cfg.InitialDataCount)))
27+
id := uint64(rand.Intn(int(w.cfg.InitialDataCount))) //nolint:gosec // speed more important
2828

2929
m := w.m.Start(metrics.JobRead)
3030
defer func() {
@@ -34,7 +34,5 @@ func (w *Workers) read(ctx context.Context) (err error) {
3434

3535
_, err = w.s.Read(ctx, id)
3636

37-
// todo: check
38-
3937
return err
4038
}

tests/slo/native/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func main() {
7272
g := errgroup.Group{}
7373

7474
for i := uint64(0); i < cfg.InitialDataCount; i++ {
75-
g.Go(func() error {
75+
g.Go(func() (err error) {
7676
e, err := gen.Generate()
7777
if err != nil {
7878
return err

tests/slo/native/storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func NewStorage(ctx context.Context, cfg *config.Config, logger *zap.Logger, poo
8888
g := errgroup.Group{}
8989

9090
for i := 0; i < poolSize; i++ {
91-
g.Go(func() error {
92-
err := s.db.Table().Do(ctx, func(ctx context.Context, s table.Session) error {
91+
g.Go(func() (err error) {
92+
err = s.db.Table().Do(ctx, func(ctx context.Context, s table.Session) error {
9393
return nil
9494
})
9595
if err != nil {

0 commit comments

Comments
 (0)