github.com/4ad/go@v0.0.0-20161219182952-69a12818b605/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  Failure to call the cancelation function returned by context.WithCancel.
    95  
    96  Flag: -lostcancel
    97  
    98  The cancelation function returned by context.WithCancel, WithTimeout,
    99  and WithDeadline must be called or the new context will remain live
   100  until its parent context is cancelled.
   101  (The background context is never cancelled.)
   102  
   103  Methods
   104  
   105  Flag: -methods
   106  
   107  Non-standard signatures for methods with familiar names, including:
   108  	Format GobEncode GobDecode MarshalJSON MarshalXML
   109  	Peek ReadByte ReadFrom ReadRune Scan Seek
   110  	UnmarshalJSON UnreadByte UnreadRune WriteByte
   111  	WriteTo
   112  
   113  Nil function comparison
   114  
   115  Flag: -nilfunc
   116  
   117  Comparisons between functions and nil.
   118  
   119  Printf family
   120  
   121  Flag: -printf
   122  
   123  Suspicious calls to functions in the Printf family, including any functions
   124  with these names, disregarding case:
   125  	Print Printf Println
   126  	Fprint Fprintf Fprintln
   127  	Sprint Sprintf Sprintln
   128  	Error Errorf
   129  	Fatal Fatalf
   130  	Log Logf
   131  	Panic Panicf Panicln
   132  The -printfuncs flag can be used to redefine this list.
   133  If the function name ends with an 'f', the function is assumed to take
   134  a format descriptor string in the manner of fmt.Printf. If not, vet
   135  complains about arguments that look like format descriptor strings.
   136  
   137  It also checks for errors such as using a Writer as the first argument of
   138  Printf.
   139  
   140  Struct tags
   141  
   142  Range loop variables
   143  
   144  Flag: -rangeloops
   145  
   146  Incorrect uses of range loop variables in closures.
   147  
   148  Shadowed variables
   149  
   150  Flag: -shadow=false (experimental; must be set explicitly)
   151  
   152  Variables that may have been unintentionally shadowed.
   153  
   154  Shifts
   155  
   156  Flag: -shift
   157  
   158  Shifts equal to or longer than the variable's length.
   159  
   160  Flag: -structtags
   161  
   162  Struct tags that do not follow the format understood by reflect.StructTag.Get.
   163  Well-known encoding struct tags (json, xml) used with unexported fields.
   164  
   165  Unreachable code
   166  
   167  Flag: -unreachable
   168  
   169  Unreachable code.
   170  
   171  Misuse of unsafe Pointers
   172  
   173  Flag: -unsafeptr
   174  
   175  Likely incorrect uses of unsafe.Pointer to convert integers to pointers.
   176  A conversion from uintptr to unsafe.Pointer is invalid if it implies that
   177  there is a uintptr-typed word in memory that holds a pointer value,
   178  because that word will be invisible to stack copying and to the garbage
   179  collector.
   180  
   181  Unused result of certain function calls
   182  
   183  Flag: -unusedresult
   184  
   185  Calls to well-known functions and methods that return a value that is
   186  discarded.  By default, this includes functions like fmt.Errorf and
   187  fmt.Sprintf and methods like String and Error. The flags -unusedfuncs
   188  and -unusedstringmethods control the set.
   189  
   190  Other flags
   191  
   192  These flags configure the behavior of vet:
   193  
   194  	-all (default true)
   195  		Enable all non-experimental checks.
   196  	-v
   197  		Verbose mode
   198  	-printfuncs
   199  		A comma-separated list of print-like function names
   200  		to supplement the standard list.
   201  		For more information, see the discussion of the -printf flag.
   202  	-shadowstrict
   203  		Whether to be strict about shadowing; can be noisy.
   204  */
   205  package main