Skip to content

Commit 2531062

Browse files
committed
refactor: improve Diff processor readability
1 parent 8911291 commit 2531062

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

pkg/result/processors/diff.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,36 @@ func NewDiff(cfg *config.Issues) *Diff {
3636
}
3737
}
3838

39-
func (Diff) Name() string {
39+
func (*Diff) Name() string {
4040
return "diff"
4141
}
4242

43-
func (p Diff) Process(issues []result.Issue) ([]result.Issue, error) {
44-
if !p.onlyNew && p.fromRev == "" && p.patchFilePath == "" && p.patch == "" { // no need to work
43+
func (p *Diff) Process(issues []result.Issue) ([]result.Issue, error) {
44+
if !p.onlyNew && p.fromRev == "" && p.patchFilePath == "" && p.patch == "" {
4545
return issues, nil
4646
}
4747

4848
var patchReader io.Reader
49-
if p.patchFilePath != "" {
49+
switch {
50+
case p.patchFilePath != "":
5051
patch, err := os.ReadFile(p.patchFilePath)
5152
if err != nil {
5253
return nil, fmt.Errorf("can't read from patch file %s: %w", p.patchFilePath, err)
5354
}
55+
5456
patchReader = bytes.NewReader(patch)
55-
} else if p.patch != "" {
57+
58+
case p.patch != "":
5659
patchReader = strings.NewReader(p.patch)
5760
}
5861

59-
c := revgrep.Checker{
62+
checker := revgrep.Checker{
6063
Patch: patchReader,
6164
RevisionFrom: p.fromRev,
6265
WholeFiles: p.wholeFiles,
6366
}
64-
if err := c.Prepare(context.Background()); err != nil {
67+
68+
if err := checker.Prepare(context.Background()); err != nil {
6569
return nil, fmt.Errorf("can't prepare diff by revgrep: %w", err)
6670
}
6771

@@ -71,15 +75,16 @@ func (p Diff) Process(issues []result.Issue) ([]result.Issue, error) {
7175
return issue
7276
}
7377

74-
hunkPos, isNew := c.IsNewIssue(issue)
78+
hunkPos, isNew := checker.IsNewIssue(issue)
7579
if !isNew {
7680
return nil
7781
}
7882

7983
newIssue := *issue
8084
newIssue.HunkPos = hunkPos
85+
8186
return &newIssue
8287
}), nil
8388
}
8489

85-
func (Diff) Finish() {}
90+
func (*Diff) Finish() {}

0 commit comments

Comments
 (0)