-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathprotogetter.go
59 lines (48 loc) · 1.31 KB
/
protogetter.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
package golinters
import (
"sync"
"github.com/ghostiam/protogetter"
"golang.org/x/tools/go/analysis"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/result"
)
func NewProtoGetter() *goanalysis.Linter {
var mu sync.Mutex
var resIssues []goanalysis.Issue
a := protogetter.NewAnalyzer()
a.Run = func(pass *analysis.Pass) (any, error) {
pgIssues := protogetter.Run(pass, protogetter.GolangciLintMode)
issues := make([]goanalysis.Issue, len(pgIssues))
for i, issue := range pgIssues {
report := &result.Issue{
FromLinter: a.Name,
Pos: issue.Pos,
Text: issue.Message,
Replacement: &result.Replacement{
Inline: &result.InlineFix{
StartCol: issue.InlineFix.StartCol,
Length: issue.InlineFix.Length,
NewString: issue.InlineFix.NewString,
},
},
}
issues[i] = goanalysis.NewIssue(report, pass)
}
if len(issues) == 0 {
return nil, nil
}
mu.Lock()
resIssues = append(resIssues, issues...)
mu.Unlock()
return nil, nil
}
return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue {
return resIssues
}).WithLoadMode(goanalysis.LoadModeTypesInfo)
}