Skip to content

Commit 1f5548f

Browse files
committed
chore: improve readability
1 parent 66a840e commit 1f5548f

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

Diff for: revgrep.go

+22-15
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ func (i simpleInputIssue) Line() int {
8888

8989
// Prepare extracts a patch and changed lines.
9090
func (c *Checker) Prepare(ctx context.Context) error {
91-
returnErr := c.preparePatch(ctx)
91+
err := c.preparePatch(ctx)
9292

9393
c.changes = c.linesChanged()
9494

95-
return returnErr
95+
return err
9696
}
9797

9898
// IsNewIssue checks whether issue found by linter is new: it was found in changed lines.
@@ -238,24 +238,29 @@ func (c *Checker) Check(ctx context.Context, reader io.Reader, writer io.Writer)
238238
return issues, returnErr
239239
}
240240

241-
func (c *Checker) debugf(format string, s ...interface{}) {
242-
if c.Debug != nil {
243-
_, _ = fmt.Fprint(c.Debug, "DEBUG: ")
244-
_, _ = fmt.Fprintf(c.Debug, format+"\n", s...)
241+
func (c *Checker) debugf(format string, s ...any) {
242+
if c.Debug == nil {
243+
return
245244
}
245+
246+
_, _ = fmt.Fprint(c.Debug, "DEBUG: ")
247+
_, _ = fmt.Fprintf(c.Debug, format+"\n", s...)
246248
}
247249

250+
// preparePatch checks if patch is supplied, if not, retrieve from VCS.
248251
func (c *Checker) preparePatch(ctx context.Context) error {
249-
// Check if patch is supplied, if not, retrieve from VCS
252+
if c.Patch != nil {
253+
return nil
254+
}
255+
256+
var err error
257+
c.Patch, c.NewFiles, err = GitPatch(ctx, c.RevisionFrom, c.RevisionTo)
258+
if err != nil {
259+
return fmt.Errorf("could not read git repo: %w", err)
260+
}
261+
250262
if c.Patch == nil {
251-
var err error
252-
c.Patch, c.NewFiles, err = GitPatch(ctx, c.RevisionFrom, c.RevisionTo)
253-
if err != nil {
254-
return fmt.Errorf("could not read git repo: %w", err)
255-
}
256-
if c.Patch == nil {
257-
return errors.New("no version control repository found")
258-
}
263+
return errors.New("no version control repository found")
259264
}
260265

261266
return nil
@@ -321,11 +326,13 @@ func (c *Checker) linesChanged() map[string][]pos {
321326
// cstart ^
322327
chdr := strings.Split(line, " ")
323328
ahdr := strings.Split(chdr[2], ",")
329+
324330
// [1:] to remove leading plus
325331
cstart, err := strconv.ParseUint(ahdr[0][1:], 10, 64)
326332
if err != nil {
327333
panic(err)
328334
}
335+
329336
s.lineNo = int(cstart) - 1 // -1 as cstart is the next line number
330337

331338
case strings.HasPrefix(line, "-"):

0 commit comments

Comments
 (0)