Skip to content

Commit

Permalink
rename difffilter to filter
Browse files Browse the repository at this point in the history
  • Loading branch information
haya14busa committed Jul 25, 2020
1 parent 369164a commit 9c703e0
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 58 deletions.
10 changes: 5 additions & 5 deletions cmd/reviewdog/doghouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (

"github.com/reviewdog/reviewdog"
"github.com/reviewdog/reviewdog/cienv"
"github.com/reviewdog/reviewdog/difffilter"
"github.com/reviewdog/reviewdog/doghouse"
"github.com/reviewdog/reviewdog/doghouse/client"
"github.com/reviewdog/reviewdog/filter"
"github.com/reviewdog/reviewdog/project"
"github.com/reviewdog/reviewdog/proto/rdf"
)
Expand Down Expand Up @@ -313,7 +313,7 @@ func TestPostResultSet_withReportURL(t *testing.T) {
SHA: sha,
}

opt := &option{filterMode: difffilter.ModeAdded}
opt := &option{filterMode: filter.ModeAdded}
if _, err := postResultSet(context.Background(), &resultSet, ghInfo, fakeCli, opt); err != nil {
t.Fatal(err)
}
Expand All @@ -338,7 +338,7 @@ func TestPostResultSet_withoutReportURL(t *testing.T) {

ghInfo := &cienv.BuildInfo{Owner: owner, Repo: repo, PullRequest: prNum, SHA: sha}

opt := &option{filterMode: difffilter.ModeAdded}
opt := &option{filterMode: filter.ModeAdded}
resp, err := postResultSet(context.Background(), &resultSet, ghInfo, fakeCli, opt)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -385,7 +385,7 @@ func TestPostResultSet_conclusion(t *testing.T) {
fakeCli.FakeCheck = func(ctx context.Context, req *doghouse.CheckRequest) (*doghouse.CheckResponse, error) {
return &doghouse.CheckResponse{ReportURL: "xxx", Conclusion: tt.conclusion}, nil
}
opt := &option{filterMode: difffilter.ModeAdded, failOnError: tt.failOnError}
opt := &option{filterMode: filter.ModeAdded, failOnError: tt.failOnError}
id := fmt.Sprintf("[conclusion=%s, failOnError=%v]", tt.conclusion, tt.failOnError)
_, err := postResultSet(context.Background(), &resultSet, ghInfo, fakeCli, opt)
if tt.wantErr && err == nil {
Expand Down Expand Up @@ -414,7 +414,7 @@ func TestPostResultSet_withEmptyResponse(t *testing.T) {

ghInfo := &cienv.BuildInfo{Owner: owner, Repo: repo, PullRequest: prNum, SHA: sha}

opt := &option{filterMode: difffilter.ModeAdded}
opt := &option{filterMode: filter.ModeAdded}
if _, err := postResultSet(context.Background(), &resultSet, ghInfo, fakeCli, opt); err == nil {
t.Error("got no error but want report missing error")
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/reviewdog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/reviewdog/reviewdog"
"github.com/reviewdog/reviewdog/cienv"
"github.com/reviewdog/reviewdog/commands"
"github.com/reviewdog/reviewdog/difffilter"
"github.com/reviewdog/reviewdog/filter"
"github.com/reviewdog/reviewdog/parser"
"github.com/reviewdog/reviewdog/project"
gerritservice "github.com/reviewdog/reviewdog/service/gerrit"
Expand Down Expand Up @@ -57,7 +57,7 @@ type option struct {
level string
guessPullRequest bool
tee bool
filterMode difffilter.Mode
filterMode filter.Mode
failOnError bool
}

Expand Down Expand Up @@ -335,7 +335,7 @@ github-pr-check reporter as a fallback.
}
ds = d
case "local":
if opt.diffCmd == "" && opt.filterMode == difffilter.ModeNoFilter {
if opt.diffCmd == "" && opt.filterMode == filter.ModeNoFilter {
ds = &reviewdog.EmptyDiff{}
} else {
d, err := diffService(opt.diffCmd, opt.diffStrip)
Expand Down
4 changes: 2 additions & 2 deletions cmd/reviewdog/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"

"github.com/reviewdog/reviewdog/commands"
"github.com/reviewdog/reviewdog/difffilter"
"github.com/reviewdog/reviewdog/filter"
)

func TestRun_local(t *testing.T) {
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestRun_local_nofilter(t *testing.T) {
t.Errorf("got no error, but want error")
}

opt.filterMode = difffilter.ModeNoFilter
opt.filterMode = filter.ModeNoFilter
if err := run(strings.NewReader(stdin), stdout, opt); err != nil {
t.Error(err)
}
Expand Down
4 changes: 2 additions & 2 deletions doghouse/server/doghouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

"github.com/reviewdog/reviewdog"
"github.com/reviewdog/reviewdog/diff"
"github.com/reviewdog/reviewdog/difffilter"
"github.com/reviewdog/reviewdog/doghouse"
"github.com/reviewdog/reviewdog/filter"
"github.com/reviewdog/reviewdog/proto/rdf"
"github.com/reviewdog/reviewdog/service/github/githubutils"
)
Expand Down Expand Up @@ -56,7 +56,7 @@ func (ch *Checker) Check(ctx context.Context) (*doghouse.CheckResponse, error) {
if ch.req.PullRequest == 0 || ch.req.OutsideDiff {
// If it's not Pull Request run, do not filter results by diff regardless
// of the filter mode.
filterMode = difffilter.ModeNoFilter
filterMode = filter.ModeNoFilter
}
filtered := reviewdog.FilterCheck(results, filediffs, 1, "", filterMode)
check, err := ch.createCheck(ctx)
Expand Down
8 changes: 4 additions & 4 deletions doghouse/server/doghouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-github/v32/github"

"github.com/reviewdog/reviewdog/difffilter"
"github.com/reviewdog/reviewdog/doghouse"
"github.com/reviewdog/reviewdog/filter"
"github.com/reviewdog/reviewdog/proto/rdf"
)

Expand Down Expand Up @@ -274,7 +274,7 @@ func TestCheck_OK(t *testing.T) {
}
}

func testOutsideDiff(t *testing.T, outsideDiff bool, filterMode difffilter.Mode) {
func testOutsideDiff(t *testing.T, outsideDiff bool, filterMode filter.Mode) {
const (
name = "haya14busa-linter"
owner = "haya14busa"
Expand Down Expand Up @@ -371,10 +371,10 @@ func testOutsideDiff(t *testing.T, outsideDiff bool, filterMode difffilter.Mode)

func TestCheck_OK_deprecated_outsidediff(t *testing.T) {
t.Run("deprecated: outside_diff", func(t *testing.T) {
testOutsideDiff(t, true, difffilter.ModeDefault)
testOutsideDiff(t, true, filter.ModeDefault)
})
t.Run("filter-mode=NoFilter", func(t *testing.T) {
testOutsideDiff(t, false, difffilter.ModeNoFilter)
testOutsideDiff(t, false, filter.ModeNoFilter)
})
}

Expand Down
6 changes: 3 additions & 3 deletions doghouse/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package doghouse

import (
"github.com/reviewdog/reviewdog"
"github.com/reviewdog/reviewdog/difffilter"
"github.com/reviewdog/reviewdog/filter"
"github.com/reviewdog/reviewdog/proto/rdf"
)

Expand Down Expand Up @@ -38,7 +38,7 @@ type CheckRequest struct {
// Optional.
Level string `json:"level"`

// Deprecated: Use FilterMode == difffilter.NoFilter instead.
// Deprecated: Use FilterMode == filter.NoFilter instead.
//
// OutsideDiff represents whether it report results in outside diff or not as
// annotations. It's useful only when PullRequest != 0. If PullRequest is
Expand All @@ -49,7 +49,7 @@ type CheckRequest struct {

// FilterMode represents a way to filter checks results
// Optional.
FilterMode difffilter.Mode `json:"filter_mode"`
FilterMode filter.Mode `json:"filter_mode"`
}

// CheckResponse represents doghouse GitHub check response.
Expand Down
12 changes: 6 additions & 6 deletions filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"path/filepath"

"github.com/reviewdog/reviewdog/diff"
"github.com/reviewdog/reviewdog/difffilter"
"github.com/reviewdog/reviewdog/filter"
"github.com/reviewdog/reviewdog/proto/rdf"
)

Expand All @@ -25,9 +25,9 @@ type FilteredCheck struct {
// FilterCheck filters check results by diff. It doesn't drop check which
// is not in diff but set FilteredCheck.ShouldReport field false.
func FilterCheck(results []*rdf.Diagnostic, diff []*diff.FileDiff, strip int,
cwd string, mode difffilter.Mode) []*FilteredCheck {
cwd string, mode filter.Mode) []*FilteredCheck {
checks := make([]*FilteredCheck, 0, len(results))
df := difffilter.New(diff, strip, cwd, mode)
df := filter.New(diff, strip, cwd, mode)
for _, result := range results {
check := &FilteredCheck{Diagnostic: result}
loc := result.GetLocation()
Expand Down Expand Up @@ -60,7 +60,7 @@ func FilterCheck(results []*rdf.Diagnostic, diff []*diff.FileDiff, strip int,
// path to the given workdir.
//
// TODO(haya14busa): DRY. Create shared logic between this and
// difffilter.normalizePath.
// filter.normalizePath.
func CleanPath(path, workdir string) string {
p := path
if filepath.IsAbs(path) && workdir != "" {
Expand All @@ -80,10 +80,10 @@ func getOldPosition(filediff *diff.FileDiff, strip int, newPath string, newLine
if filediff == nil {
return "", 0
}
if difffilter.NormalizeDiffPath(filediff.PathNew, strip) != newPath {
if filter.NormalizeDiffPath(filediff.PathNew, strip) != newPath {
return "", 0
}
oldPath = difffilter.NormalizeDiffPath(filediff.PathOld, strip)
oldPath = filter.NormalizeDiffPath(filediff.PathOld, strip)
delta := 0
for _, hunk := range filediff.Hunks {
if newLine < hunk.StartLineNew {
Expand Down
2 changes: 1 addition & 1 deletion difffilter/filter.go → filter/diff_filter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package difffilter
package filter

import (
"fmt"
Expand Down
6 changes: 3 additions & 3 deletions difffilter/filter_test.go → filter/diff_filter_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package difffilter
package filter

import (
"os"
Expand Down Expand Up @@ -58,8 +58,8 @@ const sampleDiffRoot = `--- a/sample.old.txt 2016-10-13 05:09:35.820791185 +0900
\ No newline at end of file
`

const sampleDiffSubDir = `--- a/difffilter/sample.old.txt 2016-10-13 05:09:35.820791185 +0900
+++ b/difffilter/sample.new.txt 2016-10-13 05:15:26.839245048 +0900
const sampleDiffSubDir = `--- a/filter/sample.old.txt 2016-10-13 05:09:35.820791185 +0900
+++ b/filter/sample.new.txt 2016-10-13 05:15:26.839245048 +0900
@@ -1,3 +1,4 @@
unchanged, contextual line
-deleted line
Expand Down
8 changes: 4 additions & 4 deletions filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"google.golang.org/protobuf/testing/protocmp"

"github.com/reviewdog/reviewdog/diff"
"github.com/reviewdog/reviewdog/difffilter"
"github.com/reviewdog/reviewdog/filter"
"github.com/reviewdog/reviewdog/proto/rdf"
)

Expand Down Expand Up @@ -153,7 +153,7 @@ func TestFilterCheckByAddedLines(t *testing.T) {
},
}
filediffs, _ := diff.ParseMultiFile(strings.NewReader(diffContent))
got := FilterCheck(results, filediffs, 0, "", difffilter.ModeAdded)
got := FilterCheck(results, filediffs, 0, "", filter.ModeAdded)
if diff := cmp.Diff(got, want, protocmp.Transform()); diff != "" {
t.Error(diff)
}
Expand Down Expand Up @@ -223,15 +223,15 @@ func TestFilterCheckByDiffContext(t *testing.T) {
},
}
filediffs, _ := diff.ParseMultiFile(strings.NewReader(diffContent))
got := FilterCheck(results, filediffs, 0, "", difffilter.ModeDiffContext)
got := FilterCheck(results, filediffs, 0, "", filter.ModeDiffContext)
if diff := cmp.Diff(got, want, protocmp.Transform()); diff != "" {
t.Error(diff)
}
}

func findFileDiff(filediffs []*diff.FileDiff, path string, strip int) *diff.FileDiff {
for _, file := range filediffs {
if difffilter.NormalizeDiffPath(file.PathNew, strip) == path {
if filter.NormalizeDiffPath(file.PathNew, strip) == path {
return file
}
}
Expand Down
4 changes: 2 additions & 2 deletions project/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/reviewdog/reviewdog"
"github.com/reviewdog/reviewdog/diff"
"github.com/reviewdog/reviewdog/difffilter"
"github.com/reviewdog/reviewdog/filter"
"github.com/reviewdog/reviewdog/parser"
)

Expand Down Expand Up @@ -91,7 +91,7 @@ func RunAndParse(ctx context.Context, conf *Config, runners map[string]bool, def
}

// Run runs reviewdog tasks based on Config.
func Run(ctx context.Context, conf *Config, runners map[string]bool, c reviewdog.CommentService, d reviewdog.DiffService, teeMode bool, filterMode difffilter.Mode, failOnError bool) error {
func Run(ctx context.Context, conf *Config, runners map[string]bool, c reviewdog.CommentService, d reviewdog.DiffService, teeMode bool, filterMode filter.Mode, failOnError bool) error {
results, err := RunAndParse(ctx, conf, runners, "", teeMode) // Level is not used.
if err != nil {
return err
Expand Down
22 changes: 11 additions & 11 deletions project/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"

"github.com/reviewdog/reviewdog"
"github.com/reviewdog/reviewdog/difffilter"
"github.com/reviewdog/reviewdog/filter"
)

type fakeDiffService struct {
Expand Down Expand Up @@ -39,7 +39,7 @@ func TestRun(t *testing.T) {

t.Run("empty", func(t *testing.T) {
conf := &Config{}
if err := Run(ctx, conf, nil, nil, nil, false, difffilter.ModeAdded, false); err != nil {
if err := Run(ctx, conf, nil, nil, nil, false, filter.ModeAdded, false); err != nil {
t.Error(err)
}
})
Expand All @@ -50,7 +50,7 @@ func TestRun(t *testing.T) {
"test": {},
},
}
if err := Run(ctx, conf, nil, nil, nil, false, difffilter.ModeAdded, false); err == nil {
if err := Run(ctx, conf, nil, nil, nil, false, filter.ModeAdded, false); err == nil {
t.Error("want error, got nil")
} else {
t.Log(err)
Expand All @@ -71,7 +71,7 @@ func TestRun(t *testing.T) {
},
},
}
if err := Run(ctx, conf, nil, nil, ds, false, difffilter.ModeAdded, false); err == nil {
if err := Run(ctx, conf, nil, nil, ds, false, filter.ModeAdded, false); err == nil {
t.Error("want error, got nil")
} else {
t.Log(err)
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestRun(t *testing.T) {
},
},
}
if err := Run(ctx, conf, nil, cs, ds, false, difffilter.ModeAdded, false); err != nil {
if err := Run(ctx, conf, nil, cs, ds, false, filter.ModeAdded, false); err != nil {
t.Error(err)
}
want := ""
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestRun(t *testing.T) {
},
},
}
if err := Run(ctx, conf, nil, cs, ds, false, difffilter.ModeAdded, false); err == nil {
if err := Run(ctx, conf, nil, cs, ds, false, filter.ModeAdded, false); err == nil {
t.Error("want error, got nil")
} else {
t.Log(err)
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestRun(t *testing.T) {
},
},
}
if err := Run(ctx, conf, nil, cs, ds, true, difffilter.ModeAdded, false); err == nil {
if err := Run(ctx, conf, nil, cs, ds, true, filter.ModeAdded, false); err == nil {
t.Error("want error, got nil")
} else {
t.Log(err)
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestRun(t *testing.T) {
},
},
}
if err := Run(ctx, conf, nil, cs, ds, false, difffilter.ModeAdded, false); err != nil {
if err := Run(ctx, conf, nil, cs, ds, false, filter.ModeAdded, false); err != nil {
t.Error(err)
}
})
Expand All @@ -213,7 +213,7 @@ func TestRun(t *testing.T) {
},
},
}
if err := Run(ctx, conf, nil, cs, ds, true, difffilter.ModeAdded, false); err != nil {
if err := Run(ctx, conf, nil, cs, ds, true, filter.ModeAdded, false); err != nil {
t.Error(err)
}
want := "hi\n"
Expand Down Expand Up @@ -249,7 +249,7 @@ func TestRun(t *testing.T) {
},
},
}
if err := Run(ctx, conf, map[string]bool{"test2": true}, cs, ds, false, difffilter.ModeAdded, false); err != nil {
if err := Run(ctx, conf, map[string]bool{"test2": true}, cs, ds, false, filter.ModeAdded, false); err != nil {
t.Error(err)
}
if called != 1 {
Expand Down Expand Up @@ -282,7 +282,7 @@ func TestRun(t *testing.T) {
},
},
}
if err := Run(ctx, conf, map[string]bool{"hoge": true}, cs, ds, false, difffilter.ModeAdded, false); err == nil {
if err := Run(ctx, conf, map[string]bool{"hoge": true}, cs, ds, false, filter.ModeAdded, false); err == nil {
t.Error("got no error but want runner not found error")
}
})
Expand Down

0 comments on commit 9c703e0

Please sign in to comment.