Skip to content

Commit

Permalink
fix(gomodcheck): ignore non-local repalce
Browse files Browse the repository at this point in the history
  • Loading branch information
wwcchh0123 committed Sep 19, 2024
1 parent 0b52b43 commit d19e34a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/linters/go/gomodcheck/gomodcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ func goModCheckOutput(log *xlog.Logger, a linters.Agent) (map[string][]linters.L
for _, replace := range mod.Replace {
var parsePath string
matches := re.FindString(replace.New.Path)
if matches != "" {
parsePath = filepath.Join(filepath.Dir(goModPath), matches)
if matches == "" {
continue
}
parsePath = filepath.Join(filepath.Dir(goModPath), matches)

isSub, err := isSubdirectory(a.RepoDir, parsePath)
if err != nil {
log.Errorf("failed to compare whether A is a subdirectory of B : %v", err)
Expand Down
13 changes: 13 additions & 0 deletions internal/linters/go/gomodcheck/gomodcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ func TestGoModCheck(t *testing.T) {
},
want: map[string][]linters.LinterOutput{},
},
{
id: "case3 : valid local replacement ",
content: []byte("replace github.com/xxxxx/xxx v0.0.0 => github.com/xxx/xxxx v1.1.1"),
input: linters.Agent{
RepoDir: "a/b",
PullRequestChangedFiles: []*github.CommitFile{
{
Filename: &modDir,
},
},
},
want: map[string][]linters.LinterOutput{},
},
}

for _, tc := range tcs {
Expand Down

0 comments on commit d19e34a

Please sign in to comment.