github.com/FenixAra/go@v0.0.0-20170127160404-96ea0918e670/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 HTTP responses used incorrectly 88 89 Flag: -httpresponse 90 91 Mistakes deferring a function call on an HTTP response before 92 checking whether the error returned with the response was nil. 93 94 Failure to call the cancelation function returned by 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 Range loop variables 141 142 Flag: -rangeloops 143 144 Incorrect uses of range loop variables in closures. 145 146 Shadowed variables 147 148 Flag: -shadow=false (experimental; must be set explicitly) 149 150 Variables that may have been unintentionally shadowed. 151 152 Shifts 153 154 Flag: -shift 155 156 Shifts equal to or longer than the variable's length. 157 158 Struct tags 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 Tests and documentation examples 166 167 Flag: -tests 168 169 Mistakes involving tests including functions with incorrect names or signatures 170 and example tests that document identifiers not in the package. 171 172 Unreachable code 173 174 Flag: -unreachable 175 176 Unreachable code. 177 178 Misuse of unsafe Pointers 179 180 Flag: -unsafeptr 181 182 Likely incorrect uses of unsafe.Pointer to convert integers to pointers. 183 A conversion from uintptr to unsafe.Pointer is invalid if it implies that 184 there is a uintptr-typed word in memory that holds a pointer value, 185 because that word will be invisible to stack copying and to the garbage 186 collector. 187 188 Unused result of certain function calls 189 190 Flag: -unusedresult 191 192 Calls to well-known functions and methods that return a value that is 193 discarded. By default, this includes functions like fmt.Errorf and 194 fmt.Sprintf and methods like String and Error. The flags -unusedfuncs 195 and -unusedstringmethods control the set. 196 197 Other flags 198 199 These flags configure the behavior of vet: 200 201 -all (default true) 202 Enable all non-experimental checks. 203 -v 204 Verbose mode 205 -printfuncs 206 A comma-separated list of print-like function names 207 to supplement the standard list. 208 For more information, see the discussion of the -printf flag. 209 -shadowstrict 210 Whether to be strict about shadowing; can be noisy. 211 */ 212 package main