github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/tools/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 all checks are performed. If any flags are explicitly set 33 to true, only those tests are run. Conversely, if any flag is 34 explicitly set to false, only those tests are disabled. 35 Thus -printf=true runs the printf check, -printf=false runs all checks 36 except the printf check. 37 38 Available checks: 39 40 Assembly declarations 41 42 Flag: -asmdecl 43 44 Mismatches between assembly files and Go function declarations. 45 46 Useless assignments 47 48 Flag: -assign 49 50 Check for useless assignments. 51 52 Atomic mistakes 53 54 Flag: -atomic 55 56 Common mistaken usages of the sync/atomic package. 57 58 Boolean conditions 59 60 Flag: -bool 61 62 Mistakes involving boolean operators. 63 64 Build tags 65 66 Flag: -buildtags 67 68 Badly formed or misplaced +build tags. 69 70 Unkeyed composite literals 71 72 Flag: -composites 73 74 Composite struct literals that do not use the field-keyed syntax. 75 76 Copying locks 77 78 Flag: -copylocks 79 80 Locks that are erroneously passed by value. 81 82 Documentation examples 83 84 Flag: -example 85 86 Mistakes involving example tests, including examples with incorrect names or 87 function signatures, or that document identifiers not in the package. 88 89 Methods 90 91 Flag: -methods 92 93 Non-standard signatures for methods with familiar names, including: 94 Format GobEncode GobDecode MarshalJSON MarshalXML 95 Peek ReadByte ReadFrom ReadRune Scan Seek 96 UnmarshalJSON UnreadByte UnreadRune WriteByte 97 WriteTo 98 99 Nil function comparison 100 101 Flag: -nilfunc 102 103 Comparisons between functions and nil. 104 105 Printf family 106 107 Flag: -printf 108 109 Suspicious calls to functions in the Printf family, including any functions 110 with these names, disregarding case: 111 Print Printf Println 112 Fprint Fprintf Fprintln 113 Sprint Sprintf Sprintln 114 Error Errorf 115 Fatal Fatalf 116 Log Logf 117 Panic Panicf Panicln 118 If the function name ends with an 'f', the function is assumed to take 119 a format descriptor string in the manner of fmt.Printf. If not, vet 120 complains about arguments that look like format descriptor strings. 121 122 It also checks for errors such as using a Writer as the first argument of 123 Printf. 124 125 Range loop variables 126 127 Flag: -rangeloops 128 129 Incorrect uses of range loop variables in closures. 130 131 Shadowed variables 132 133 Flag: -shadow=false (experimental; must be set explicitly) 134 135 Variables that may have been unintentionally shadowed. 136 137 Shifts 138 139 Flag: -shift 140 141 Shifts equal to or longer than the variable's length. 142 143 Struct tags 144 145 Flag: -structtags 146 147 Struct tags that do not follow the format understood by reflect.StructTag.Get. 148 Well-known encoding struct tags (json, xml) used with unexported fields. 149 150 Unreachable code 151 152 Flag: -unreachable 153 154 Unreachable code. 155 156 Misuse of unsafe Pointers 157 158 Flag: -unsafeptr 159 160 Likely incorrect uses of unsafe.Pointer to convert integers to pointers. 161 A conversion from uintptr to unsafe.Pointer is invalid if it implies that 162 there is a uintptr-typed word in memory that holds a pointer value, 163 because that word will be invisible to stack copying and to the garbage 164 collector. 165 166 Unused result of certain function calls 167 168 Flag: -unusedresult 169 170 Calls to well-known functions and methods that return a value that is 171 discarded. By default, this includes functions like fmt.Errorf and 172 fmt.Sprintf and methods like String and Error. The flags -unusedfuncs 173 and -unusedstringmethods control the set. 174 175 Other flags 176 177 These flags configure the behavior of vet: 178 179 -all (default true) 180 Check everything; disabled if any explicit check is requested. 181 -v 182 Verbose mode 183 -printfuncs 184 A comma-separated list of print-like functions to supplement 185 the standard list. Each entry is in the form Name:N where N 186 is the zero-based argument position of the first argument 187 involved in the print: either the format or the first print 188 argument for non-formatted prints. For example, 189 if you have Warn and Warnf functions that take an 190 io.Writer as their first argument, like Fprintf, 191 -printfuncs=Warn:1,Warnf:1 192 -shadowstrict 193 Whether to be strict about shadowing; can be noisy. 194 -test 195 For testing only: sets -all and -shadow. 196 */ 197 package main // import "golang.org/x/tools/cmd/vet"