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