forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmigrate_formatters.go
79 lines (65 loc) · 2.17 KB
/
migrate_formatters.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package migrate
import (
"slices"
"strings"
"github.com/golangci/golangci-lint/pkg/commands/internal/migrate/ptr"
"github.com/golangci/golangci-lint/pkg/commands/internal/migrate/versionone"
"github.com/golangci/golangci-lint/pkg/commands/internal/migrate/versiontwo"
)
func toFormatters(old *versionone.Config) versiontwo.Formatters {
enable, _ := ProcessEffectiveLinters(old.Linters)
formatterNames := onlyFormatterNames(enable)
var paths []string
if len(formatterNames) != 0 {
paths = slices.Concat(old.Issues.ExcludeFiles, old.Issues.ExcludeDirs)
}
return versiontwo.Formatters{
Enable: formatterNames,
Settings: versiontwo.FormatterSettings{
Gci: toGciSettings(old.LintersSettings.Gci),
GoFmt: toGoFmtSettings(old.LintersSettings.GoFmt),
GoFumpt: toGoFumptSettings(old.LintersSettings.GoFumpt),
GoImports: toGoImportsSettings(old.LintersSettings.GoImports),
},
Exclusions: versiontwo.FormatterExclusions{
Generated: toExclusionGenerated(old.Issues.ExcludeGenerated),
Paths: paths,
},
}
}
func toGciSettings(old versionone.GciSettings) versiontwo.GciSettings {
return versiontwo.GciSettings{
Sections: old.Sections,
NoInlineComments: old.NoInlineComments,
NoPrefixComments: old.NoPrefixComments,
CustomOrder: old.CustomOrder,
NoLexOrder: old.CustomOrder,
}
}
func toGoFmtSettings(old versionone.GoFmtSettings) versiontwo.GoFmtSettings {
settings := versiontwo.GoFmtSettings{
Simplify: old.Simplify,
}
for _, rule := range old.RewriteRules {
settings.RewriteRules = append(settings.RewriteRules, versiontwo.GoFmtRewriteRule{
Pattern: rule.Pattern,
Replacement: rule.Replacement,
})
}
return settings
}
func toGoFumptSettings(old versionone.GoFumptSettings) versiontwo.GoFumptSettings {
return versiontwo.GoFumptSettings{
ModulePath: old.ModulePath,
ExtraRules: old.ExtraRules,
}
}
func toGoImportsSettings(old versionone.GoImportsSettings) versiontwo.GoImportsSettings {
var localPrefixes []string
if ptr.Deref(old.LocalPrefixes) != "" {
localPrefixes = strings.Split(ptr.Deref(old.LocalPrefixes), ",")
}
return versiontwo.GoImportsSettings{
LocalPrefixes: localPrefixes,
}
}