diff --git a/revgrep.go b/revgrep.go index d0940d3..f15d601 100644 --- a/revgrep.go +++ b/revgrep.go @@ -31,6 +31,9 @@ type Checker struct { // RevisionFrom check revision starting at, leave blank for auto detection // ignored if patch is set. RevisionFrom string + // WholeFiles indicates that the user wishes to see all issues that comes up + // anywhere in any file that has been changed in this revision or patch. + WholeFiles bool // RevisionTo checks revision finishing at, leave blank for auto detection // ignored if patch is set. RevisionTo string @@ -113,6 +116,10 @@ func (c Checker) IsNewIssue(i InputIssue) (hunkPos int, isNew bool) { return 0, false } + if c.WholeFiles { + return i.Line(), true + } + var ( fpos pos changed bool diff --git a/revgrep_test.go b/revgrep_test.go index 88ad841..12887d7 100644 --- a/revgrep_test.go +++ b/revgrep_test.go @@ -78,6 +78,46 @@ func TestCheckerRegexp(t *testing.T) { } } +// TestWholeFile tests Checker.WholeFiles will report any issues in files that have changes, even if +// they are outside the diff. +func TestWholeFiles(t *testing.T) { + tests := []struct { + name string + line string + matches bool + }{ + {"inside diff", "file.go:1:issue", true}, + {"outside diff", "file.go:10:5:issue", true}, + {"different file", "file2.go:1:issue", false}, + } + + diff := []byte(`--- a/file.go ++++ b/file.go +@@ -1,1 +1,1 @@ +-func Line() {} ++func NewLine() {}`) + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + checker := Checker{ + Patch: bytes.NewReader(diff), + WholeFiles: true, + } + + issues, err := checker.Check(bytes.NewReader([]byte(test.line)), ioutil.Discard) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if test.matches && len(issues) != 1 { + t.Fatalf("expected one issue to be returned, but got %#v", issues) + } + if !test.matches && len(issues) != 0 { + t.Fatalf("expected no issues to be returned, but got %#v", issues) + } + }) + } +} + // TestChangesReturn tests the writer in the argument to the Changes function // and generally tests the entire programs functionality. func TestChangesWriter(t *testing.T) {