Skip to content

Commit ee3af9f

Browse files
committed
docs: replace default exclusions by exclusion presets
1 parent c704960 commit ee3af9f

File tree

11 files changed

+156
-149
lines changed

11 files changed

+156
-149
lines changed

Diff for: assets/cli-help.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: assets/default-exclusions.json

-92
This file was deleted.

Diff for: assets/exclusion-presets.json

+88
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: assets/linters-info.json

+13-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: docs/src/docs/usage/false-positives.mdx

+3-4
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,11 @@ You can see more examples of using `//nolint` in [our tests](https://github.com/
169169

170170
Use `//nolint` instead of `// nolint` because machine-readable comments should have no space by Go convention.
171171

172-
## Default Exclusions
172+
## Exclusion Presets
173173

174-
Some exclusions are considered as common, to help golangci-lint users those common exclusions are used as default exclusions.
174+
Some exclusions are considered as common, to help golangci-lint users those common exclusions are provided through presets.
175175

176-
If you don't want to use it you can set `issues.exclude-use-default` to `false`.
177-
{.DefaultExclusions}
176+
{.ExclusionPresets}
178177

179178
### Default Directory Exclusions
180179

Diff for: pkg/lint/lintersdb/builder_linter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
382382
WithURL("https://github.com/mvdan/gofumpt"),
383383

384384
linter.NewConfig(golines.New(&cfg.LintersSettings.GoLines)).
385-
WithSince("v1.64.0").
385+
WithSince("v2.0.0").
386386
WithPresets(linter.PresetFormatting).
387387
WithAutoFix().
388388
WithURL("https://github.com/segmentio/golines"),

Diff for: pkg/result/processors/exclusion_presets.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package processors
22

33
import "github.com/golangci/golangci-lint/pkg/config"
44

5-
var linterExclusionPresets = map[string][]config.ExcludeRule{
5+
var LinterExclusionPresets = map[string][]config.ExcludeRule{
66
config.ExclusionPresetComments: {
77
{
88
// Annoying issue about not having a comment. The rare codebase has such comments.
@@ -129,7 +129,7 @@ func getLinterExclusionPresets(names []string) []config.ExcludeRule {
129129
var rules []config.ExcludeRule
130130

131131
for _, name := range names {
132-
if p, ok := linterExclusionPresets[name]; ok {
132+
if p, ok := LinterExclusionPresets[name]; ok {
133133
rules = append(rules, p...)
134134
}
135135
}

Diff for: scripts/website/dump_info/main.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/golangci/golangci-lint/pkg/config"
1313
"github.com/golangci/golangci-lint/pkg/lint/linter"
1414
"github.com/golangci/golangci-lint/pkg/lint/lintersdb"
15+
"github.com/golangci/golangci-lint/pkg/result/processors"
1516
"github.com/golangci/golangci-lint/scripts/website/types"
1617
)
1718

@@ -71,8 +72,21 @@ func saveLinters() error {
7172
}
7273

7374
func saveDefaultExclusions() error {
74-
// FIXME
75-
return saveToJSONFile(filepath.Join("assets", "default-exclusions.json"), nil)
75+
data := make(map[string][]types.ExcludeRule)
76+
77+
for name, rules := range processors.LinterExclusionPresets {
78+
for _, rule := range rules {
79+
data[name] = append(data[name], types.ExcludeRule{
80+
Linters: rule.Linters,
81+
Path: rule.Path,
82+
PathExcept: rule.PathExcept,
83+
Text: rule.Text,
84+
Source: rule.Source,
85+
})
86+
}
87+
}
88+
89+
return saveToJSONFile(filepath.Join("assets", "exclusion-presets.json"), data)
7690
}
7791

7892
func saveCLIHelp(dst string) error {

Diff for: scripts/website/expand_templates/exclusions.go

+24-23
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,32 @@ package main
33
import (
44
"bytes"
55
"path/filepath"
6-
"strings"
76
"text/template"
87

98
"github.com/golangci/golangci-lint/scripts/website/types"
109
)
1110

12-
const exclusionTmpl = `{{ $tick := "` + "`" + `" }}
13-
### {{ .ID }}
14-
15-
- linter: {{ $tick }}{{ .Linter }}{{ $tick }}
16-
- pattern: {{ $tick }}{{ .Pattern }}{{ $tick }}
17-
- why: {{ .Why }}
18-
`
19-
20-
func getDefaultExclusions() (string, error) {
21-
defaultExcludePatterns, err := readJSONFile[[]types.ExcludePattern](filepath.Join("assets", "default-exclusions.json"))
11+
const exclusionTmpl = `{{- $tick := "` + "`" + `" -}}
12+
{{- range $name, $rules := . }}
13+
### {{ $tick }}{{ $name }}{{ $tick }}
14+
{{ range $rule := $rules }}
15+
{{ $tick }}{{ range $linter := $rule.Linters }}{{ $linter }}{{ end }}{{ $tick }}:
16+
{{ if $rule.Path -}}
17+
- Path: {{ $tick }}{{ $rule.Path }}{{ $tick }}
18+
{{ end -}}
19+
{{ if $rule.PathExcept -}}
20+
- Path Except: {{ $tick }}{{ $rule.PathExcept }}{{ $tick }}
21+
{{ end -}}
22+
{{ if $rule.Text -}}
23+
- Text: {{ $tick }}{{ $rule.Text }}{{ $tick }}
24+
{{ end -}}
25+
{{ if $rule.Source -}}
26+
- Source: {{ $tick }}{{ $rule.Source }}{{ $tick }}
27+
{{ end -}}
28+
{{ end }}{{ end }}`
29+
30+
func getExclusionPresets() (string, error) {
31+
linterExclusionPresets, err := readJSONFile[map[string][]types.ExcludeRule](filepath.Join("assets", "exclusion-presets.json"))
2232
if err != nil {
2333
return "", err
2434
}
@@ -30,18 +40,9 @@ func getDefaultExclusions() (string, error) {
3040
return "", err
3141
}
3242

33-
for _, pattern := range defaultExcludePatterns {
34-
data := map[string]any{
35-
"ID": pattern.ID,
36-
"Linter": pattern.Linter,
37-
"Pattern": strings.ReplaceAll(pattern.Pattern, "`", "`"),
38-
"Why": pattern.Why,
39-
}
40-
41-
err := tmpl.Execute(bufferString, data)
42-
if err != nil {
43-
return "", err
44-
}
43+
err = tmpl.Execute(bufferString, linterExclusionPresets)
44+
if err != nil {
45+
return "", err
4546
}
4647

4748
return bufferString.String(), nil

Diff for: scripts/website/expand_templates/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func buildTemplateContext() (map[string]string, error) {
115115
return nil, fmt.Errorf("get the latest version: %w", err)
116116
}
117117

118-
exclusions, err := getDefaultExclusions()
118+
exclusions, err := getExclusionPresets()
119119
if err != nil {
120120
return nil, fmt.Errorf("default exclusions: %w", err)
121121
}
@@ -127,7 +127,7 @@ func buildTemplateContext() (map[string]string, error) {
127127
"LintersCommandOutputEnabledOnly": helps.Enable,
128128
"EnabledByDefaultLinters": getLintersListMarkdown(true),
129129
"DisabledByDefaultLinters": getLintersListMarkdown(false),
130-
"DefaultExclusions": exclusions,
130+
"ExclusionPresets": exclusions,
131131
"ThanksList": getThanksList(),
132132
"RunHelpText": helps.Help,
133133
"ChangeLog": string(changeLog),

0 commit comments

Comments
 (0)