Skip to content

Commit 266ee1e

Browse files
committed
git-codereview: do not check vendor folder with gofmt
The go command already skips the vendor folder when running go fmt. The "go mod vendor" command updates all vendor packages at once, so this becomes more of an issue. Change-Id: I0b2d51d2f1f01998e9ca7a244af491bd18150e8a Reviewed-on: https://go-review.googlesource.com/c/158839 Run-TryBot: Daniel Theophanes <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Josh Bleecher Snyder <[email protected]>
1 parent 80efb4d commit 266ee1e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

git-codereview/gofmt.go

+3
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ func gofmtRequired(file string) bool {
345345
if !strings.HasSuffix(file, ".go") {
346346
return false
347347
}
348+
if strings.HasPrefix(file, "vendor/") || strings.Contains(file, "/vendor/") {
349+
return false
350+
}
348351
if !strings.HasPrefix(file, "test/") {
349352
return true
350353
}

git-codereview/gofmt_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,22 @@ func TestGofmt(t *testing.T) {
3131
if err := os.MkdirAll(gt.client+"/test/bench", 0755); err != nil {
3232
t.Fatal(err)
3333
}
34+
if err := os.MkdirAll(gt.client+"/vendor", 0755); err != nil {
35+
t.Fatal(err)
36+
}
3437
write(t, gt.client+"/bad.go", badGo)
3538
write(t, gt.client+"/good.go", goodGo)
39+
write(t, gt.client+"/vendor/bad.go", badGo)
3640
write(t, gt.client+"/test/bad.go", badGo)
3741
write(t, gt.client+"/test/good.go", goodGo)
3842
write(t, gt.client+"/test/bench/bad.go", badGo)
3943
write(t, gt.client+"/test/bench/good.go", goodGo)
4044
trun(t, gt.client, "git", "add", ".") // make files tracked
4145

4246
testMain(t, "gofmt", "-l")
43-
testPrintedStdout(t, "bad.go\n", "!good.go", fromSlash("!test/bad"), fromSlash("test/bench/bad.go"))
44-
47+
testPrintedStdout(t, "bad.go\n", "!good.go", fromSlash("!test/bad"), fromSlash("test/bench/bad.go"), fromSlash("!vendor/bad.go"))
4548
testMain(t, "gofmt", "-l")
46-
testPrintedStdout(t, "bad.go\n", "!good.go", fromSlash("!test/bad"), fromSlash("test/bench/bad.go"))
49+
testPrintedStdout(t, "bad.go\n", "!good.go", fromSlash("!test/bad"), fromSlash("test/bench/bad.go"), fromSlash("!vendor/bad.go"))
4750

4851
testMain(t, "gofmt")
4952
testNoStdout(t)

0 commit comments

Comments
 (0)