Skip to content

Commit 9b531a8

Browse files
authored
Update golangci-lint to v2 (#208)
1 parent 38b5d4e commit 9b531a8

16 files changed

+297
-137
lines changed

.golangci.yml

Lines changed: 167 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,171 @@
1+
version: "2"
12
linters:
3+
enable:
4+
- asasalint
5+
- asciicheck
6+
- bidichk
7+
- bodyclose
8+
- canonicalheader
9+
# - containedctx - there are enough legitimate cases
10+
- contextcheck
11+
- copyloopvar
12+
# - cyclop - too opinionated on code structure
13+
- decorder
14+
# - depguard - must be explicitly configured
15+
# - dogsled - some APIs just lend to it
16+
# - dupl - duplicate code can be useful many times
17+
- dupword
18+
- durationcheck
19+
# - err113 - good for avoiding errors.New but prevents fmt.Errorf which seems too strict
20+
- errchkjson
21+
- errname
22+
- errorlint
23+
- exhaustive
24+
# - exhaustruct - tedious for non-controlled structs
25+
- exptostd
26+
- fatcontext
27+
# - forbidigo - must be explicitly configured
28+
- forcetypeassert
29+
# - funcorder - TODO to consider this as it can be good, but huge blast radious
30+
# - funlen - long functions can be clearer many times
31+
# - ginkgolinter - don't use ginkgo
32+
- gocheckcompilerdirectives
33+
# - gochecknoglobals - globals are useful many times
34+
# - gochecknoinits - inits are useful many times
35+
- gochecksumtype
36+
# - gocognit - too opinionated on code structure
37+
# - goconst - repeated strings can be more readable
38+
- gocritic
39+
# - gocyclo - too opinionated on code structure
40+
- godot
41+
# - godox - sometimes we leave TODOs
42+
# - goheader - must be explicitly configured
43+
# - gomoddirectives - must be explicitly configured
44+
# - gomodguard - must be explicitly configured
45+
- goprintffuncname
46+
- gosec
47+
# - gosmopolitan - sometimes want to use Japanese text
48+
# - grouper - requiring group for single item conflicts with gofumpt
49+
- iface
50+
# - importas - must be explicitly configured
51+
- inamedparam
52+
# - interfacebloat - no standard rule
53+
- intrange
54+
# - ireturn - not always valid
55+
# - lll - too opinionated on code structure
56+
- loggercheck
57+
# - maintidx - too opinionated on code structure
58+
- makezero
59+
- mirror
60+
# - mnd - can be more readable
61+
- musttag
62+
- nakedret
63+
# - nestif - too opinionated on code structure
64+
- nilerr
65+
- nilnesserr
66+
- nilnil
67+
# nlreturn - too opinionated on style
68+
- noctx
69+
# - nolintlint - seems to just remove nolint directives
70+
# nonamedreturns - too opinionated on style
71+
- nosprintfhostport
72+
# - paralleltest - not always possible
73+
- perfsprint
74+
- prealloc
75+
# - predeclared - can be too tedious
76+
# - promlinter - don't use prometheus
77+
- protogetter
78+
- reassign
79+
- recvcheck
80+
- revive
81+
- rowserrcheck
82+
- sloglint
83+
- spancheck
84+
- sqlclosecheck
85+
- tagalign
86+
- testifylint
87+
# - testpackage - don't need it usually
88+
- thelper
89+
- tparallel
90+
- unconvert
91+
- usestdlibvars
92+
- usetesting
93+
# - varnamelen - too opinionated on style
94+
- wastedassign
95+
- whitespace
96+
- wrapcheck
97+
# - wsl - too opinionated on style
98+
- zerologlint
99+
settings:
100+
gosec:
101+
excludes:
102+
# Use unsafe frequently for cgo performance and should be fine
103+
- G103
104+
# Due to 32-bit nature of wasm, it's very common to convert to 32-bit here
105+
# and not worth too much checking.
106+
- G115
107+
grouper:
108+
const-require-grouping: true
109+
import-require-grouping: true
110+
var-require-grouping: true
111+
revive:
112+
# Defaults from https://github.com/mgechev/revive/blob/master/defaults.toml
113+
# Because we want to set preserveScope in one setting, we end up having to
114+
# list them all out.
115+
rules:
116+
- name: blank-imports
117+
- name: context-as-argument
118+
- name: context-keys-type
119+
- name: dot-imports
120+
- name: empty-block
121+
- name: error-naming
122+
- name: error-return
123+
- name: error-strings
124+
- name: errorf
125+
- name: exported
126+
disabled: true
127+
- name: increment-decrement
128+
- name: indent-error-flow
129+
arguments:
130+
- preserve-scope
131+
- name: package-comments
132+
disabled: true
133+
- name: range
134+
- name: receiver-naming
135+
- name: redefines-builtin-id
136+
# TODO: Investigate why preserve-scope doesn't work
137+
- name: superfluous-else
138+
disabled: true
139+
arguments:
140+
- preserve-scope
141+
- name: time-naming
142+
- name: unexported-return
143+
- name: unreachable-code
144+
- name: unused-parameter
145+
- name: var-declaration
146+
- name: var-naming
147+
exclusions:
148+
presets:
149+
- comments
150+
rules:
151+
- linters:
152+
- errcheck
153+
- errchkjson
154+
- gosec
155+
- noctx
156+
path: _test\.go
157+
paths:
158+
# Preserve code copied from upstream
159+
- all_test.go
160+
- benchmarks_test.go
161+
- find_test.go
162+
formatters:
2163
enable:
3164
- gci
4165
- gofumpt
5-
linters-settings:
6-
gci:
7-
sections:
8-
- standard
9-
- default
10-
- prefix(github.com/wasilibs/go-re2)
11-
issues:
12-
exclude-rules:
13-
- path: magefiles
14-
linters:
15-
- deadcode
16-
- path: _test.go
17-
linters:
18-
# We have tests for deprecated methods
19-
- staticcheck
166+
settings:
167+
gci:
168+
sections:
169+
- standard
170+
- default
171+
- prefix(github.com/wasilibs/go-re2)

all_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ func compileTest(t *testing.T, expr string, error string) *Regexp {
6161
}
6262

6363
func TestGoodCompile(t *testing.T) {
64-
for i := 0; i < len(goodRe); i++ {
64+
for i := range goodRe {
6565
compileTest(t, goodRe[i], "")
6666
}
6767
}
6868

6969
func TestBadCompile(t *testing.T) {
70-
for i := 0; i < len(badRe); i++ {
70+
for i := range badRe {
7171
compileTest(t, badRe[i].re, badRe[i].err)
7272
}
7373
}
@@ -429,7 +429,7 @@ func TestSubexp(t *testing.T) {
429429
continue
430430
}
431431
if c.names != nil {
432-
for i := 0; i < 1+n; i++ {
432+
for i := range 1 + n {
433433
if names[i] != c.names[i] {
434434
t.Errorf("%q: SubexpNames[%d] = %q, want %q", c.input, i, names[i], c.names[i])
435435
}
@@ -536,7 +536,7 @@ func TestSwitchBacktrack(t *testing.T) {
536536

537537
// GAP: Because we just wrap pointers to C++ structs, Go reflection cannot compare
538538
// for equality correctly.
539-
//func TestDeepEqual(t *testing.T) {
539+
// func TestDeepEqual(t *testing.T) {
540540
// re1 := MustCompile("a.*b.*c.*d")
541541
// re2 := MustCompile("a.*b.*c.*d")
542542
// if !reflect.DeepEqual(re1, re2) { // has always been true, since Go 1.

0 commit comments

Comments
 (0)