1 Star 0 Fork 0

lonely/gometalinter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
aggregate.go 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"sort"
"strings"
)
type issueKey struct {
path string
line, col int
message string
}
type multiIssue struct {
*Issue
linterNames []string
}
// AggregateIssueChan reads issues from a channel, aggregates issues which have
// the same file, line, vol, and message, and returns aggregated issues on
// a new channel.
func AggregateIssueChan(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.String(),
line: issue.Line,
col: issue.Col,
message: issue.Message,
}
if existing, ok := issueMap[key]; ok {
existing.linterNames = append(existing.linterNames, issue.Linter)
} else {
issueMap[key] = &multiIssue{
Issue: issue,
linterNames: []string{issue.Linter},
}
}
}
for _, multi := range issueMap {
issue := multi.Issue
sort.Strings(multi.linterNames)
issue.Linter = strings.Join(multi.linterNames, ", ")
out <- issue
}
close(out)
}()
return out
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lonely0422/gometalinter.git
git@gitee.com:lonely0422/gometalinter.git
lonely0422
gometalinter
gometalinter
v2.0.4

搜索帮助