2013-05-17 14:20:39 -06:00
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Vet examines Go source code and reports suspicious constructs, such as Printf
|
|
|
|
calls whose arguments do not align with the format string. Vet uses heuristics
|
|
|
|
that do not guarantee all reports are genuine problems, but it can find errors
|
|
|
|
not caught by the compilers.
|
|
|
|
|
2014-02-24 11:44:02 -07:00
|
|
|
It can be invoked three ways:
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-02-24 11:44:02 -07:00
|
|
|
By package, from the go tool:
|
|
|
|
go vet package/path/name
|
|
|
|
vets the package whose path is provided.
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-02-24 11:44:02 -07:00
|
|
|
By files:
|
|
|
|
go tool vet source/directory/*.go
|
|
|
|
vets the files named, all of which must be in the same package.
|
|
|
|
|
|
|
|
By directory:
|
|
|
|
go tool vet source/directory
|
|
|
|
recursively descends the directory, vetting each file in isolation.
|
2014-02-24 12:39:42 -07:00
|
|
|
Package-level type-checking is disabled, so the vetting is weaker.
|
2014-02-24 11:44:02 -07:00
|
|
|
|
|
|
|
Vet's exit code is 2 for erroneous invocation of the tool, 1 if a
|
2013-05-17 14:20:39 -06:00
|
|
|
problem was reported, and 0 otherwise. Note that the tool does not
|
|
|
|
check every possible problem and depends on unreliable heuristics
|
|
|
|
so it should be used as guidance only, not as a firm indicator of
|
|
|
|
program correctness.
|
|
|
|
|
2014-03-06 22:02:49 -07:00
|
|
|
By default all checks are performed. If any flags are explicitly set
|
|
|
|
to true, only those tests are run. Conversely, if any flag is
|
|
|
|
explicitly set to false, only those tests are disabled.
|
|
|
|
Thus -printf=true runs the printf check, -printf=false runs all checks
|
|
|
|
except the printf check.
|
2013-05-17 14:20:39 -06:00
|
|
|
|
|
|
|
Available checks:
|
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Printf family
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Flag: -printf
|
2013-05-17 14:20:39 -06:00
|
|
|
|
|
|
|
Suspicious calls to functions in the Printf family, including any functions
|
2014-05-19 12:34:31 -06:00
|
|
|
with these names, disregarding case:
|
2013-05-17 14:20:39 -06:00
|
|
|
Print Printf Println
|
|
|
|
Fprint Fprintf Fprintln
|
|
|
|
Sprint Sprintf Sprintln
|
|
|
|
Error Errorf
|
|
|
|
Fatal Fatalf
|
2014-08-25 13:31:49 -06:00
|
|
|
Log Logf
|
2013-05-17 14:20:39 -06:00
|
|
|
Panic Panicf Panicln
|
|
|
|
If the function name ends with an 'f', the function is assumed to take
|
|
|
|
a format descriptor string in the manner of fmt.Printf. If not, vet
|
|
|
|
complains about arguments that look like format descriptor strings.
|
|
|
|
|
|
|
|
It also checks for errors such as using a Writer as the first argument of
|
|
|
|
Printf.
|
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Methods
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Flag: -methods
|
2013-05-17 14:20:39 -06:00
|
|
|
|
|
|
|
Non-standard signatures for methods with familiar names, including:
|
|
|
|
Format GobEncode GobDecode MarshalJSON MarshalXML
|
|
|
|
Peek ReadByte ReadFrom ReadRune Scan Seek
|
|
|
|
UnmarshalJSON UnreadByte UnreadRune WriteByte
|
|
|
|
WriteTo
|
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Struct tags
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Flag: -structtags
|
2013-05-17 14:20:39 -06:00
|
|
|
|
|
|
|
Struct tags that do not follow the format understood by reflect.StructTag.Get.
|
2014-06-13 19:44:31 -06:00
|
|
|
Well-known encoding struct tags (json, xml) used with unexported fields.
|
2013-05-17 14:20:39 -06:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Unkeyed composite literals
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Flag: -composites
|
2013-05-17 14:20:39 -06:00
|
|
|
|
2013-08-02 20:19:59 -06:00
|
|
|
Composite struct literals that do not use the field-keyed syntax.
|
2013-05-17 14:20:39 -06:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Assembly declarations
|
2013-05-17 14:20:39 -06:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Flag: -asmdecl
|
2013-05-17 14:20:39 -06:00
|
|
|
|
2014-02-12 17:05:01 -07:00
|
|
|
Mismatches between assembly files and Go function declarations.
|
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Useless assignments
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Flag: -assign
|
2014-02-12 17:05:01 -07:00
|
|
|
|
|
|
|
Check for useless assignments.
|
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Atomic mistakes
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Flag: -atomic
|
2014-02-12 17:05:01 -07:00
|
|
|
|
|
|
|
Common mistaken usages of the sync/atomic package.
|
|
|
|
|
2014-07-02 11:39:57 -06:00
|
|
|
Boolean conditions
|
|
|
|
|
|
|
|
Flag: -bool
|
|
|
|
|
|
|
|
Mistakes involving boolean operators.
|
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Build tags
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Flag: -buildtags
|
2013-05-17 14:20:39 -06:00
|
|
|
|
2014-02-12 17:05:01 -07:00
|
|
|
Badly formed or misplaced +build tags.
|
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Copying locks
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Flag: -copylocks
|
2014-02-12 17:05:01 -07:00
|
|
|
|
|
|
|
Locks that are erroneously passed by value.
|
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Nil function comparison
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Flag: -nilfunc
|
2014-02-12 17:05:01 -07:00
|
|
|
|
|
|
|
Comparisons between functions and nil.
|
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Range loop variables
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Flag: -rangeloops
|
2014-02-12 17:05:01 -07:00
|
|
|
|
|
|
|
Incorrect uses of range loop variables in closures.
|
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Unreachable code
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Flag: -unreachable
|
2014-02-12 17:05:01 -07:00
|
|
|
|
|
|
|
Unreachable code.
|
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Shadowed variables
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Flag: -shadow=false (experimental; must be set explicitly)
|
2014-02-12 17:05:01 -07:00
|
|
|
|
|
|
|
Variables that may have been unintentionally shadowed.
|
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Misuse of unsafe Pointers
|
2014-05-15 13:32:51 -06:00
|
|
|
|
2014-05-19 12:34:31 -06:00
|
|
|
Flag: -unsafeptr
|
2014-05-15 13:32:51 -06:00
|
|
|
|
|
|
|
Likely incorrect uses of unsafe.Pointer to convert integers to pointers.
|
2014-05-19 12:34:31 -06:00
|
|
|
A conversion from uintptr to unsafe.Pointer is invalid if it implies that
|
|
|
|
there is a uintptr-typed word in memory that holds a pointer value,
|
|
|
|
because that word will be invisible to stack copying and to the garbage
|
|
|
|
collector.
|
2014-02-12 17:05:01 -07:00
|
|
|
|
2014-08-29 12:17:01 -06:00
|
|
|
Shifts
|
|
|
|
|
|
|
|
Flag: -shift
|
|
|
|
|
|
|
|
Shifts equal to or longer than the variable's length.
|
|
|
|
|
2014-02-12 17:05:01 -07:00
|
|
|
Other flags
|
|
|
|
|
|
|
|
These flags configure the behavior of vet:
|
|
|
|
|
|
|
|
-all (default true)
|
|
|
|
Check everything; disabled if any explicit check is requested.
|
2013-05-17 14:20:39 -06:00
|
|
|
-v
|
|
|
|
Verbose mode
|
|
|
|
-printfuncs
|
|
|
|
A comma-separated list of print-like functions to supplement
|
|
|
|
the standard list. Each entry is in the form Name:N where N
|
|
|
|
is the zero-based argument position of the first argument
|
|
|
|
involved in the print: either the format or the first print
|
|
|
|
argument for non-formatted prints. For example,
|
|
|
|
if you have Warn and Warnf functions that take an
|
|
|
|
io.Writer as their first argument, like Fprintf,
|
|
|
|
-printfuncs=Warn:1,Warnf:1
|
2014-02-12 17:05:01 -07:00
|
|
|
-shadowstrict
|
|
|
|
Whether to be strict about shadowing; can be noisy.
|
|
|
|
-test
|
|
|
|
For testing only: sets -all and -shadow.
|
2013-05-17 14:20:39 -06:00
|
|
|
*/
|
2014-12-08 21:00:58 -07:00
|
|
|
package main // import "golang.org/x/tools/cmd/vet"
|