...

Source file src/cmd/vet/doc.go

Documentation: cmd/vet

     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  	httpresponse     check for mistakes using HTTP responses
    44  	ifaceassert      detect impossible interface-to-interface type assertions
    45  	loopclosure      check references to loop variables from within nested functions
    46  	lostcancel       check cancel func returned by context.WithCancel is called
    47  	nilfunc          check for useless comparisons between functions and nil
    48  	printf           check consistency of Printf format strings and arguments
    49  	shift            check for shifts that equal or exceed the width of the integer
    50  	sigchanyzer      check for unbuffered channel of os.Signal
    51  	slog             check for invalid structured logging calls
    52  	stdmethods       check signature of methods of well-known interfaces
    53  	stringintconv    check for string(int) conversions
    54  	structtag        check that struct field tags conform to reflect.StructTag.Get
    55  	testinggoroutine report calls to (*testing.T).Fatal from goroutines started by a test
    56  	tests            check for common mistaken usages of tests and examples
    57  	timeformat       check for calls of (time.Time).Format or time.Parse with 2006-02-01
    58  	unmarshal        report passing non-pointer or non-interface values to unmarshal
    59  	unreachable      check for unreachable code
    60  	unsafeptr        check for invalid conversions of uintptr to unsafe.Pointer
    61  	unusedresult     check for unused results of calls to some functions
    62  
    63  For details and flags of a particular check, such as printf, run "go tool vet help printf".
    64  
    65  By default, all checks are performed.
    66  If any flags are explicitly set to true, only those tests are run.
    67  Conversely, if any flag is explicitly set to false, only those tests are disabled.
    68  Thus -printf=true runs the printf check,
    69  and -printf=false runs all checks except the printf check.
    70  
    71  For information on writing a new check, see golang.org/x/tools/go/analysis.
    72  
    73  Core flags:
    74  
    75  	-c=N
    76  	  	display offending line plus N lines of surrounding context
    77  	-json
    78  	  	emit analysis diagnostics (and errors) in JSON format
    79  */
    80  package main
    81  

View as plain text