Gerrit Bot has uploaded this change for review.
Ignore `/vendor/` by default when linting
I'd like to continue from #303. All credits go to @dvyukov's work.
This PR will ignore `/vendor/` by default when linting. But `golint ./vendor/...` will still lint that `vendor` directory normally.
This'll fix #320 and fix #151.
Change-Id: I44a85ca633d2f9fd7083c6844a702b650b269325
GitHub-Last-Rev: 0dcd199f6e2c9e5fb738b78bfa2170de4c78a25f
GitHub-Pull-Request: golang/lint#325
---
M golint/golint.go
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/golint/golint.go b/golint/golint.go
index d8360ad..0088274 100644
--- a/golint/golint.go
+++ b/golint/golint.go
@@ -48,9 +48,12 @@
var dirsRun, filesRun, pkgsRun int
var args []string
for _, arg := range flag.Args() {
- if strings.HasSuffix(arg, "/...") && isDir(arg[:len(arg)-len("/...")]) {
+ if trimmedArg := strings.TrimSuffix(arg, "/..."); trimmedArg != arg && isDir(trimmedArg) {
dirsRun = 1
for _, dirname := range allPackagesInFS(arg) {
+ if strings.Contains(dirname[len(trimmedArg):], "/vendor/") {
+ continue
+ }
args = append(args, dirname)
}
} else if isDir(arg) {
To view, visit change 96085. To unsubscribe, or for help writing mail filters, visit settings.
Congratulations on opening your first change. Thank you for your contribution!
Next steps:
Within the next week or so, a maintainer will review your change and provide
feedback. See https://golang.org/doc/contribute.html#review for more info and
tips to get your patch through code review.
Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.
During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11, it means that this CL will be reviewed as part of the next development
cycle. See https://golang.org/s/release for more details.
See previous comments:
https://github.com/golang/lint/pull/325#issuecomment-364845741
https://github.com/golang/lint/pull/325#issuecomment-365101260
Tested with Debian Testing and Windows Server 2016. It seems to properly handle edge cases with vendor expansion.
Edge Cases: https://golang.org/cmd/go/#hdr-Description_of_package_lists
Test Repo: https://github.com/josephlr/golint-325
Patch set 1:Code-Review +1
Please take a look.
1 comment:
Patch Set #1, Line 54: if strings.Contains(dirname[len(trimmedArg):], "/vendor/") {
If arg is a relative path that starts with "vendor/", this check won't match it.
Usually this pattern requires two checks, Contains("/x/") || HasPrefix("x/").
To view, visit change 96085. To unsubscribe, or for help writing mail filters, visit settings.
Given the long back and forth with this small change, can we please add a test for the matching logic, here?
Daniel Martí abandoned this change.
To view, visit change 96085. To unsubscribe, or for help writing mail filters, visit settings.