aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vet/main.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2015-09-21 10:30:04 -0700
committerRob Pike <r@golang.org>2015-09-21 17:48:38 +0000
commit7454f53604b9953b5b7a3897c6b855957f911e66 (patch)
treea1a3ada821b2f35075d4794ecdd3c16251f384f6 /src/cmd/vet/main.go
parent4e99ed6fef28bc263ec42e63fd717a13367fb659 (diff)
downloadgo-7454f53604b9953b5b7a3897c6b855957f911e66.tar.gz
go-7454f53604b9953b5b7a3897c6b855957f911e66.zip
cmd/vet: copy changes from golang.org/x/tools to cmd/vet
This means bringing over the examples flag and sorting doc.go. Subsequent changes will generalize the examples flag to a general test naming flag, but let's start with the original code. No more changes to golang.org/x/tools please. This should not have happened (and letting it happen was partly my fault). Change-Id: Ia879ea1d15d82372df14853f919263125dfb7b96 Reviewed-on: https://go-review.googlesource.com/14821 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/cmd/vet/main.go')
-rw-r--r--src/cmd/vet/main.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/cmd/vet/main.go b/src/cmd/vet/main.go
index 453cfe0ce0..fbba009d11 100644
--- a/src/cmd/vet/main.go
+++ b/src/cmd/vet/main.go
@@ -51,6 +51,14 @@ var experimental = map[string]bool{}
// setTrueCount record how many flags are explicitly set to true.
var setTrueCount int
+// dirsRun and filesRun indicate whether the vet is applied to directory or
+// file targets. The distinction affects which checks are run.
+var dirsRun, filesRun bool
+
+// includesNonTest indicates whether the vet is applied to non-test targets.
+// Certain checks are relevant only if they touch both test and non-test files.
+var includesNonTest bool
+
// A triState is a boolean that knows whether it has been set to either true or false.
// It is used to identify if a flag appears; the standard boolean flag cannot
// distinguish missing from unset. It also satisfies flag.Value.
@@ -207,8 +215,6 @@ func main() {
if flag.NArg() == 0 {
Usage()
}
- dirs := false
- files := false
for _, name := range flag.Args() {
// Is it a directory?
fi, err := os.Stat(name)
@@ -217,15 +223,18 @@ func main() {
continue
}
if fi.IsDir() {
- dirs = true
+ dirsRun = true
} else {
- files = true
+ filesRun = true
+ if !strings.HasSuffix(name, "_test.go") {
+ includesNonTest = true
+ }
}
}
- if dirs && files {
+ if dirsRun && filesRun {
Usage()
}
- if dirs {
+ if dirsRun {
for _, name := range flag.Args() {
walkDir(name)
}