Ai
1 Star 0 Fork 0

Laomo./golangci-lint

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
diff.go 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
package processors
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"github.com/golangci/golangci-lint/pkg/result"
"github.com/golangci/revgrep"
)
type Diff struct {
onlyNew bool
fromRev string
patchFilePath string
patch string
}
var _ Processor = Diff{}
func NewDiff(onlyNew bool, fromRev, patchFilePath string) *Diff {
return &Diff{
onlyNew: onlyNew,
fromRev: fromRev,
patchFilePath: patchFilePath,
patch: os.Getenv("GOLANGCI_DIFF_PROCESSOR_PATCH"),
}
}
func (p Diff) Name() string {
return "diff"
}
func (p Diff) Process(issues []result.Issue) ([]result.Issue, error) {
if !p.onlyNew && p.fromRev == "" && p.patchFilePath == "" && p.patch == "" { // no need to work
return issues, nil
}
var patchReader io.Reader
if p.patchFilePath != "" {
patch, err := ioutil.ReadFile(p.patchFilePath)
if err != nil {
return nil, fmt.Errorf("can't read from patch file %s: %s", p.patchFilePath, err)
}
patchReader = bytes.NewReader(patch)
} else if p.patch != "" {
patchReader = strings.NewReader(p.patch)
}
c := revgrep.Checker{
Patch: patchReader,
RevisionFrom: p.fromRev,
}
if err := c.Prepare(); err != nil {
return nil, fmt.Errorf("can't prepare diff by revgrep: %s", err)
}
return transformIssues(issues, func(i *result.Issue) *result.Issue {
hunkPos, isNew := c.IsNewIssue(i)
if !isNew {
return nil
}
newI := *i
newI.HunkPos = hunkPos
return &newI
}), nil
}
func (Diff) Finish() {}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LaomoBK/golangci-lint.git
git@gitee.com:LaomoBK/golangci-lint.git
LaomoBK
golangci-lint
golangci-lint
v1.10.1

搜索帮助