Skip to content

Commit 83ff65a

Browse files
authored
docs: improve linters settings section (#2499)
1 parent a471733 commit 83ff65a

File tree

1 file changed

+81
-68
lines changed

1 file changed

+81
-68
lines changed

.golangci.example.yml

+81-68
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ linters-settings:
128128
# default: true (disabled)
129129
disable-dec-num-check: false
130130

131+
depguard:
132+
list-type: denylist
133+
include-go-root: false
134+
packages:
135+
- github.com/sirupsen/logrus
136+
packages-with-error-message:
137+
# specify an error message to output when a denied package is used
138+
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
139+
# create additional guards that follow the same configuration pattern
140+
# results from all guards are aggregated together
141+
additional-guards:
142+
- list-type: denylist
143+
include-go-root: false
144+
packages:
145+
- github.com/stretchr/testify
146+
# specify rules by which the linter ignores certain files for consideration
147+
ignore-file-rules:
148+
- "**/*_test.go"
149+
- "**/mock/**/*.go"
150+
131151
dogsled:
132152
# checks assignments with too many blank identifiers; default is 2
133153
max-blank-identifiers: 2
@@ -163,9 +183,9 @@ linters-settings:
163183
- io.Copy(os.Stdout)
164184

165185
errchkjson:
166-
# with check-error-free-encoding set to true, errchkjson does warn about errors
186+
# With check-error-free-encoding set to true, errchkjson does warn about errors
167187
# from json encoding functions that are safe to be ignored,
168-
# because they are not possible to happen (default false)
188+
# because they are not possible to happen.
169189
#
170190
# if check-error-free-encoding is set to true and errcheck linter is enabled,
171191
# it is recommended to add the following exceptions to prevent from false positives:
@@ -175,9 +195,12 @@ linters-settings:
175195
# exclude-functions:
176196
# - encoding/json.Marshal
177197
# - encoding/json.MarshalIndent
178-
# - (*encoding/json.Encoder).Encode
179-
check-error-free-encoding: false
180-
# if report-no-exported is true, encoding a struct without exported fields is reported as issue (default false)
198+
#
199+
# default: false
200+
check-error-free-encoding: true
201+
202+
# Issue on struct encoding that doesn't have exported fields.
203+
# default: false
181204
report-no-exported: false
182205

183206
errorlint:
@@ -210,11 +233,12 @@ linters-settings:
210233
- 'example.com/package.ExampleStruct'
211234

212235
forbidigo:
213-
# Forbid the following identifiers (identifiers are written using regexp):
236+
# Forbid the following identifiers (list of regexp):
214237
forbid:
215238
- ^print.*$
216239
- 'fmt\.Print.*'
217-
# Exclude godoc examples from forbidigo checks. Default is true.
240+
# Exclude godoc examples from forbidigo checks.
241+
# default: true
218242
exclude_godoc_examples: false
219243

220244
funlen:
@@ -228,25 +252,34 @@ linters-settings:
228252
local-prefixes: github.com/org/project
229253

230254
gocognit:
231-
# minimal code complexity to report, 30 by default (but we recommend 10-20)
255+
# Minimal code complexity to report
256+
# default: 30, (but we recommended 10-20)
232257
min-complexity: 10
233258

234259
goconst:
235-
# minimal length of string constant, 3 by default
260+
# Minimal length of string constant
261+
# default: 3
236262
min-len: 3
237-
# minimum occurrences of constant string count to trigger issue, 3 by default
263+
# Minimum occurrences of constant string count to trigger issue
264+
# default: 3
238265
min-occurrences: 3
239-
# ignore test files, false by default
266+
# Ignore test files
267+
# default: false
240268
ignore-tests: false
241-
# look for existing constants matching the values, true by default
269+
# Look for existing constants matching the values
270+
# default: true
242271
match-constant: true
243-
# search also for duplicated numbers, false by default
272+
# Search also for duplicated numbers.
273+
# default: false
244274
numbers: false
245-
# minimum value, only works with goconst.numbers, 3 by default
275+
# Minimum value, only works with goconst.numbers
276+
# default: 3
246277
min: 3
247-
# maximum value, only works with goconst.numbers, 3 by default
278+
# Maximum value, only works with goconst.numbers
279+
# default: 3
248280
max: 3
249-
# ignore when constant is not used as function argument, true by default
281+
# Ignore when constant is not used as function argument
282+
# default: true
250283
ignore-calls: true
251284

252285
gocritic:
@@ -468,6 +501,12 @@ linters-settings:
468501
# reason: "testing if blocked version constraint works." # Reason why the version constraint exists. (Optional)
469502
local_replace_directives: false # Set to true to raise lint issues for packages that are loaded from a local path via replace directive
470503

504+
gosimple:
505+
# Select the Go version to target. The default is '1.13'.
506+
go: "1.15"
507+
# https://staticcheck.io/docs/options#checks
508+
checks: [ "all" ]
509+
471510
gosec:
472511
# To select a subset of rules to run.
473512
# Available rules: https://github.com/securego/gosec#available-rules
@@ -498,12 +537,6 @@ linters-settings:
498537
per_char_threshold: "3.0"
499538
truncate: "32"
500539

501-
gosimple:
502-
# Select the Go version to target. The default is '1.13'.
503-
go: "1.15"
504-
# https://staticcheck.io/docs/options#checks
505-
checks: [ "all" ]
506-
507540
govet:
508541
# report about shadowed variables
509542
check-shadowing: true
@@ -526,26 +559,6 @@ linters-settings:
526559
- shadow
527560
disable-all: false
528561

529-
depguard:
530-
list-type: denylist
531-
include-go-root: false
532-
packages:
533-
- github.com/sirupsen/logrus
534-
packages-with-error-message:
535-
# specify an error message to output when a denied package is used
536-
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
537-
# create additional guards that follow the same configuration pattern
538-
# results from all guards are aggregated together
539-
additional-guards:
540-
- list-type: denylist
541-
include-go-root: false
542-
packages:
543-
- github.com/stretchr/testify
544-
# specify rules by which the linter ignores certain files for consideration
545-
ignore-file-rules:
546-
- "**/*_test.go"
547-
- "**/mock/**/*.go"
548-
549562
ifshort:
550563
# Maximum length of variable declaration measured in number of lines, after which linter won't suggest using short syntax.
551564
# Has higher priority than max-decl-chars.
@@ -591,7 +604,6 @@ linters-settings:
591604
# You can specify idiomatic endings for interface
592605
- (or|er)$
593606

594-
# Reject patterns
595607
reject:
596608
- github.com\/user\/package\/v4\.Type
597609

@@ -668,30 +680,26 @@ linters-settings:
668680
range-loops: true # Report preallocation suggestions on range loops, true by default
669681
for-loops: false # Report preallocation suggestions on for loops, false by default
670682

671-
promlinter:
672-
# Promlinter cannot infer all metrics name in static analysis.
673-
# Enable strict mode will also include the errors caused by failing to parse the args.
674-
strict: false
675-
# Please refer to https://github.com/yeya24/promlinter#usage for detailed usage.
676-
disabled-linters:
677-
# - "Help"
678-
# - "MetricUnits"
679-
# - "Counter"
680-
# - "HistogramSummaryReserved"
681-
# - "MetricTypeInName"
682-
# - "ReservedChars"
683-
# - "CamelCase"
684-
# - "lintUnitAbbreviations"
685-
686683
predeclared:
687684
# comma-separated list of predeclared identifiers to not report on
688685
ignore: ""
689686
# include method names and field names (i.e., qualified names) in checks
690687
q: false
691688

692-
rowserrcheck:
693-
packages:
694-
- github.com/jmoiron/sqlx
689+
promlinter:
690+
# Promlinter cannot infer all metrics name in static analysis.
691+
# Enable strict mode will also include the errors caused by failing to parse the args.
692+
strict: false
693+
# Please refer to https://github.com/yeya24/promlinter#usage for detailed usage.
694+
disabled-linters:
695+
- "Help"
696+
- "MetricUnits"
697+
- "Counter"
698+
- "HistogramSummaryReserved"
699+
- "MetricTypeInName"
700+
- "ReservedChars"
701+
- "CamelCase"
702+
- "UnitAbbreviations"
695703

696704
revive:
697705
# see https://github.com/mgechev/revive#available-rules for details.
@@ -996,6 +1004,10 @@ linters-settings:
9961004
severity: warning
9971005
disable: false
9981006

1007+
rowserrcheck:
1008+
packages:
1009+
- github.com/jmoiron/sqlx
1010+
9991011
staticcheck:
10001012
# Select the Go version to target. The default is '1.13'.
10011013
go: "1.15"
@@ -1030,6 +1042,11 @@ linters-settings:
10301042
avro: snake
10311043
mapstructure: kebab
10321044

1045+
tenv:
1046+
# The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
1047+
# By default, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
1048+
all: false
1049+
10331050
testpackage:
10341051
# regexp pattern to skip files
10351052
skip-regexp: (export|internal)_test\.go
@@ -1050,10 +1067,6 @@ linters-settings:
10501067
name: true
10511068
begin: true
10521069

1053-
tenv:
1054-
# The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
1055-
# By default, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
1056-
all: false
10571070

10581071
unparam:
10591072
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
@@ -1062,9 +1075,9 @@ linters-settings:
10621075
# with golangci-lint call it on a directory with the changed file.
10631076
check-exported: false
10641077

1065-
unused:
1066-
# Select the Go version to target. The default is '1.13'.
1067-
go: "1.15"
1078+
varcheck:
1079+
# Check usage of exported fields and variables.
1080+
exported-fields: true
10681081

10691082
varnamelen:
10701083
# The longest distance, in source lines, that is being considered a "small scope." (defaults to 5)

0 commit comments

Comments
 (0)