docs: improve goconst documentation. (#2128)
This commit is contained in:
parent
511efdb3cf
commit
245257b8fb
@ -179,8 +179,20 @@ linters-settings:
|
|||||||
goconst:
|
goconst:
|
||||||
# minimal length of string constant, 3 by default
|
# minimal length of string constant, 3 by default
|
||||||
min-len: 3
|
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
|
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:
|
gocritic:
|
||||||
# Which checks should be enabled; can't be combined with 'disabled-checks';
|
# Which checks should be enabled; can't be combined with 'disabled-checks';
|
||||||
|
@ -46,19 +46,23 @@ func NewGoconst() *goanalysis.Linter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkConstants(pass *analysis.Pass, lintCtx *linter.Context) ([]goanalysis.Issue, error) {
|
func checkConstants(pass *analysis.Pass, lintCtx *linter.Context) ([]goanalysis.Issue, error) {
|
||||||
|
settings := lintCtx.Settings().Goconst
|
||||||
|
|
||||||
cfg := goconstAPI.Config{
|
cfg := goconstAPI.Config{
|
||||||
IgnoreTests: lintCtx.Settings().Goconst.IgnoreTests,
|
IgnoreTests: settings.IgnoreTests,
|
||||||
MatchWithConstants: lintCtx.Settings().Goconst.MatchWithConstants,
|
MatchWithConstants: settings.MatchWithConstants,
|
||||||
MinStringLength: lintCtx.Settings().Goconst.MinStringLen,
|
MinStringLength: settings.MinStringLen,
|
||||||
MinOccurrences: lintCtx.Settings().Goconst.MinOccurrencesCount,
|
MinOccurrences: settings.MinOccurrencesCount,
|
||||||
ParseNumbers: lintCtx.Settings().Goconst.ParseNumbers,
|
ParseNumbers: settings.ParseNumbers,
|
||||||
NumberMin: lintCtx.Settings().Goconst.NumberMin,
|
NumberMin: settings.NumberMin,
|
||||||
NumberMax: lintCtx.Settings().Goconst.NumberMax,
|
NumberMax: settings.NumberMax,
|
||||||
ExcludeTypes: map[goconstAPI.Type]bool{},
|
ExcludeTypes: map[goconstAPI.Type]bool{},
|
||||||
}
|
}
|
||||||
if lintCtx.Settings().Goconst.IgnoreCalls {
|
|
||||||
|
if settings.IgnoreCalls {
|
||||||
cfg.ExcludeTypes[goconstAPI.Call] = true
|
cfg.ExcludeTypes[goconstAPI.Call] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
goconstIssues, err := goconstAPI.Run(pass.Files, pass.Fset, &cfg)
|
goconstIssues, err := goconstAPI.Run(pass.Files, pass.Fset, &cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user