3 Star 0 Fork 0

mirrors_anirudh-ramesh/reviewdog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
comment_iowriter.go 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
haya14busa 提交于 2020-07-25 16:26 . Remove reviewdog.Comment.Body
package reviewdog
import (
"context"
"fmt"
"io"
)
var _ CommentService = &RawCommentWriter{}
// RawCommentWriter is comment writer which writes results to given writer
// without any formatting.
type RawCommentWriter struct {
w io.Writer
}
func NewRawCommentWriter(w io.Writer) *RawCommentWriter {
return &RawCommentWriter{w: w}
}
func (s *RawCommentWriter) Post(_ context.Context, c *Comment) error {
_, err := fmt.Fprintln(s.w, c.Result.Diagnostic.OriginalOutput)
return err
}
var _ CommentService = &UnifiedCommentWriter{}
// UnifiedCommentWriter is comment writer which writes results to given writer
// in one of following unified formats.
//
// Format:
// - <file>: [<tool name>] <message>
// - <file>:<lnum>: [<tool name>] <message>
// - <file>:<lnum>:<col>: [<tool name>] <message>
// where <message> can be multiple lines.
type UnifiedCommentWriter struct {
w io.Writer
}
func NewUnifiedCommentWriter(w io.Writer) *UnifiedCommentWriter {
return &UnifiedCommentWriter{w: w}
}
func (mc *UnifiedCommentWriter) Post(_ context.Context, c *Comment) error {
loc := c.Result.Diagnostic.GetLocation()
s := loc.GetPath()
start := loc.GetRange().GetStart()
if start.GetLine() > 0 {
s += fmt.Sprintf(":%d", start.GetLine())
if start.GetColumn() > 0 {
s += fmt.Sprintf(":%d", start.GetColumn())
}
}
s += fmt.Sprintf(": [%s] %s", c.ToolName, c.Result.Diagnostic.GetMessage())
_, err := fmt.Fprintln(mc.w, s)
return err
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_anirudh-ramesh/reviewdog.git
git@gitee.com:mirrors_anirudh-ramesh/reviewdog.git
mirrors_anirudh-ramesh
reviewdog
reviewdog
master

搜索帮助