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