Skip to content

Commit 0a4585f

Browse files
committed
chore: duplicate linter structure to avoid side-effect of the serialization
1 parent 4370aa6 commit 0a4585f

File tree

4 files changed

+70
-22
lines changed

4 files changed

+70
-22
lines changed

Diff for: pkg/lint/linter/config.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,28 @@ const (
2828
const LastLinter = "nolintlint"
2929

3030
type Deprecation struct {
31-
Since string `json:"since,omitempty"`
32-
Message string `json:"message,omitempty"`
33-
Replacement string `json:"replacement,omitempty"`
31+
Since string
32+
Message string
33+
Replacement string
3434
}
3535

3636
type Config struct {
37-
Linter Linter `json:"-"`
38-
EnabledByDefault bool `json:"enabledByDefault,omitempty"`
37+
Linter Linter
38+
EnabledByDefault bool
3939

40-
LoadMode packages.LoadMode `json:"loadMode,omitempty"`
40+
LoadMode packages.LoadMode
4141

42-
InPresets []string `json:"inPresets,omitempty"`
43-
AlternativeNames []string `json:"alternativeNames,omitempty"`
42+
InPresets []string
43+
AlternativeNames []string
4444

45-
OriginalURL string `json:"originalURL,omitempty"` // URL of original (not forked) repo, needed for autogenerated README
46-
Internal bool `json:"internal"` // Internal linters cannot be disabled (ex: typecheck).
47-
CanAutoFix bool `json:"canAutoFix,omitempty"`
48-
IsSlow bool `json:"isSlow"`
49-
DoesChangeTypes bool `json:"doesChangeTypes,omitempty"`
45+
OriginalURL string // URL of original (not forked) repo, needed for autogenerated README
46+
Internal bool // Internal linters cannot be disabled (ex: typecheck).
47+
CanAutoFix bool
48+
IsSlow bool
49+
DoesChangeTypes bool
5050

51-
Since string `json:"since,omitempty"`
52-
Deprecation *Deprecation `json:"deprecation,omitempty"`
51+
Since string
52+
Deprecation *Deprecation
5353
}
5454

5555
func (lc *Config) WithEnabledByDefault() *Config {

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

+24-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,30 @@ func main() {
1919

2020
var wraps []types.LinterWrapper
2121
for _, l := range linters {
22-
wraps = append(wraps, types.LinterWrapper{Config: l, Name: l.Linter.Name(), Desc: l.Linter.Desc()})
22+
wrapper := types.LinterWrapper{
23+
Name: l.Linter.Name(),
24+
Desc: l.Linter.Desc(),
25+
EnabledByDefault: l.EnabledByDefault,
26+
LoadMode: l.LoadMode,
27+
InPresets: l.InPresets,
28+
AlternativeNames: l.AlternativeNames,
29+
OriginalURL: l.OriginalURL,
30+
Internal: l.Internal,
31+
CanAutoFix: l.CanAutoFix,
32+
IsSlow: l.IsSlow,
33+
DoesChangeTypes: l.DoesChangeTypes,
34+
Since: l.Since,
35+
}
36+
37+
if l.Deprecation != nil {
38+
wrapper.Deprecation = &types.Deprecation{
39+
Since: l.Deprecation.Since,
40+
Message: l.Deprecation.Message,
41+
Replacement: l.Deprecation.Replacement,
42+
}
43+
}
44+
45+
wraps = append(wraps, wrapper)
2346
}
2447

2548
err := saveToJSONFile(filepath.Join("assets", "linters-info.json"), wraps)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func getName(lc *types.LinterWrapper) string {
6868
name = fmt.Sprintf("%s [%s](#%s)", name, spanWithID(listItemPrefix+lc.Name, "Configuration", "⚙️"), lc.Name)
6969
}
7070

71-
if !lc.IsDeprecated() {
71+
if lc.Deprecation == nil {
7272
return name
7373
}
7474

@@ -89,7 +89,7 @@ func check(b bool, title string) string {
8989

9090
func getDesc(lc *types.LinterWrapper) string {
9191
desc := lc.Desc
92-
if lc.IsDeprecated() {
92+
if lc.Deprecation == nil {
9393
desc = lc.Deprecation.Message
9494
if lc.Deprecation.Replacement != "" {
9595
desc += fmt.Sprintf(" Replaced by %s.", lc.Deprecation.Replacement)

Diff for: scripts/website/types/types.go

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,41 @@
11
package types
22

3-
import "github.com/golangci/golangci-lint/pkg/lint/linter"
3+
import (
4+
"golang.org/x/tools/go/packages"
5+
)
46

57
type CLIHelp struct {
68
Enable string `json:"enable"`
79
Disable string `json:"disable"`
810
Help string `json:"help"`
911
}
1012

13+
type Deprecation struct {
14+
Since string `json:"since,omitempty"`
15+
Message string `json:"message,omitempty"`
16+
Replacement string `json:"replacement,omitempty"`
17+
}
18+
19+
// LinterWrapper same fields but with struct tags.
20+
// The field Name and Desc are added to have the information about the linter.
21+
// The field Linter is removed (not serializable).
1122
type LinterWrapper struct {
12-
*linter.Config
23+
Name string `json:"name"` // From linter.
24+
Desc string `json:"desc"` // From linter.
25+
26+
EnabledByDefault bool `json:"enabledByDefault,omitempty"`
27+
28+
LoadMode packages.LoadMode `json:"loadMode,omitempty"`
29+
30+
InPresets []string `json:"inPresets,omitempty"`
31+
AlternativeNames []string `json:"alternativeNames,omitempty"`
32+
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).
35+
CanAutoFix bool `json:"canAutoFix,omitempty"`
36+
IsSlow bool `json:"isSlow"`
37+
DoesChangeTypes bool `json:"doesChangeTypes,omitempty"`
1338

14-
Name string `json:"name"`
15-
Desc string `json:"desc"`
39+
Since string `json:"since,omitempty"`
40+
Deprecation *Deprecation `json:"deprecation,omitempty"`
1641
}

0 commit comments

Comments
 (0)