Skip to content

Commit 039bb0f

Browse files
committed
refactor: improve Diff processor readability
1 parent 7af5f7c commit 039bb0f

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
@@ -35,32 +35,36 @@ func NewDiff(cfg *config.Issues) *Diff {
3535
}
3636
}
3737

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

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

4747
var patchReader io.Reader
48-
if p.patchFilePath != "" {
48+
switch {
49+
case p.patchFilePath != "":
4950
patch, err := os.ReadFile(p.patchFilePath)
5051
if err != nil {
5152
return nil, fmt.Errorf("can't read from patch file %s: %w", p.patchFilePath, err)
5253
}
54+
5355
patchReader = bytes.NewReader(patch)
54-
} else if p.patch != "" {
56+
57+
case p.patch != "":
5558
patchReader = strings.NewReader(p.patch)
5659
}
5760

58-
c := revgrep.Checker{
61+
checker := revgrep.Checker{
5962
Patch: patchReader,
6063
RevisionFrom: p.fromRev,
6164
WholeFiles: p.wholeFiles,
6265
}
63-
if err := c.Prepare(); err != nil {
66+
67+
if err := checker.Prepare(); err != nil {
6468
return nil, fmt.Errorf("can't prepare diff by revgrep: %w", err)
6569
}
6670

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

73-
hunkPos, isNew := c.IsNewIssue(issue)
77+
hunkPos, isNew := checker.IsNewIssue(issue)
7478
if !isNew {
7579
return nil
7680
}
7781

7882
newIssue := *issue
7983
newIssue.HunkPos = hunkPos
84+
8085
return &newIssue
8186
}), nil
8287
}
8388

84-
func (Diff) Finish() {}
89+
func (*Diff) Finish() {}

0 commit comments

Comments
 (0)