-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgolangci_plugin.go
52 lines (41 loc) · 935 Bytes
/
golangci_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
package mockguard
import (
"golang.org/x/tools/go/analysis"
"github.com/golangci/plugin-module-register/register"
)
func init() {
RegisterPlugin()
}
func RegisterPlugin() {
// https://golangci-lint.run/plugins/module-plugins/
register.Plugin("mockguard", newPlugin)
}
func newPlugin(conf any) (register.LinterPlugin, error) {
s, err := register.DecodeSettings[settings](conf)
if err != nil {
return nil, err
}
return &plugin{settings: &s}, nil
}
type settings struct {
FileName string
Content string
}
type plugin struct {
settings *settings
}
func (p *plugin) BuildAnalyzers() ([]*analysis.Analyzer, error) {
if p.settings.FileName != "" {
FileName = p.settings.FileName
}
if p.settings.Content != "" {
Content = p.settings.Content
}
return []*analysis.Analyzer{
Analyzer,
}, nil
}
func (p *plugin) GetLoadMode() string {
return register.LoadModeSyntax
}
var _ register.LinterPlugin = &plugin{}