github.com/ader1990/go@v0.0.0-20140630135419-8c24447fa791/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 file in isolation.
    25  Package-level type-checking is disabled, so the vetting is weaker.
    26  
    27  Vet's exit code is 2 for erroneous invocation of the tool, 1 if a
    28  problem was reported, and 0 otherwise. Note that the tool does not
    29  check every possible problem and depends on unreliable heuristics
    30  so it should be used as guidance only, not as a firm indicator of
    31  program correctness.
    32  
    33  By default all checks are performed. If any flags are explicitly set
    34  to true, only those tests are run. Conversely, if any flag is
    35  explicitly set to false, only those tests are disabled.
    36  Thus -printf=true runs the printf check, -printf=false runs all checks
    37  except the printf check.
    38  
    39  Available checks:
    40  
    41  Printf family
    42  
    43  Flag: -printf
    44  
    45  Suspicious calls to functions in the Printf family, including any functions
    46  with these names, disregarding case:
    47  	Print Printf Println
    48  	Fprint Fprintf Fprintln
    49  	Sprint Sprintf Sprintln
    50  	Error Errorf
    51  	Fatal Fatalf
    52  	Panic Panicf Panicln
    53  If the function name ends with an 'f', the function is assumed to take
    54  a format descriptor string in the manner of fmt.Printf. If not, vet
    55  complains about arguments that look like format descriptor strings.
    56  
    57  It also checks for errors such as using a Writer as the first argument of
    58  Printf.
    59  
    60  Methods
    61  
    62  Flag: -methods
    63  
    64  Non-standard signatures for methods with familiar names, including:
    65  	Format GobEncode GobDecode MarshalJSON MarshalXML
    66  	Peek ReadByte ReadFrom ReadRune Scan Seek
    67  	UnmarshalJSON UnreadByte UnreadRune WriteByte
    68  	WriteTo
    69  
    70  Struct tags
    71  
    72  Flag: -structtags
    73  
    74  Struct tags that do not follow the format understood by reflect.StructTag.Get.
    75  
    76  Unkeyed composite literals
    77  
    78  Flag: -composites
    79  
    80  Composite struct literals that do not use the field-keyed syntax.
    81  
    82  Assembly declarations
    83  
    84  Flag: -asmdecl
    85  
    86  Mismatches between assembly files and Go function declarations.
    87  
    88  Useless assignments
    89  
    90  Flag: -assign
    91  
    92  Check for useless assignments.
    93  
    94  Atomic mistakes
    95  
    96  Flag: -atomic
    97  
    98  Common mistaken usages of the sync/atomic package.
    99  
   100  Build tags
   101  
   102  Flag: -buildtags
   103  
   104  Badly formed or misplaced +build tags.
   105  
   106  Copying locks
   107  
   108  Flag: -copylocks
   109  
   110  Locks that are erroneously passed by value.
   111  
   112  Nil function comparison
   113  
   114  Flag: -nilfunc
   115  
   116  Comparisons between functions and nil.
   117  
   118  Range loop variables
   119  
   120  Flag: -rangeloops
   121  
   122  Incorrect uses of range loop variables in closures.
   123  
   124  Unreachable code
   125  
   126  Flag: -unreachable
   127  
   128  Unreachable code.
   129  
   130  Shadowed variables
   131  
   132  Flag: -shadow=false (experimental; must be set explicitly)
   133  
   134  Variables that may have been unintentionally shadowed.
   135  
   136  Misuse of unsafe Pointers
   137  
   138  Flag: -unsafeptr
   139  
   140  Likely incorrect uses of unsafe.Pointer to convert integers to pointers.
   141  A conversion from uintptr to unsafe.Pointer is invalid if it implies that
   142  there is a uintptr-typed word in memory that holds a pointer value,
   143  because that word will be invisible to stack copying and to the garbage
   144  collector.
   145  
   146  Other flags
   147  
   148  These flags configure the behavior of vet:
   149  
   150  	-all (default true)
   151  		Check everything; disabled if any explicit check is requested.
   152  	-v
   153  		Verbose mode
   154  	-printfuncs
   155  		A comma-separated list of print-like functions to supplement
   156  		the standard list.  Each entry is in the form Name:N where N
   157  		is the zero-based argument position of the first argument
   158  		involved in the print: either the format or the first print
   159  		argument for non-formatted prints.  For example,
   160  		if you have Warn and Warnf functions that take an
   161  		io.Writer as their first argument, like Fprintf,
   162  			-printfuncs=Warn:1,Warnf:1
   163  	-shadowstrict
   164  		Whether to be strict about shadowing; can be noisy.
   165  	-test
   166  		For testing only: sets -all and -shadow.
   167  */
   168  package documentation