From 0d405af12f63e9c431f3af4860bbd151b945f162 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 14 Jun 2017 14:52:01 +0200 Subject: [PATCH 1/5] golint: add flag to ignore vendor dirs A typical usage for a project is: golint ./... Scanning all vendored packages creates noise, takes time and is usually not useful. Add -vendor flag that controls inclusion of vendor dirs during ... expansion. Note: this changes default behavior as the default value for the flag is false. This is debatable. The rationale for false is: - go tool at tip ignores vendor during fmt and test - people generally don't want to change vendored packages, especially for style --- golint/golint.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/golint/golint.go b/golint/golint.go index d8360ad3..cced794b 100644 --- a/golint/golint.go +++ b/golint/golint.go @@ -22,6 +22,7 @@ import ( var ( minConfidence = flag.Float64("min_confidence", 0.8, "minimum confidence of a problem to print it") setExitStatus = flag.Bool("set_exit_status", false, "set exit status to 1 if any issues are found") + checkVendor = flag.Bool("vendor", false, "include packages in vendor dirs when expanding ...") suggestions int ) @@ -51,6 +52,9 @@ func main() { if strings.HasSuffix(arg, "/...") && isDir(arg[:len(arg)-len("/...")]) { dirsRun = 1 for _, dirname := range allPackagesInFS(arg) { + if !*checkVendor && strings.Contains("/" + dirname, "/vendor/") { + continue + } args = append(args, dirname) } } else if isDir(arg) { From 8818d615d442026b0d6fdf88a62fbbe1e2aa74e7 Mon Sep 17 00:00:00 2001 From: Kanitkorn S Date: Mon, 4 Sep 2017 12:56:38 +0700 Subject: [PATCH 2/5] Fix codestyle on /golint/golint.go --- golint/golint.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/golint/golint.go b/golint/golint.go index cced794b..a3ba9cce 100644 --- a/golint/golint.go +++ b/golint/golint.go @@ -22,7 +22,7 @@ import ( var ( minConfidence = flag.Float64("min_confidence", 0.8, "minimum confidence of a problem to print it") setExitStatus = flag.Bool("set_exit_status", false, "set exit status to 1 if any issues are found") - checkVendor = flag.Bool("vendor", false, "include packages in vendor dirs when expanding ...") + checkVendor = flag.Bool("vendor", false, "include packages in vendor dirs when expanding ...") suggestions int ) From c3b1f712978acc170688ad48e06b4dc3ac536ce5 Mon Sep 17 00:00:00 2001 From: Kanitkorn S Date: Tue, 12 Sep 2017 18:58:07 +0700 Subject: [PATCH 3/5] Remove `-vendor` flag from the command --- golint/golint.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/golint/golint.go b/golint/golint.go index a3ba9cce..02d2ca18 100644 --- a/golint/golint.go +++ b/golint/golint.go @@ -22,7 +22,6 @@ import ( var ( minConfidence = flag.Float64("min_confidence", 0.8, "minimum confidence of a problem to print it") setExitStatus = flag.Bool("set_exit_status", false, "set exit status to 1 if any issues are found") - checkVendor = flag.Bool("vendor", false, "include packages in vendor dirs when expanding ...") suggestions int ) @@ -52,7 +51,7 @@ func main() { if strings.HasSuffix(arg, "/...") && isDir(arg[:len(arg)-len("/...")]) { dirsRun = 1 for _, dirname := range allPackagesInFS(arg) { - if !*checkVendor && strings.Contains("/" + dirname, "/vendor/") { + if strings.Contains("/"+dirname, "/vendor/") { continue } args = append(args, dirname) From ab1f5eef69b52c294f4c5a1ce6e02571b693617b Mon Sep 17 00:00:00 2001 From: Kanitkorn S Date: Tue, 12 Sep 2017 19:53:47 +0700 Subject: [PATCH 4/5] Lint `/vendor/` if it's specified in args --- golint/golint.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/golint/golint.go b/golint/golint.go index 02d2ca18..c54dd942 100644 --- a/golint/golint.go +++ b/golint/golint.go @@ -47,11 +47,12 @@ func main() { // checks are run. It is no valid to mix target types. var dirsRun, filesRun, pkgsRun int var args []string - for _, arg := range flag.Args() { - if strings.HasSuffix(arg, "/...") && isDir(arg[:len(arg)-len("/...")]) { + for _, arg := range flag.Args() { + basePath := arg[:len(arg)-len("/...")] + if strings.HasSuffix(arg, "/...") && isDir(basePath) { dirsRun = 1 for _, dirname := range allPackagesInFS(arg) { - if strings.Contains("/"+dirname, "/vendor/") { + if strings.Contains(dirname[len(basePath):], "/vendor/") { continue } args = append(args, dirname) From 0dcd199f6e2c9e5fb738b78bfa2170de4c78a25f Mon Sep 17 00:00:00 2001 From: Kanitkorn S Date: Tue, 23 Jan 2018 15:51:37 +0700 Subject: [PATCH 5/5] Fix command panic with a short arg More info: https://github.com/golang/lint/pull/325#discussion_r163038294 --- golint/golint.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/golint/golint.go b/golint/golint.go index c54dd942..00882749 100644 --- a/golint/golint.go +++ b/golint/golint.go @@ -47,12 +47,11 @@ func main() { // checks are run. It is no valid to mix target types. var dirsRun, filesRun, pkgsRun int var args []string - for _, arg := range flag.Args() { - basePath := arg[:len(arg)-len("/...")] - if strings.HasSuffix(arg, "/...") && isDir(basePath) { + for _, arg := range flag.Args() { + if trimmedArg := strings.TrimSuffix(arg, "/..."); trimmedArg != arg && isDir(trimmedArg) { dirsRun = 1 for _, dirname := range allPackagesInFS(arg) { - if strings.Contains(dirname[len(basePath):], "/vendor/") { + if strings.Contains(dirname[len(trimmedArg):], "/vendor/") { continue } args = append(args, dirname)