Source file src/cmd/vet/doc.go

     1  // Copyright 2018 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  Vet examines Go source code and reports suspicious constructs, such as Printf
     7  calls whose arguments do not align with the format string. Vet uses heuristics
     8  that do not guarantee all reports are genuine problems, but it can find errors
     9  not caught by the compilers.
    10  
    11  Vet is normally invoked through the go command.
    12  This command vets the package in the current directory:
    13  
    14  	go vet
    15  
    16  whereas this one vets the packages whose path is provided:
    17  
    18  	go vet my/project/...
    19  
    20  Use "go help packages" to see other ways of specifying which packages to vet.
    21  
    22  Vet's exit code is non-zero for erroneous invocation of the tool or if a
    23  problem was reported, and 0 otherwise. Note that the tool does not
    24  check every possible problem and depends on unreliable heuristics,
    25  so it should be used as guidance only, not as a firm indicator of
    26  program correctness.
    27  
    28  To list the available checks, run "go tool vet help":
    29  
    30  	appends          check for missing values after append
    31  	asmdecl          report mismatches between assembly files and Go declarations
    32  	assign           check for useless assignments
    33  	atomic           check for common mistakes using the sync/atomic package
    34  	bools            check for common mistakes involving boolean operators
    35  	buildtag         check //go:build and // +build directives
    36  	cgocall          detect some violations of the cgo pointer passing rules
    37  	composites       check for unkeyed composite literals
    38  	copylocks        check for locks erroneously passed by value
    39  	defers           report common mistakes in defer statements
    40  	directive        check Go toolchain directives such as //go:debug
    41  	errorsas         report passing non-pointer or non-error values to errors.As
    42  	framepointer     report assembly that clobbers the frame pointer before saving it
    43  	hostport         check format of addresses passed to net.Dial
    44  	httpresponse     check for mistakes using HTTP responses
    45  	ifaceassert      detect impossible interface-to-interface type assertions
    46  	loopclosure      check references to loop variables from within nested functions
    47  	lostcancel       check cancel func returned by context.WithCancel is called
    48  	nilfunc          check for useless comparisons between functions and nil
    49  	printf           check consistency of Printf format strings and arguments
    50  	shift            check for shifts that equal or exceed the width of the integer
    51  	sigchanyzer      check for unbuffered channel of os.Signal
    52  	slog             check for invalid structured logging calls
    53  	stdmethods       check signature of methods of well-known interfaces
    54  	stdversion       report uses of too-new standard library symbols
    55  	stringintconv    check for string(int) conversions
    56  	structtag        check that struct field tags conform to reflect.StructTag.Get
    57  	testinggoroutine report calls to (*testing.T).Fatal from goroutines started by a test
    58  	tests            check for common mistaken usages of tests and examples
    59  	timeformat       check for calls of (time.Time).Format or time.Parse with 2006-02-01
    60  	unmarshal        report passing non-pointer or non-interface values to unmarshal
    61  	unreachable      check for unreachable code
    62  	unsafeptr        check for invalid conversions of uintptr to unsafe.Pointer
    63  	unusedresult     check for unused results of calls to some functions
    64  	waitgroup        check for misuses of sync.WaitGroup
    65  
    66  For details and flags of a particular check, such as printf, run "go tool vet help printf".
    67  
    68  By default, all checks are performed.
    69  If any flags are explicitly set to true, only those tests are run.
    70  Conversely, if any flag is explicitly set to false, only those tests are disabled.
    71  Thus -printf=true runs the printf check,
    72  and -printf=false runs all checks except the printf check.
    73  
    74  For information on writing a new check, see golang.org/x/tools/go/analysis.
    75  
    76  Core flags:
    77  
    78  	-c=N
    79  	  	display offending line plus N lines of surrounding context
    80  	-json
    81  	  	emit analysis diagnostics (and errors) in JSON format
    82  */
    83  package main
    84  

View as plain text