-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.go
66 lines (53 loc) · 1.35 KB
/
plugin.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
package plugin
import (
"fillmore-labs.com/zerolint/pkg/analyzer"
"fillmore-labs.com/zerolint/pkg/visitor"
"github.com/golangci/plugin-module-register/register"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/inspect"
)
const Name = "zerolint"
func init() { //nolint:gochecknoinits
register.Plugin(Name, New)
}
type Settings struct {
Excluded []string `json:"excluded"`
Basic bool `json:"basic"`
}
func New(settings any) (register.LinterPlugin, error) { //nolint:ireturn
s, err := register.DecodeSettings[Settings](settings)
if err != nil {
return nil, err
}
return Plugin{settings: s}, nil
}
type Plugin struct {
settings Settings
}
func (p Plugin) BuildAnalyzers() ([]*analysis.Analyzer, error) {
run := func(pass *analysis.Pass) (any, error) {
excludes := make(map[string]struct{}, len(p.settings.Excluded))
for _, ex := range p.settings.Excluded {
excludes[ex] = struct{}{}
}
v := visitor.Run{
Visitor: visitor.Visitor{
Pass: pass,
Excludes: excludes,
},
Basic: p.settings.Basic,
}
v.Run()
return any(nil), nil
}
analyzer := &analysis.Analyzer{
Name: Name,
Doc: analyzer.Doc,
Run: run,
Requires: []*analysis.Analyzer{inspect.Analyzer},
}
return []*analysis.Analyzer{analyzer}, nil
}
func (Plugin) GetLoadMode() string {
return register.LoadModeTypesInfo
}