github.com/gocuntian/go@v0.0.0-20160610041250-fee02d270bf8/src/cmd/vet/doc.go (about)

     1  // Copyright 2010 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  /*
     6  
     7  Vet examines Go source code and reports suspicious constructs, such as Printf
     8  calls whose arguments do not align with the format string. Vet uses heuristics
     9  that do not guarantee all reports are genuine problems, but it can find errors
    10  not caught by the compilers.
    11  
    12  It can be invoked three ways:
    13  
    14  By package, from the go tool:
    15  	go vet package/path/name
    16  vets the package whose path is provided.
    17  
    18  By files:
    19  	go tool vet source/directory/*.go
    20  vets the files named, all of which must be in the same package.
    21  
    22  By directory:
    23  	go tool vet source/directory
    24  recursively descends the directory, vetting each package it finds.
    25  
    26  Vet's exit code is 2 for erroneous invocation of the tool, 1 if a
    27  problem was reported, and 0 otherwise. Note that the tool does not
    28  check every possible problem and depends on unreliable heuristics
    29  so it should be used as guidance only, not as a firm indicator of
    30  program correctness.
    31  
    32  By default the -all flag is set so all checks are performed.
    33  If any flags are explicitly set to true, only those tests are run. Conversely, if
    34  any flag is explicitly set to false, only those tests are disabled.  Thus -printf=true
    35  runs the printf check, -printf=false runs all checks except the printf check.
    36  
    37  Available checks:
    38  
    39  Assembly declarations
    40  
    41  Flag: -asmdecl
    42  
    43  Mismatches between assembly files and Go function declarations.
    44  
    45  Useless assignments
    46  
    47  Flag: -assign
    48  
    49  Check for useless assignments.
    50  
    51  Atomic mistakes
    52  
    53  Flag: -atomic
    54  
    55  Common mistaken usages of the sync/atomic package.
    56  
    57  Boolean conditions
    58  
    59  Flag: -bool
    60  
    61  Mistakes involving boolean operators.
    62  
    63  Build tags
    64  
    65  Flag: -buildtags
    66  
    67  Badly formed or misplaced +build tags.
    68  
    69  Invalid uses of cgo
    70  
    71  Flag: -cgocall
    72  
    73  Detect some violations of the cgo pointer passing rules.
    74  
    75  Unkeyed composite literals
    76  
    77  Flag: -composites
    78  
    79  Composite struct literals that do not use the field-keyed syntax.
    80  
    81  Copying locks
    82  
    83  Flag: -copylocks
    84  
    85  Locks that are erroneously passed by value.
    86  
    87  Tests, benchmarks and documentation examples
    88  
    89  Flag: -tests
    90  
    91  Mistakes involving tests including functions with incorrect names or signatures
    92  and example tests that document identifiers not in the package.
    93  
    94  Methods
    95  
    96  Flag: -methods
    97  
    98  Non-standard signatures for methods with familiar names, including:
    99  	Format GobEncode GobDecode MarshalJSON MarshalXML
   100  	Peek ReadByte ReadFrom ReadRune Scan Seek
   101  	UnmarshalJSON UnreadByte UnreadRune WriteByte
   102  	WriteTo
   103  
   104  Nil function comparison
   105  
   106  Flag: -nilfunc
   107  
   108  Comparisons between functions and nil.
   109  
   110  Printf family
   111  
   112  Flag: -printf
   113  
   114  Suspicious calls to functions in the Printf family, including any functions
   115  with these names, disregarding case:
   116  	Print Printf Println
   117  	Fprint Fprintf Fprintln
   118  	Sprint Sprintf Sprintln
   119  	Error Errorf
   120  	Fatal Fatalf
   121  	Log Logf
   122  	Panic Panicf Panicln
   123  The -printfuncs flag can be used to redefine this list.
   124  If the function name ends with an 'f', the function is assumed to take
   125  a format descriptor string in the manner of fmt.Printf. If not, vet
   126  complains about arguments that look like format descriptor strings.
   127  
   128  It also checks for errors such as using a Writer as the first argument of
   129  Printf.
   130  
   131  Struct tags
   132  
   133  Range loop variables
   134  
   135  Flag: -rangeloops
   136  
   137  Incorrect uses of range loop variables in closures.
   138  
   139  Shadowed variables
   140  
   141  Flag: -shadow=false (experimental; must be set explicitly)
   142  
   143  Variables that may have been unintentionally shadowed.
   144  
   145  Shifts
   146  
   147  Flag: -shift
   148  
   149  Shifts equal to or longer than the variable's length.
   150  
   151  Flag: -structtags
   152  
   153  Struct tags that do not follow the format understood by reflect.StructTag.Get.
   154  Well-known encoding struct tags (json, xml) used with unexported fields.
   155  
   156  Unreachable code
   157  
   158  Flag: -unreachable
   159  
   160  Unreachable code.
   161  
   162  Misuse of unsafe Pointers
   163  
   164  Flag: -unsafeptr
   165  
   166  Likely incorrect uses of unsafe.Pointer to convert integers to pointers.
   167  A conversion from uintptr to unsafe.Pointer is invalid if it implies that
   168  there is a uintptr-typed word in memory that holds a pointer value,
   169  because that word will be invisible to stack copying and to the garbage
   170  collector.
   171  
   172  Unused result of certain function calls
   173  
   174  Flag: -unusedresult
   175  
   176  Calls to well-known functions and methods that return a value that is
   177  discarded.  By default, this includes functions like fmt.Errorf and
   178  fmt.Sprintf and methods like String and Error. The flags -unusedfuncs
   179  and -unusedstringmethods control the set.
   180  
   181  Other flags
   182  
   183  These flags configure the behavior of vet:
   184  
   185  	-all (default true)
   186  		Enable all non-experimental checks.
   187  	-v
   188  		Verbose mode
   189  	-printfuncs
   190  		A comma-separated list of print-like function names
   191  		to supplement the standard list.
   192  		For more information, see the discussion of the -printf flag.
   193  	-shadowstrict
   194  		Whether to be strict about shadowing; can be noisy.
   195  */
   196  package main