docs: add a section about default exclusions (#3117)
This commit is contained in:
parent
2b4c9ab4fc
commit
d286cb910c
@ -2097,7 +2097,7 @@ issues:
|
|||||||
# it can be disabled by `exclude-use-default: false`.
|
# it can be disabled by `exclude-use-default: false`.
|
||||||
# To list all excluded by default patterns execute `golangci-lint run --help`
|
# To list all excluded by default patterns execute `golangci-lint run --help`
|
||||||
#
|
#
|
||||||
# Default: []
|
# Default: https://golangci-lint.run/usage/false-positives/#default-exclusions
|
||||||
exclude:
|
exclude:
|
||||||
- abcdef
|
- abcdef
|
||||||
|
|
||||||
@ -2139,9 +2139,24 @@ issues:
|
|||||||
exclude-case-sensitive: false
|
exclude-case-sensitive: false
|
||||||
|
|
||||||
# The list of ids of default excludes to include or disable.
|
# The list of ids of default excludes to include or disable.
|
||||||
|
# https://golangci-lint.run/usage/false-positives/#default-exclusions
|
||||||
# Default: []
|
# Default: []
|
||||||
include:
|
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.
|
# Maximum issues count per one linter.
|
||||||
# Set to 0 to disable.
|
# Set to 0 to disable.
|
||||||
|
@ -14,7 +14,7 @@ conduct](https://github.com/golangci/golangci-lint/blob/master/CODE_OF_CONDUCT.m
|
|||||||
Prerequisites:
|
Prerequisites:
|
||||||
|
|
||||||
- `make`
|
- `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.
|
Fork and clone [golangci-lint](https://github.com/golangci/golangci-lint) repository.
|
||||||
|
|
||||||
|
@ -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.
|
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.
|
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}
|
||||||
|
@ -188,15 +188,16 @@ func GetDefaultExcludePatternsStrings() []string {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(ldez): this behavior must be changed in v2, because this is confusing.
|
||||||
func GetExcludePatterns(include []string) []ExcludePattern {
|
func GetExcludePatterns(include []string) []ExcludePattern {
|
||||||
includeMap := make(map[string]bool, len(include))
|
includeMap := make(map[string]struct{}, len(include))
|
||||||
for _, inc := range include {
|
for _, inc := range include {
|
||||||
includeMap[inc] = true
|
includeMap[inc] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var ret []ExcludePattern
|
var ret []ExcludePattern
|
||||||
for _, p := range DefaultExcludePatterns {
|
for _, p := range DefaultExcludePatterns {
|
||||||
if !includeMap[p.ID] {
|
if _, ok := includeMap[p.ID]; !ok {
|
||||||
ret = append(ret, p)
|
ret = append(ret, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,6 +212,7 @@ func buildTemplateContext() (map[string]string, error) {
|
|||||||
"LintersCommandOutputDisabledOnly": string(lintersOutParts[1]),
|
"LintersCommandOutputDisabledOnly": string(lintersOutParts[1]),
|
||||||
"EnabledByDefaultLinters": getLintersListMarkdown(true),
|
"EnabledByDefaultLinters": getLintersListMarkdown(true),
|
||||||
"DisabledByDefaultLinters": getLintersListMarkdown(false),
|
"DisabledByDefaultLinters": getLintersListMarkdown(false),
|
||||||
|
"DefaultExclusions": getDefaultExclusions(),
|
||||||
"ThanksList": getThanksList(),
|
"ThanksList": getThanksList(),
|
||||||
"RunHelpText": string(shortHelp),
|
"RunHelpText": string(shortHelp),
|
||||||
"ChangeLog": string(changeLog),
|
"ChangeLog": string(changeLog),
|
||||||
@ -219,6 +220,21 @@ func buildTemplateContext() (map[string]string, error) {
|
|||||||
}, nil
|
}, 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 {
|
func getLintersListMarkdown(enabled bool) string {
|
||||||
var neededLcs []*linter.Config
|
var neededLcs []*linter.Config
|
||||||
lcs := lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs()
|
lcs := lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user