Skip to content

Commit 245257b

Browse files
authored
docs: improve goconst documentation. (#2128)
1 parent 511efdb commit 245257b

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

.golangci.example.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,20 @@ linters-settings:
179179
goconst:
180180
# minimal length of string constant, 3 by default
181181
min-len: 3
182-
# minimal occurrences count to trigger, 3 by default
182+
# minimum occurrences of constant string count to trigger issue, 3 by default
183183
min-occurrences: 3
184+
# ignore test files, false by default
185+
ignore-tests: false
186+
# look for existing constants matching the values, true by default
187+
match-constant: true
188+
# search also for duplicated numbers, false by default
189+
numbers: false
190+
# minimum value, only works with goconst.numbers, 3 by default
191+
min: 3
192+
# maximum value, only works with goconst.numbers, 3 by default
193+
max: 3
194+
# ignore when constant is not used as function argument, true by default
195+
ignore-calls: true
184196

185197
gocritic:
186198
# Which checks should be enabled; can't be combined with 'disabled-checks';

pkg/golinters/goconst.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,23 @@ func NewGoconst() *goanalysis.Linter {
4646
}
4747

4848
func checkConstants(pass *analysis.Pass, lintCtx *linter.Context) ([]goanalysis.Issue, error) {
49+
settings := lintCtx.Settings().Goconst
50+
4951
cfg := goconstAPI.Config{
50-
IgnoreTests: lintCtx.Settings().Goconst.IgnoreTests,
51-
MatchWithConstants: lintCtx.Settings().Goconst.MatchWithConstants,
52-
MinStringLength: lintCtx.Settings().Goconst.MinStringLen,
53-
MinOccurrences: lintCtx.Settings().Goconst.MinOccurrencesCount,
54-
ParseNumbers: lintCtx.Settings().Goconst.ParseNumbers,
55-
NumberMin: lintCtx.Settings().Goconst.NumberMin,
56-
NumberMax: lintCtx.Settings().Goconst.NumberMax,
52+
IgnoreTests: settings.IgnoreTests,
53+
MatchWithConstants: settings.MatchWithConstants,
54+
MinStringLength: settings.MinStringLen,
55+
MinOccurrences: settings.MinOccurrencesCount,
56+
ParseNumbers: settings.ParseNumbers,
57+
NumberMin: settings.NumberMin,
58+
NumberMax: settings.NumberMax,
5759
ExcludeTypes: map[goconstAPI.Type]bool{},
5860
}
59-
if lintCtx.Settings().Goconst.IgnoreCalls {
61+
62+
if settings.IgnoreCalls {
6063
cfg.ExcludeTypes[goconstAPI.Call] = true
6164
}
65+
6266
goconstIssues, err := goconstAPI.Run(pass.Files, pass.Fset, &cfg)
6367
if err != nil {
6468
return nil, err

0 commit comments

Comments
 (0)