go/analysis/cmd/vet: new name for cmd/analyze

This is the new vet command. It can be run standalone:

	$ vet my/project/...

or (soon) under go vet:

	$ GOVETTOOL=$(which vet) go vet my/project/...

A forthcoming CL will add support for the second mode, and define a
vet-lite command that supports only that mode, but has fewer
dependencies; it is intended to be vendored into $GOROOT/src/cmd/vet.

Change-Id: I57696ae6d43aa31fd10b370247b7e7497f0f3597
Reviewed-on: https://go-review.googlesource.com/c/143417
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
This commit is contained in:
Alan Donovan 2018-10-19 13:50:20 -04:00
parent 5efdaf2100
commit 9545aa7b51
4 changed files with 12 additions and 11 deletions

View File

@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// The analyze command is a static checker for Go programs, similar to // The vet command is a static checker for Go programs. It has pluggable
// vet, but with pluggable analyzers defined using the analysis // analyzers defined using the golang.org/x/tools/go/analysis API, and
// interface, and using the go/packages API to load packages in any // using the golang.org/x/tools/go/packages API to load packages in any
// build system. // build system.
// //
// Each analysis flag name is preceded by the analysis name: --analysis.flag. // Each analysis flag name is preceded by the analysis name: --analysis.flag.

View File

@ -72,15 +72,15 @@ To add a new Analyzer to an existing driver, add another item to the list:
A driver may use the name, flags, and documentation to provide on-line A driver may use the name, flags, and documentation to provide on-line
help that describes the analyses its performs. help that describes the analyses its performs.
The "analyze" command, shown below, is an example of a driver that runs The vet command, shown below, is an example of a driver that runs
multiple analyzers. It is based on the multichecker package multiple analyzers. It is based on the multichecker package
(see the "Standalone commands" section for details). (see the "Standalone commands" section for details).
$ go build golang.org/x/tools/cmd/analyze $ go build golang.org/x/tools/cmd/vet
$ ./analyze help $ ./vet help
Analyze is a tool for static analysis of Go programs. vet is a tool for static analysis of Go programs.
Usage: analyze [-flag] [package] Usage: vet [-flag] [package]
Registered analyzers: Registered analyzers:
@ -90,7 +90,7 @@ multiple analyzers. It is based on the multichecker package
... ...
unusedresult check for unused results of calls to some functions unusedresult check for unused results of calls to some functions
$ ./analyze help unusedresult $ ./vet help unusedresult
unusedresult: check for unused results of calls to some functions unusedresult: check for unused results of calls to some functions
Analyzer flags: Analyzer flags:

View File

@ -54,8 +54,9 @@ func Main(analyzers ...*analysis.Analyzer) {
args := flag.Args() args := flag.Args()
if len(args) == 0 { if len(args) == 0 {
fmt.Fprintln(os.Stderr, strings.ReplaceAll(usage, "PROGNAME", progname)) fmt.Fprintln(os.Stderr, strings.ReplaceAll(usage, "PROGNAME", progname))
fmt.Fprintf(os.Stderr, `Run '%[1]s help' for more detail, fmt.Fprintf(os.Stderr, "Run '%[1]s help' for more detail,\n"+
or '%[1]s help name' for details and flags of a specific analyzer.\n`, progname) " or '%[1]s help name' for details and flags of a specific analyzer.\n",
progname)
os.Exit(1) os.Exit(1)
} }