Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions revgrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions revgrep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down