Skip to content

Commit d67a26d

Browse files
ashmckenziestanhu
andcommitted
Merge branch 'sh-add-golangci-lint' into 'main'
Add golangci-lint to CI job See merge request https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/839 Merged-by: Ash McKenzie <[email protected]> Approved-by: Jaime Martinez <[email protected]> Approved-by: Ash McKenzie <[email protected]> Reviewed-by: Ash McKenzie <[email protected]> Reviewed-by: Jaime Martinez <[email protected]> Co-authored-by: Stan Hu <[email protected]>
2 parents 3591b12 + 948c19e commit d67a26d

File tree

2 files changed

+359
-0
lines changed

2 files changed

+359
-0
lines changed

.gitlab-ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,18 @@ modules:tidy:
208208
script:
209209
- go mod tidy
210210
- git diff --exit-code go.mod go.sum
211+
212+
lint:
213+
image: golangci/golangci-lint
214+
stage: test
215+
script:
216+
- apt update && apt install -y libkrb5-dev
217+
# Write the code coverage report to gl-code-quality-report.json
218+
# and print linting issues to stdout in the format: path/to/file:line description
219+
# remove `--issues-exit-code 0` or set to non-zero to fail the job if linting issues are detected
220+
- golangci-lint run --issues-exit-code 0 --print-issued-lines=false --out-format code-climate:gl-code-quality-report.json,line-number
221+
artifacts:
222+
reports:
223+
codequality: gl-code-quality-report.json
224+
paths:
225+
- gl-code-quality-report.json

.golangci.yml

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

0 commit comments

Comments
 (0)