docs: add a section about default exclusions (#3117)

This commit is contained in:
Ludovic Fernandez 2022-08-20 19:05:13 +02:00 committed by GitHub
parent 2b4c9ab4fc
commit d286cb910c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 6 deletions

View File

@ -2097,7 +2097,7 @@ issues:
# it can be disabled by `exclude-use-default: false`.
# To list all excluded by default patterns execute `golangci-lint run --help`
#
# Default: []
# Default: https://golangci-lint.run/usage/false-positives/#default-exclusions
exclude:
- abcdef
@ -2139,9 +2139,24 @@ issues:
exclude-case-sensitive: false
# The list of ids of default excludes to include or disable.
# https://golangci-lint.run/usage/false-positives/#default-exclusions
# Default: []
include:
- EXC0002 # disable excluding of issues about comments from golint.
- EXC0001
- EXC0002
- EXC0003
- EXC0004
- EXC0005
- EXC0006
- EXC0007
- EXC0008
- EXC0009
- EXC0010
- EXC0011
- EXC0012
- EXC0013
- EXC0014
- EXC0015
# Maximum issues count per one linter.
# Set to 0 to disable.

View File

@ -14,7 +14,7 @@ conduct](https://github.com/golangci/golangci-lint/blob/master/CODE_OF_CONDUCT.m
Prerequisites:
- `make`
- [Go 1.13+](https://golang.org/doc/install)
- [Go](https://golang.org/doc/install)
Fork and clone [golangci-lint](https://github.com/golangci/golangci-lint) repository.

View File

@ -142,3 +142,10 @@ func someLegacyFunction() *string {
You can see more examples of using `//nolint` in [our tests](https://github.com/golangci/golangci-lint/tree/master/pkg/result/processors/testdata) for it.
Use `//nolint` instead of `// nolint` because machine-readable comments should have no space by Go convention.
## Default Exclusions
Some exclusions are considered as common, to help golangci-lint users those common exclusions are used as default exclusions.
If you don't want to use it you can set `issues.exclude-use-default` to `false`.
{.DefaultExclusions}

View File

@ -188,15 +188,16 @@ func GetDefaultExcludePatternsStrings() []string {
return ret
}
// TODO(ldez): this behavior must be changed in v2, because this is confusing.
func GetExcludePatterns(include []string) []ExcludePattern {
includeMap := make(map[string]bool, len(include))
includeMap := make(map[string]struct{}, len(include))
for _, inc := range include {
includeMap[inc] = true
includeMap[inc] = struct{}{}
}
var ret []ExcludePattern
for _, p := range DefaultExcludePatterns {
if !includeMap[p.ID] {
if _, ok := includeMap[p.ID]; !ok {
ret = append(ret, p)
}
}

View File

@ -212,6 +212,7 @@ func buildTemplateContext() (map[string]string, error) {
"LintersCommandOutputDisabledOnly": string(lintersOutParts[1]),
"EnabledByDefaultLinters": getLintersListMarkdown(true),
"DisabledByDefaultLinters": getLintersListMarkdown(false),
"DefaultExclusions": getDefaultExclusions(),
"ThanksList": getThanksList(),
"RunHelpText": string(shortHelp),
"ChangeLog": string(changeLog),
@ -219,6 +220,21 @@ func buildTemplateContext() (map[string]string, error) {
}, nil
}
func getDefaultExclusions() string {
bufferString := bytes.NewBufferString("")
for _, pattern := range config.DefaultExcludePatterns {
_, _ = fmt.Fprintln(bufferString)
_, _ = fmt.Fprintf(bufferString, "### %s\n", pattern.ID)
_, _ = fmt.Fprintln(bufferString)
_, _ = fmt.Fprintf(bufferString, "- linter: `%s`\n", pattern.Linter)
_, _ = fmt.Fprintf(bufferString, "- pattern: `%s`\n", strings.ReplaceAll(pattern.Pattern, "`", "`"))
_, _ = fmt.Fprintf(bufferString, "- why: %s\n", pattern.Why)
}
return bufferString.String()
}
func getLintersListMarkdown(enabled bool) string {
var neededLcs []*linter.Config
lcs := lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs()