Skip to content

Commit 8b6a80b

Browse files
authored
ci: add golangci-lint and fix existing lint failures (#118)
This PR adds `golangci-lint` based on the configuration from `coder/coder` ([here](https://github.com/coder/coder/blob/main/.golangci.yaml)) then migrated to v2 using `golangci-lint migrate` plus the addition of few more linters. --------- Signed-off-by: Callum Styan <[email protected]>
1 parent 3a54a31 commit 8b6a80b

File tree

11 files changed

+599
-105
lines changed

11 files changed

+599
-105
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- master
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
golangci:
14+
name: lint
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-go@v5
19+
with:
20+
go-version: stable
21+
- name: golangci-lint
22+
uses: golangci/golangci-lint-action@v8
23+
with:
24+
version: v2.1

.golangci.yml

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
version: "2"
2+
linters:
3+
default: none
4+
enable:
5+
- asciicheck
6+
- bidichk
7+
- bodyclose
8+
- dogsled
9+
- dupl
10+
- errcheck
11+
- errname
12+
- errorlint
13+
- exhaustruct
14+
- forcetypeassert
15+
- gocognit
16+
- gocritic
17+
- godot
18+
- gomodguard
19+
- gosec
20+
- govet
21+
- importas
22+
- ineffassign
23+
- makezero
24+
- misspell
25+
- nestif
26+
- nilnil
27+
# - noctx
28+
# - paralleltest
29+
- revive
30+
- staticcheck
31+
# - tparallel
32+
- unconvert
33+
- unused
34+
settings:
35+
dupl:
36+
threshold: 412
37+
godot:
38+
scope: all
39+
capital: true
40+
exhaustruct:
41+
include:
42+
- httpmw\.\w+
43+
- github.com/coder/coder/v2/coderd/database\.[^G][^e][^t]\w+Params
44+
gocognit:
45+
min-complexity: 300
46+
goconst:
47+
min-len: 4
48+
min-occurrences: 3
49+
gocritic:
50+
enabled-checks:
51+
- badLock
52+
- badRegexp
53+
- boolExprSimplify
54+
- builtinShadow
55+
- builtinShadowDecl
56+
- commentedOutImport
57+
- deferUnlambda
58+
- dupImport
59+
- dynamicFmtString
60+
- emptyDecl
61+
- emptyFallthrough
62+
- emptyStringTest
63+
- evalOrder
64+
- externalErrorReassign
65+
- filepathJoin
66+
- hexLiteral
67+
- httpNoBody
68+
- importShadow
69+
- indexAlloc
70+
- initClause
71+
- methodExprCall
72+
- nestingReduce
73+
- nilValReturn
74+
- preferFilepathJoin
75+
- rangeAppendAll
76+
- regexpPattern
77+
- redundantSprint
78+
- regexpSimplify
79+
- ruleguard
80+
- sliceClear
81+
- sortSlice
82+
- sprintfQuotedString
83+
- sqlQuery
84+
- stringConcatSimplify
85+
- stringXbytes
86+
- todoCommentWithoutDetail
87+
- tooManyResultsChecker
88+
- truncateCmp
89+
- typeAssertChain
90+
- typeDefFirst
91+
- unlabelStmt
92+
- weakCond
93+
- whyNoLint
94+
settings:
95+
ruleguard:
96+
failOn: all
97+
rules: ${base-path}/scripts/rules.go
98+
gosec:
99+
excludes:
100+
- G601
101+
govet:
102+
disable:
103+
- loopclosure
104+
importas:
105+
no-unaliased: true
106+
misspell:
107+
locale: US
108+
ignore-rules:
109+
- trialer
110+
nestif:
111+
min-complexity: 20
112+
revive:
113+
severity: warning
114+
rules:
115+
- name: atomic
116+
- name: bare-return
117+
- name: blank-imports
118+
- name: bool-literal-in-expr
119+
- name: call-to-gc
120+
- name: confusing-results
121+
- name: constant-logical-expr
122+
- name: context-as-argument
123+
- name: context-keys-type
124+
# - name: deep-exit
125+
- name: defer
126+
- name: dot-imports
127+
- name: duplicated-imports
128+
- name: early-return
129+
- name: empty-block
130+
- name: empty-lines
131+
- name: error-naming
132+
- name: error-return
133+
- name: error-strings
134+
- name: errorf
135+
- name: exported
136+
- name: flag-parameter
137+
- name: get-return
138+
- name: identical-branches
139+
- name: if-return
140+
- name: import-shadowing
141+
- name: increment-decrement
142+
- name: indent-error-flow
143+
- name: modifies-value-receiver
144+
- name: package-comments
145+
- name: range
146+
- name: receiver-naming
147+
- name: redefines-builtin-id
148+
- name: string-of-int
149+
- name: struct-tag
150+
- name: superfluous-else
151+
- name: time-naming
152+
- name: unconditional-recursion
153+
- name: unexported-naming
154+
- name: unexported-return
155+
- name: unhandled-error
156+
- name: unnecessary-stmt
157+
- name: unreachable-code
158+
- name: unused-parameter
159+
- name: unused-receiver
160+
- name: var-declaration
161+
- name: var-naming
162+
- name: waitgroup-by-value
163+
staticcheck:
164+
checks:
165+
- all
166+
- SA4006 # Detects redundant assignments
167+
- SA4009 # Detects redundant variable declarations
168+
- SA1019
169+
exclusions:
170+
generated: lax
171+
presets:
172+
- comments
173+
- common-false-positives
174+
- legacy
175+
- std-error-handling
176+
rules:
177+
- linters:
178+
- errcheck
179+
- exhaustruct
180+
- forcetypeassert
181+
path: _test\.go
182+
- linters:
183+
- exhaustruct
184+
path: scripts/*
185+
- linters:
186+
- ALL
187+
path: scripts/rules.go
188+
paths:
189+
- scripts/rules.go
190+
- coderd/database/dbmem
191+
- node_modules
192+
- .git
193+
- third_party$
194+
- builtin$
195+
- examples$
196+
issues:
197+
max-issues-per-linter: 0
198+
max-same-issues: 0
199+
fix: true
200+
formatters:
201+
enable:
202+
- goimports
203+
- gofmt
204+
exclusions:
205+
generated: lax
206+
paths:
207+
- scripts/rules.go
208+
- coderd/database/dbmem
209+
- node_modules
210+
- .git
211+
- third_party$
212+
- builtin$
213+
- examples$

0 commit comments

Comments
 (0)