diff --git a/.golangci.example.yml b/.golangci.example.yml index 7cdb607310d4..6e0bfeabc5df 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -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'; diff --git a/pkg/golinters/goconst.go b/pkg/golinters/goconst.go index 0801ee15d8a8..bdec4e10b079 100644 --- a/pkg/golinters/goconst.go +++ b/pkg/golinters/goconst.go @@ -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