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