Skip to content

docs: improve goconst documentation. #2128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
20 changes: 12 additions & 8 deletions pkg/golinters/goconst.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down