/
uniq_by_line.go
58 lines (46 loc) · 1.16 KB
/
uniq_by_line.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
package processors
import (
"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/result"
)
type lineToCount map[int]int
type fileToLineToCount map[string]lineToCount
type UniqByLine struct {
flc fileToLineToCount
cfg *config.Config
}
func NewUniqByLine(cfg *config.Config) *UniqByLine {
return &UniqByLine{
flc: fileToLineToCount{},
cfg: cfg,
}
}
var _ Processor = &UniqByLine{}
func (p UniqByLine) Name() string {
return "uniq_by_line"
}
func (p *UniqByLine) Process(issues []result.Issue) ([]result.Issue, error) {
if !p.cfg.Output.UniqByLine {
return issues, nil
}
return filterIssues(issues, func(i *result.Issue) bool {
if i.Replacement != nil && p.cfg.Issues.NeedFix {
// if issue will be auto-fixed we shouldn't collapse issues:
// e.g. one line can contain 2 misspellings, they will be in 2 issues and misspell should fix both of them.
return true
}
lc := p.flc[i.FilePath()]
if lc == nil {
lc = lineToCount{}
p.flc[i.FilePath()] = lc
}
const limit = 1
count := lc[i.Line()]
if count == limit {
return false
}
lc[i.Line()]++
return true
}), nil
}
func (p UniqByLine) Finish() {}