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