forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmax_from_linter.go
51 lines (42 loc) · 1.29 KB
/
max_from_linter.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
package processors
import (
"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/golangci/golangci-lint/pkg/result"
)
var _ Processor = (*MaxFromLinter)(nil)
// MaxFromLinter limits the number of reports from the same linter.
type MaxFromLinter struct {
linterCounter map[string]int
limit int
log logutils.Log
cfg *config.Config
}
func NewMaxFromLinter(limit int, log logutils.Log, cfg *config.Config) *MaxFromLinter {
return &MaxFromLinter{
linterCounter: map[string]int{},
limit: limit,
log: log,
cfg: cfg,
}
}
func (*MaxFromLinter) Name() string {
return "max_from_linter"
}
func (p *MaxFromLinter) Process(issues []result.Issue) ([]result.Issue, error) {
if p.limit <= 0 { // no limit
return issues, nil
}
return filterIssuesUnsafe(issues, func(issue *result.Issue) bool {
p.linterCounter[issue.FromLinter]++ // always inc for stat
return p.linterCounter[issue.FromLinter] <= p.limit
}), nil
}
func (p *MaxFromLinter) Finish() {
walkStringToIntMapSortedByValue(p.linterCounter, func(linter string, count int) {
if count > p.limit {
p.log.Infof("%d/%d issues from linter %s were hidden, use --max-issues-per-linter",
count-p.limit, count, linter)
}
})
}