@@ -88,11 +88,11 @@ func (i simpleInputIssue) Line() int {
88
88
89
89
// Prepare extracts a patch and changed lines.
90
90
func (c * Checker ) Prepare (ctx context.Context ) error {
91
- returnErr := c .preparePatch (ctx )
91
+ err := c .preparePatch (ctx )
92
92
93
93
c .changes = c .linesChanged ()
94
94
95
- return returnErr
95
+ return err
96
96
}
97
97
98
98
// 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)
238
238
return issues , returnErr
239
239
}
240
240
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
245
244
}
245
+
246
+ _ , _ = fmt .Fprint (c .Debug , "DEBUG: " )
247
+ _ , _ = fmt .Fprintf (c .Debug , format + "\n " , s ... )
246
248
}
247
249
250
+ // preparePatch checks if patch is supplied, if not, retrieve from VCS.
248
251
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
+
250
262
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" )
259
264
}
260
265
261
266
return nil
@@ -321,11 +326,13 @@ func (c *Checker) linesChanged() map[string][]pos {
321
326
// cstart ^
322
327
chdr := strings .Split (line , " " )
323
328
ahdr := strings .Split (chdr [2 ], "," )
329
+
324
330
// [1:] to remove leading plus
325
331
cstart , err := strconv .ParseUint (ahdr [0 ][1 :], 10 , 64 )
326
332
if err != nil {
327
333
panic (err )
328
334
}
335
+
329
336
s .lineNo = int (cstart ) - 1 // -1 as cstart is the next line number
330
337
331
338
case strings .HasPrefix (line , "-" ):
0 commit comments