Skip to content

Commit 12a70d5

Browse files
committed
chore: duplicate exclusiion structure to avoid side-effect of the serialization
1 parent fd43ac5 commit 12a70d5

File tree

4 files changed

+45
-19
lines changed

4 files changed

+45
-19
lines changed

pkg/config/issues.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ func validateOptionalRegex(value string) error {
206206
}
207207

208208
type ExcludePattern struct {
209-
ID string `json:"id,omitempty"`
210-
Pattern string `json:"pattern,omitempty"`
211-
Linter string `json:"linter,omitempty"`
212-
Why string `json:"why,omitempty"`
209+
ID string
210+
Pattern string
211+
Linter string
212+
Why string
213213
}
214214

215215
func GetDefaultExcludePatternsStrings() []string {

scripts/website/dump_info/main.go

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ import (
1515
)
1616

1717
func main() {
18+
err := saveLinters()
19+
if err != nil {
20+
log.Fatalf("Save linters: %v", err)
21+
}
22+
23+
err = saveDefaultExclusions()
24+
if err != nil {
25+
log.Fatalf("Save default exclusions: %v", err)
26+
}
27+
28+
err = saveCLIHelp(filepath.Join("assets", "cli-help.json"))
29+
if err != nil {
30+
log.Fatalf("Save CLI help: %v", err)
31+
}
32+
}
33+
34+
func saveLinters() error {
1835
linters := lintersdb.NewLinterBuilder().Build(config.NewDefault())
1936

2037
var wraps []types.LinterWrapper
@@ -45,20 +62,22 @@ func main() {
4562
wraps = append(wraps, wrapper)
4663
}
4764

48-
err := saveToJSONFile(filepath.Join("assets", "linters-info.json"), wraps)
49-
if err != nil {
50-
log.Fatalf("Save linters: %v", err)
51-
}
65+
return saveToJSONFile(filepath.Join("assets", "linters-info.json"), wraps)
66+
}
5267

53-
err = saveToJSONFile(filepath.Join("assets", "default-exclusions.json"), config.DefaultExcludePatterns)
54-
if err != nil {
55-
log.Fatalf("Save default exclusions: %v", err)
56-
}
68+
func saveDefaultExclusions() error {
69+
var excludePatterns []types.ExcludePattern
5770

58-
err = saveCLIHelp(filepath.Join("assets", "cli-help.json"))
59-
if err != nil {
60-
log.Fatalf("Save CLI help: %v", err)
71+
for _, pattern := range config.DefaultExcludePatterns {
72+
excludePatterns = append(excludePatterns, types.ExcludePattern{
73+
ID: pattern.ID,
74+
Pattern: pattern.Pattern,
75+
Linter: pattern.Linter,
76+
Why: pattern.Why,
77+
})
6178
}
79+
80+
return saveToJSONFile(filepath.Join("assets", "default-exclusions.json"), excludePatterns)
6281
}
6382

6483
func saveCLIHelp(dst string) error {

scripts/website/expand_templates/exclusions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"path/filepath"
77
"strings"
88

9-
"github.com/golangci/golangci-lint/pkg/config"
9+
"github.com/golangci/golangci-lint/scripts/website/types"
1010
)
1111

1212
func getDefaultExclusions() string {
13-
defaultExcludePatterns, err := readJSONFile[[]config.ExcludePattern](filepath.Join("assets", "default-exclusions.json"))
13+
defaultExcludePatterns, err := readJSONFile[[]types.ExcludePattern](filepath.Join("assets", "default-exclusions.json"))
1414
if err != nil {
1515
panic(err)
1616
}

scripts/website/types/types.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ type CLIHelp struct {
1010
Help string `json:"help"`
1111
}
1212

13+
type ExcludePattern struct {
14+
ID string `json:"id,omitempty"`
15+
Pattern string `json:"pattern,omitempty"`
16+
Linter string `json:"linter,omitempty"`
17+
Why string `json:"why,omitempty"`
18+
}
19+
1320
type Deprecation struct {
1421
Since string `json:"since,omitempty"`
1522
Message string `json:"message,omitempty"`
@@ -30,8 +37,8 @@ type LinterWrapper struct {
3037
InPresets []string `json:"inPresets,omitempty"`
3138
AlternativeNames []string `json:"alternativeNames,omitempty"`
3239

33-
OriginalURL string `json:"originalURL,omitempty"` // URL of original (not forked) repo, needed for autogenerated README
34-
Internal bool `json:"internal"` // Internal linters cannot be disabled (ex: typecheck).
40+
OriginalURL string `json:"originalURL,omitempty"`
41+
Internal bool `json:"internal"`
3542
CanAutoFix bool `json:"canAutoFix,omitempty"`
3643
IsSlow bool `json:"isSlow"`
3744
DoesChangeTypes bool `json:"doesChangeTypes,omitempty"`

0 commit comments

Comments
 (0)