Documentation
¶
Overview ¶
The unitchecker package defines the main function for an analysis driver that analyzes a single compilation unit during a build. It is invoked by a build system such as "go vet":
$ go vet -vettool=$(which vet)
It supports the following command-line protocol:
-V=full describe executable (to the build tool) -flags describe flags (to the build tool) foo.cfg description of compilation unit (from the build tool)
This package does not depend on go/packages. If you need a standalone tool, use multichecker, which supports this mode but can also load packages from source using go/packages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Main ¶
Main is the main function of a vet-like analysis tool that must be invoked by a build system to analyze a single package.
The protocol required by 'go vet -vettool=...' is that the tool must support:
-flags describe flags in JSON -V=full describe executable for build caching foo.cfg perform separate modular analyze on the single unit described by a JSON config file foo.cfg.
Also, subject to approval of proposal #71859:
-fix don't print each diagnostic, apply its first fix -diff don't apply a fix, print the diff (requires -fix)
Additionally, the environment variable GOVET has the value "vet" or "fix" depending on whether the command is being invoked by "go vet", to report diagnostics, or "go fix", to apply fixes. This is necessary so that callers of Main can select their analyzer suite before flag parsing. (Vet analyzers must report real code problems, whereas Fix analyzers may fix non-problems such as style issues.)
Types ¶
type Config ¶
type Config struct { ID string // e.g. "fmt [fmt.test]" Compiler string // gc or gccgo, provided to MakeImporter Dir string // (unused) ImportPath string // package path GoVersion string // minimum required Go version, such as "go1.21.0" GoFiles []string NonGoFiles []string IgnoredFiles []string ModulePath string // module path ModuleVersion string // module version ImportMap map[string]string // maps import path to package path PackageFile map[string]string // maps package path to file of type information Standard map[string]bool // package belongs to standard library PackageVetx map[string]string // maps package path to file of fact information VetxOnly bool // run analysis only for facts, not diagnostics VetxOutput string // where to write file of fact information SucceedOnTypecheckFailure bool }
A Config describes a compilation unit to be analyzed. It is provided to the tool in a JSON-encoded file whose name ends with ".cfg".