docs: improve goconst documentation. (#2128)

This commit is contained in:
Ludovic Fernandez 2021-07-27 11:13:33 +02:00 committed by GitHub
parent 511efdb3cf
commit 245257b8fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 9 deletions

View File

@ -179,8 +179,20 @@ linters-settings:
goconst:
# minimal length of string constant, 3 by default
min-len: 3
# minimal occurrences count to trigger, 3 by default
# minimum occurrences of constant string count to trigger issue, 3 by default
min-occurrences: 3
# ignore test files, false by default
ignore-tests: false
# look for existing constants matching the values, true by default
match-constant: true
# search also for duplicated numbers, false by default
numbers: false
# minimum value, only works with goconst.numbers, 3 by default
min: 3
# maximum value, only works with goconst.numbers, 3 by default
max: 3
# ignore when constant is not used as function argument, true by default
ignore-calls: true
gocritic:
# Which checks should be enabled; can't be combined with 'disabled-checks';

View File

@ -46,19 +46,23 @@ func NewGoconst() *goanalysis.Linter {
}
func checkConstants(pass *analysis.Pass, lintCtx *linter.Context) ([]goanalysis.Issue, error) {
settings := lintCtx.Settings().Goconst
cfg := goconstAPI.Config{
IgnoreTests: lintCtx.Settings().Goconst.IgnoreTests,
MatchWithConstants: lintCtx.Settings().Goconst.MatchWithConstants,
MinStringLength: lintCtx.Settings().Goconst.MinStringLen,
MinOccurrences: lintCtx.Settings().Goconst.MinOccurrencesCount,
ParseNumbers: lintCtx.Settings().Goconst.ParseNumbers,
NumberMin: lintCtx.Settings().Goconst.NumberMin,
NumberMax: lintCtx.Settings().Goconst.NumberMax,
IgnoreTests: settings.IgnoreTests,
MatchWithConstants: settings.MatchWithConstants,
MinStringLength: settings.MinStringLen,
MinOccurrences: settings.MinOccurrencesCount,
ParseNumbers: settings.ParseNumbers,
NumberMin: settings.NumberMin,
NumberMax: settings.NumberMax,
ExcludeTypes: map[goconstAPI.Type]bool{},
}
if lintCtx.Settings().Goconst.IgnoreCalls {
if settings.IgnoreCalls {
cfg.ExcludeTypes[goconstAPI.Call] = true
}
goconstIssues, err := goconstAPI.Run(pass.Files, pass.Fset, &cfg)
if err != nil {
return nil, err