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-12 17:05:01 -07:00
|
|
|
Usage:
|
|
|
|
|
|
|
|
go tool vet [flag] [file.go ...]
|
|
|
|
go tool vet [flag] [directory ...] # Scan all .go files under directory, recursively
|
|
|
|
|
2013-05-17 14:20:39 -06:00
|
|
|
Its exit code is 2 for erroneous invocation of the tool, 1 if a
|
|
|
|
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.
|
|
|
|
|
|
|
|
By default all checks are performed, but if explicit flags are provided, only
|
|
|
|
those identified by the flags are performed.
|
|
|
|
|
|
|
|
Available checks:
|
|
|
|
|
2014-02-12 17:05:01 -07:00
|
|
|
1. Printf family
|
|
|
|
|
|
|
|
Flag -printf
|
2013-05-17 14:20:39 -06:00
|
|
|
|
|
|
|
Suspicious calls to functions in the Printf family, including any functions
|
|
|
|
with these names:
|
|
|
|
Print Printf Println
|
|
|
|
Fprint Fprintf Fprintln
|
|
|
|
Sprint Sprintf Sprintln
|
|
|
|
Error Errorf
|
|
|
|
Fatal Fatalf
|
|
|
|
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-02-12 17:05:01 -07:00
|
|
|
2. Methods
|
|
|
|
|
|
|
|
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-02-12 17:05:01 -07:00
|
|
|
3. Struct tags
|
|
|
|
|
|
|
|
Flag -structtags
|
2013-05-17 14:20:39 -06:00
|
|
|
|
|
|
|
Struct tags that do not follow the format understood by reflect.StructTag.Get.
|
|
|
|
|
2014-02-12 17:05:01 -07:00
|
|
|
4. Unkeyed composite literals
|
|
|
|
|
|
|
|
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-02-12 17:05:01 -07:00
|
|
|
5. Assembly declarations
|
2013-05-17 14:20:39 -06:00
|
|
|
|
2014-02-12 17:05:01 -07: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.
|
|
|
|
|
|
|
|
6. Useless assignments
|
|
|
|
|
|
|
|
Flag -assign
|
|
|
|
|
|
|
|
Check for useless assignments.
|
|
|
|
|
|
|
|
7. Atomic mistakes
|
|
|
|
|
|
|
|
Flag -atomic
|
|
|
|
|
|
|
|
Common mistaken usages of the sync/atomic package.
|
|
|
|
|
|
|
|
8. Build tags
|
|
|
|
|
|
|
|
Flag -buildtags
|
2013-05-17 14:20:39 -06:00
|
|
|
|
2014-02-12 17:05:01 -07:00
|
|
|
Badly formed or misplaced +build tags.
|
|
|
|
|
|
|
|
9. Copying locks
|
|
|
|
|
|
|
|
Flag -copylocks
|
|
|
|
|
|
|
|
Locks that are erroneously passed by value.
|
|
|
|
|
|
|
|
10. Nil function comparison
|
|
|
|
|
|
|
|
Flag -nilfunc
|
|
|
|
|
|
|
|
Comparisons between functions and nil.
|
|
|
|
|
|
|
|
11. Range loop variables
|
|
|
|
|
|
|
|
Flag -rangeloops
|
|
|
|
|
|
|
|
Incorrect uses of range loop variables in closures.
|
|
|
|
|
|
|
|
12. Unreachable code
|
|
|
|
|
|
|
|
Flag -unreachable
|
|
|
|
|
|
|
|
Unreachable code.
|
|
|
|
|
|
|
|
13. Shadowed variables
|
|
|
|
|
|
|
|
Flag -shadow=false (experimental; must be set explicitly)
|
|
|
|
|
|
|
|
Variables that may have been unintentionally shadowed.
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
package main
|