Skip to content

Commit 872d15c

Browse files
yxxherohexcsl
authored andcommitted
feat: add lint CI (databus23#469)
* feat: add lint CI Signed-off-by: yxxhero <[email protected]> * fix lint errors Signed-off-by: yxxhero <[email protected]> * fix more lint error Signed-off-by: yxxhero <[email protected]> * fix more lint errors Signed-off-by: yxxhero <[email protected]> --------- Signed-off-by: yxxhero <[email protected]>
1 parent e466c92 commit 872d15c

File tree

11 files changed

+426
-36
lines changed

11 files changed

+426
-36
lines changed

.github/workflows/lint.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: Lint
3+
4+
on:
5+
push:
6+
branches: [ master ]
7+
paths-ignore: [ '**.md' ]
8+
pull_request:
9+
branches: [ master ]
10+
paths-ignore: [ '**.md' ]
11+
12+
env:
13+
GO_VERSION: 1.19
14+
15+
jobs:
16+
lint:
17+
name: Lint
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 10
20+
steps:
21+
- uses: actions/setup-go@v3
22+
with:
23+
go-version: '1.19'
24+
25+
- name: Checkout code
26+
uses: actions/checkout@v3
27+
28+
- name: Golangci lint
29+
uses: golangci/golangci-lint-action@v3
30+
with:
31+
version: v1.51.0

.golangci.yaml

Lines changed: 360 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,360 @@
1+
# This file contains all available configuration options
2+
# with their default values.
3+
4+
# options for analysis running
5+
run:
6+
# default concurrency is a available CPU number
7+
# concurrency: 4
8+
9+
# timeout for analysis, e.g. 30s, 5m, default is 1m
10+
timeout: 30m
11+
12+
# exit code when at least one issue was found, default is 1
13+
issues-exit-code: 1
14+
15+
# include test files or not, default is true
16+
tests: true
17+
18+
# list of build tags, all linters use it. Default is empty list.
19+
# build-tags:
20+
# - mytag
21+
22+
# which dirs to skip: issues from them won't be reported;
23+
# can use regexp here: generated.*, regexp is applied on full path;
24+
# default value is empty list, but default dirs are skipped independently
25+
# from this option's value (see skip-dirs-use-default).
26+
# skip-dirs:
27+
# - src/external_libs
28+
# - autogenerated_by_my_lib
29+
30+
# default is true. Enables skipping of directories:
31+
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
32+
skip-dirs-use-default: true
33+
34+
# which files to skip: they will be analyzed, but issues from them
35+
# won't be reported. Default value is empty list, but there is
36+
# no need to include all autogenerated files, we confidently recognize
37+
# autogenerated files. If it's not please let us know.
38+
# skip-files:
39+
# - ".*\\.my\\.go$"
40+
# - lib/bad.go
41+
42+
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
43+
# If invoked with -mod=readonly, the go command is disallowed from the implicit
44+
# automatic updating of go.mod described above. Instead, it fails when any changes
45+
# to go.mod are needed. This setting is most useful to check that go.mod does
46+
# not need updates, such as in a continuous integration and testing system.
47+
# If invoked with -mod=vendor, the go command assumes that the vendor
48+
# directory holds the correct copies of dependencies and ignores
49+
# the dependency descriptions in go.mod.
50+
# modules-download-mode: readonly|release|vendor
51+
52+
# output configuration options
53+
output:
54+
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
55+
format: line-number
56+
57+
# print lines of code with issue, default is true
58+
print-issued-lines: true
59+
60+
# print linter name in the end of issue text, default is true
61+
print-linter-name: true
62+
63+
# all available settings of specific linters
64+
linters-settings:
65+
gci:
66+
sections:
67+
- standard
68+
- default
69+
- prefix(github.com/databus23/helm-diff/v3)
70+
71+
errcheck:
72+
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
73+
# default is false: such cases aren't reported by default.
74+
check-type-assertions: false
75+
76+
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
77+
# default is false: such cases aren't reported by default.
78+
check-blank: false
79+
80+
# [deprecated] comma-separated list of pairs of the form pkg:regex
81+
# the regex is used to ignore names within pkg. (default "fmt:.*").
82+
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
83+
# ignore: fmt:.*
84+
85+
# path to a file containing a list of functions to exclude from checking
86+
# see https://github.com/kisielk/errcheck#excluding-functions for details
87+
# exclude: /path/to/file.txt
88+
89+
# Disable error checking, as errorcheck detects more errors and is more configurable.
90+
gosec:
91+
exclude:
92+
- "G104"
93+
94+
govet:
95+
# report about shadowed variables
96+
check-shadowing: false
97+
98+
# settings per analyzer
99+
settings:
100+
printf: # analyzer name, run `go tool vet help` to see all analyzers
101+
funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
102+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
103+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
104+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
105+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
106+
107+
# enable or disable analyzers by name
108+
# enable:
109+
# - atomicalign
110+
# enable-all: false
111+
# disable:
112+
# - shadow
113+
# disable-all: false
114+
golint:
115+
# minimal confidence for issues, default is 0.8
116+
min-confidence: 0.8
117+
gofmt:
118+
# simplify code: gofmt with `-s` option, true by default
119+
simplify: true
120+
goimports:
121+
# put imports beginning with prefix after 3rd-party packages;
122+
# it's a comma-separated list of prefixes
123+
# local-prefixes: github.com/org/project
124+
gocyclo:
125+
# minimal code complexity to report, 30 by default (but we recommend 10-20)
126+
min-complexity: 30
127+
gocognit:
128+
# minimal code complexity to report, 30 by default (but we recommend 10-20)
129+
min-complexity: 100
130+
maligned:
131+
# print struct with more effective memory layout or not, false by default
132+
suggest-new: true
133+
dupl:
134+
# tokens count to trigger issue, 150 by default
135+
threshold: 100
136+
goconst:
137+
# minimal length of string constant, 3 by default
138+
min-len: 3
139+
# minimal occurrences count to trigger, 3 by default
140+
min-occurrences: 8
141+
# depguard:
142+
# list-type: blacklist
143+
# include-go-root: false
144+
# packages:
145+
# - github.com/sirupsen/logrus
146+
# packages-with-error-messages:
147+
# # specify an error message to output when a blacklisted package is used
148+
# github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
149+
misspell:
150+
# Correct spellings using locale preferences for US or UK.
151+
# Default is to use a neutral variety of English.
152+
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
153+
locale: US
154+
ignore-words:
155+
- GitLab
156+
lll:
157+
# max line length, lines longer will be reported. Default is 120.
158+
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
159+
line-length: 120
160+
# tab width in spaces. Default to 1.
161+
tab-width: 1
162+
unused:
163+
# treat code as a program (not a library) and report unused exported identifiers; default is false.
164+
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
165+
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
166+
# with golangci-lint call it on a directory with the changed file.
167+
check-exported: false
168+
unparam:
169+
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
170+
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
171+
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
172+
# with golangci-lint call it on a directory with the changed file.
173+
check-exported: false
174+
nakedret:
175+
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
176+
max-func-lines: 30
177+
prealloc:
178+
# XXX: we don't recommend using this linter before doing performance profiling.
179+
# For most programs usage of prealloc will be a premature optimization.
180+
181+
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
182+
# True by default.
183+
simple: true
184+
range-loops: true # Report preallocation suggestions on range loops, true by default
185+
for-loops: false # Report preallocation suggestions on for loops, false by default
186+
gocritic:
187+
# Which checks should be enabled; can't be combined with 'disabled-checks';
188+
# See https://go-critic.github.io/overview#checks-overview
189+
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
190+
# By default list of stable checks is used.
191+
# enabled-checks:
192+
# - rangeValCopy
193+
194+
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
195+
# disabled-checks:
196+
# - regexpMust
197+
198+
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
199+
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
200+
# enabled-tags:
201+
# - performance
202+
203+
settings: # settings passed to gocritic
204+
captLocal: # must be valid enabled check name
205+
paramsOnly: true
206+
# rangeValCopy:
207+
# sizeThreshold: 32
208+
godox:
209+
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
210+
# might be left in the code accidentally and should be resolved before merging
211+
keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
212+
- TODO
213+
- BUG
214+
- FIXME
215+
- NOTE
216+
- OPTIMIZE # marks code that should be optimized before merging
217+
- HACK # marks hack-arounds that should be removed before merging
218+
dogsled:
219+
# checks assignments with too many blank identifiers; default is 2
220+
max-blank-identifiers: 2
221+
222+
whitespace:
223+
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
224+
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
225+
wsl:
226+
# If true append is only allowed to be cuddled if appending value is
227+
# matching variables, fields or types on line above. Default is true.
228+
strict-append: true
229+
# Allow calls and assignments to be cuddled as long as the lines have any
230+
# matching variables, fields or types. Default is true.
231+
allow-assign-and-call: true
232+
# Allow multiline assignments to be cuddled. Default is true.
233+
allow-multiline-assign: true
234+
# Allow declarations (var) to be cuddled.
235+
allow-cuddle-declarations: false
236+
# Allow trailing comments in ending of blocks
237+
allow-trailing-comment: false
238+
# Force newlines in end of case at this limit (0 = never).
239+
force-case-trailing-whitespace: 0
240+
revive:
241+
ignore-generated-header: true
242+
severity: warning
243+
funlen:
244+
# Checks the number of lines in a function.
245+
# If lower than 0, disable the check.
246+
# Default: 60
247+
lines: 280
248+
# Checks the number of statements in a function.
249+
# If lower than 0, disable the check.
250+
# Default: 40
251+
statements: 140
252+
253+
linters:
254+
# please, do not use `enable-all`: it's deprecated and will be removed soon.
255+
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
256+
disable-all: true
257+
enable:
258+
- bodyclose
259+
- depguard
260+
- usestdlibvars
261+
- reassign
262+
- errcheck
263+
- funlen
264+
- gocognit
265+
- goconst
266+
- gofmt
267+
- goimports
268+
- revive
269+
- gosimple
270+
- govet
271+
- ineffassign
272+
- misspell
273+
- nakedret
274+
- exportloopref
275+
- staticcheck
276+
- typecheck
277+
- unconvert
278+
- unparam
279+
- unused
280+
- whitespace
281+
- gci
282+
# - gocritic
283+
# - godox
284+
# - gosec
285+
# - interfacer
286+
# - stylecheck
287+
# - dogsled
288+
# - dupl
289+
# don't enable:
290+
# - deadcode
291+
# - gochecknoglobals
292+
# - gochecknoinits
293+
# - gocyclo
294+
# - lll
295+
# - maligned
296+
# - prealloc
297+
# - varcheck
298+
299+
issues:
300+
# List of regexps of issue texts to exclude, empty list by default.
301+
# But independently from this option we use default exclude patterns,
302+
# it can be disabled by `exclude-use-default: false`. To list all
303+
# excluded by default patterns execute `golangci-lint run --help`
304+
# exclude:
305+
# - abcdef
306+
307+
# Excluding configuration per-path, per-linter, per-text and per-source
308+
exclude-rules:
309+
# Exclude some linters from running on tests files.
310+
- path: _test\.go
311+
linters:
312+
- gocyclo
313+
- errcheck
314+
- dupl
315+
- gosec
316+
- funlen
317+
318+
# Exclude known linters from partially hard-vendored code,
319+
# which is impossible to exclude via "nolint" comments.
320+
# - path: internal/hmac/
321+
# text: "weak cryptographic primitive"
322+
# linters:
323+
# - gosec
324+
325+
# Exclude some staticcheck messages
326+
# - linters:
327+
# - staticcheck
328+
# text: "SA9003:"
329+
330+
# Exclude lll issues for long lines with go:generate
331+
- linters:
332+
- lll
333+
source: "^//go:generate "
334+
335+
# Independently from option `exclude` we use default exclude patterns,
336+
# it can be disabled by this option. To list all
337+
# excluded by default patterns execute `golangci-lint run --help`.
338+
# Default value for this option is true.
339+
exclude-use-default: false
340+
341+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
342+
max-issues-per-linter: 0
343+
344+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
345+
max-same-issues: 0
346+
347+
# Show only new issues: if there are unstaged changes or untracked files,
348+
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
349+
# It's a super-useful option for integration of golangci-lint into existing
350+
# large codebase. It's not practical to fix all existing issues at the moment
351+
# of integration: much better don't allow issues in new code.
352+
# Default is false.
353+
new: false
354+
355+
# Show only new issues created after git revision `REV`
356+
# This should be passed as flag during individual CI jobs.
357+
# new-from-rev: REV
358+
359+
# Show only new issues created in git patch with set file path.
360+
# new-from-patch: path/to/patch/file

0 commit comments

Comments
 (0)