1 Star 0 Fork 0

Laomo. / golangci-lint

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
checkstyle.go 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
package printers
import (
"context"
"encoding/xml"
"fmt"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/golangci/golangci-lint/pkg/result"
)
type checkstyleOutput struct {
XMLName xml.Name `xml:"checkstyle"`
Version string `xml:"version,attr"`
Files []*checkstyleFile `xml:"file"`
}
type checkstyleFile struct {
Name string `xml:"name,attr"`
Errors []*checkstyleError `xml:"error"`
}
type checkstyleError struct {
Column int `xml:"column,attr"`
Line int `xml:"line,attr"`
Message string `xml:"message,attr"`
Severity string `xml:"severity,attr"`
Source string `xml:"source,attr"`
}
const defaultSeverity = "error"
type Checkstyle struct{}
func NewCheckstyle() *Checkstyle {
return &Checkstyle{}
}
func (Checkstyle) Print(ctx context.Context, issues <-chan result.Issue) error {
out := checkstyleOutput{
Version: "5.0",
}
files := map[string]*checkstyleFile{}
for issue := range issues {
file, ok := files[issue.FilePath()]
if !ok {
file = &checkstyleFile{
Name: issue.FilePath(),
}
files[issue.FilePath()] = file
}
newError := &checkstyleError{
Column: issue.Column(),
Line: issue.Line(),
Message: issue.Text,
Source: issue.FromLinter,
Severity: defaultSeverity,
}
file.Errors = append(file.Errors, newError)
}
out.Files = make([]*checkstyleFile, 0, len(files))
for _, file := range files {
out.Files = append(out.Files, file)
}
data, err := xml.Marshal(&out)
if err != nil {
return err
}
fmt.Fprintf(logutils.StdOut, "%s%s\n", xml.Header, data)
return nil
}
1
https://gitee.com/LaomoBK/golangci-lint.git
git@gitee.com:LaomoBK/golangci-lint.git
LaomoBK
golangci-lint
golangci-lint
v1.10.1

搜索帮助