forked from alecthomas/gometalinter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aggregate.go
50 lines (46 loc) · 948 Bytes
/
aggregate.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
package main
import (
"sort"
"strings"
)
type (
issueKey struct {
path string
line, col int
message string
}
multiIssue struct {
*Issue
linterNames []string
}
)
func aggregateIssues(issues chan *Issue) chan *Issue {
out := make(chan *Issue, 1000000)
issueMap := make(map[issueKey]*multiIssue)
go func() {
for issue := range issues {
key := issueKey{
path: issue.Path,
line: issue.Line,
col: issue.Col,
message: issue.Message,
}
if existing, ok := issueMap[key]; ok {
existing.linterNames = append(existing.linterNames, issue.Linter.Name)
} else {
issueMap[key] = &multiIssue{
Issue: issue,
linterNames: []string{issue.Linter.Name},
}
}
}
for _, multi := range issueMap {
issue := multi.Issue
sort.Strings(multi.linterNames)
issue.Linter.Name = strings.Join(multi.linterNames, ", ")
out <- issue
}
close(out)
}()
return out
}