Skip to content

Commit c3a681f

Browse files
butuzovSeigeC
authored andcommitted
docs: improve linters settings section (golangci#2499)
1 parent f842147 commit c3a681f

File tree

1 file changed

+81
-48
lines changed

1 file changed

+81
-48
lines changed

.golangci.example.yml

Lines changed: 81 additions & 48 deletions
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
@@ -596,7 +629,6 @@ linters-settings:
596629
# You can specify idiomatic endings for interface
597630
- (or|er)$
598631

599-
# Reject patterns
600632
reject:
601633
- github.com\/user\/package\/v4\.Type
602634

@@ -673,30 +705,26 @@ linters-settings:
673705
range-loops: true # Report preallocation suggestions on range loops, true by default
674706
for-loops: false # Report preallocation suggestions on for loops, false by default
675707

676-
promlinter:
677-
# Promlinter cannot infer all metrics name in static analysis.
678-
# Enable strict mode will also include the errors caused by failing to parse the args.
679-
strict: false
680-
# Please refer to https://github.com/yeya24/promlinter#usage for detailed usage.
681-
disabled-linters:
682-
# - "Help"
683-
# - "MetricUnits"
684-
# - "Counter"
685-
# - "HistogramSummaryReserved"
686-
# - "MetricTypeInName"
687-
# - "ReservedChars"
688-
# - "CamelCase"
689-
# - "lintUnitAbbreviations"
690-
691708
predeclared:
692709
# comma-separated list of predeclared identifiers to not report on
693710
ignore: ""
694711
# include method names and field names (i.e., qualified names) in checks
695712
q: false
696713

697-
rowserrcheck:
698-
packages:
699-
- github.com/jmoiron/sqlx
714+
promlinter:
715+
# Promlinter cannot infer all metrics name in static analysis.
716+
# Enable strict mode will also include the errors caused by failing to parse the args.
717+
strict: false
718+
# Please refer to https://github.com/yeya24/promlinter#usage for detailed usage.
719+
disabled-linters:
720+
- "Help"
721+
- "MetricUnits"
722+
- "Counter"
723+
- "HistogramSummaryReserved"
724+
- "MetricTypeInName"
725+
- "ReservedChars"
726+
- "CamelCase"
727+
- "UnitAbbreviations"
700728

701729
revive:
702730
# see https://github.com/mgechev/revive#available-rules for details.
@@ -1001,6 +1029,10 @@ linters-settings:
10011029
severity: warning
10021030
disable: false
10031031

1032+
rowserrcheck:
1033+
packages:
1034+
- github.com/jmoiron/sqlx
1035+
10041036
staticcheck:
10051037
# Select the Go version to target. The default is '1.13'.
10061038
go: "1.15"
@@ -1035,6 +1067,11 @@ linters-settings:
10351067
avro: snake
10361068
mapstructure: kebab
10371069

1070+
tenv:
1071+
# The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
1072+
# By default, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
1073+
all: false
1074+
10381075
testpackage:
10391076
# regexp pattern to skip files
10401077
skip-regexp: (export|internal)_test\.go
@@ -1055,10 +1092,6 @@ linters-settings:
10551092
name: true
10561093
begin: true
10571094

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

10631096
unparam:
10641097
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
@@ -1067,9 +1100,9 @@ linters-settings:
10671100
# with golangci-lint call it on a directory with the changed file.
10681101
check-exported: false
10691102

1070-
unused:
1071-
# Select the Go version to target. The default is '1.13'.
1072-
go: "1.15"
1103+
varcheck:
1104+
# Check usage of exported fields and variables.
1105+
exported-fields: true
10731106

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

0 commit comments

Comments
 (0)