Skip to content

Commit 5d5bf78

Browse files
committed
feat: add IsNew method
1 parent 41fcbf6 commit 5d5bf78

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

revgrep.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ type Checker struct {
3939
// If not set, current working directory is used.
4040
AbsPath string
4141

42-
// Calculated changes for next calls to IsNewIssue
42+
// Calculated changes for next calls to [Checker.IsNewIssue]/[Checker.IsNew].
4343
changes map[string][]pos
4444
}
4545

4646
// Prepare extracts a patch and changed lines.
4747
//
48-
// WARNING: it should only be used before an explicit call to [Checker.IsNewIssue].
48+
// WARNING: it should only be used before an explicit call to [Checker.IsNewIssue]/[Checker.IsNew].
4949
//
5050
// WARNING: only [Checker.Patch], [Checker.RevisionFrom], [Checker.RevisionTo], [Checker.WholeFiles] options are used,
5151
// the other options ([Checker.Regexp], [Checker.AbsPath]) are only used by [Checker.Check].
@@ -57,18 +57,18 @@ func (c *Checker) Prepare(ctx context.Context) error {
5757
return err
5858
}
5959

60-
// IsNewIssue checks whether issue found by linter is new: it was found in changed lines.
60+
// IsNew checks whether issue found by linter is new: it was found in changed lines.
6161
//
6262
// WARNING: it requires to call [Checker.Prepare] before call this method to load the changes from patch.
63-
func (c *Checker) IsNewIssue(i InputIssue) (hunkPos int, isNew bool) {
64-
changes, ok := c.changes[filepath.ToSlash(i.FilePath())]
63+
func (c *Checker) IsNew(filePath string, line int) (hunkPos int, isNew bool) {
64+
changes, ok := c.changes[filepath.ToSlash(filePath)]
6565
if !ok {
6666
// file wasn't changed
6767
return 0, false
6868
}
6969

7070
if c.WholeFiles {
71-
return i.Line(), true
71+
return line, true
7272
}
7373

7474
var (
@@ -78,7 +78,7 @@ func (c *Checker) IsNewIssue(i InputIssue) (hunkPos int, isNew bool) {
7878

7979
// found file, see if lines matched
8080
for _, pos := range changes {
81-
if pos.lineNo == i.Line() {
81+
if pos.lineNo == line {
8282
fpos = pos
8383
changed = true
8484

@@ -101,6 +101,13 @@ func (c *Checker) IsNewIssue(i InputIssue) (hunkPos int, isNew bool) {
101101
return 0, false
102102
}
103103

104+
// IsNewIssue checks whether issue found by linter is new: it was found in changed lines.
105+
//
106+
// WARNING: it requires to call [Checker.Prepare] before call this method to load the changes from patch.
107+
func (c *Checker) IsNewIssue(i InputIssue) (hunkPos int, isNew bool) {
108+
return c.IsNew(i.FilePath(), i.Line())
109+
}
110+
104111
// Check scans reader and writes any lines to writer that have been added in [Checker.Patch].
105112
//
106113
// Returns the issues written to writer when no error occurs.

0 commit comments

Comments
 (0)