Go Analysis Framework: modular static analysis by go team

https://news.ycombinator.com/rss Hits: 22
Summary

Package analysis defines the interface between a modular static analysis and an analysis driver program. Background ¶A static analysis is a function that inspects a package of Go code and reports a set of diagnostics (typically mistakes in the code), and perhaps produces other results as well, such as suggested refactorings or other facts. An analysis that reports mistakes is informally called a "checker". For example, the printf checker reports mistakes in fmt.Printf format strings. A "modular" analysis is one that inspects one package at a time but can save information from a lower-level package and use it when inspecting a higher-level package, analogous to separate compilation in a toolchain. The printf checker is modular: when it discovers that a function such as log.Fatalf delegates to fmt.Printf, it records this fact, and checks calls to that function too, including calls made from another package. By implementing a common interface, checkers from a variety of sources can be easily selected, incorporated, and reused in a wide range of driver programs including command-line tools (such as vet), text editors and IDEs, build and test systems (such as go build, Bazel, or Buck), test frameworks, code review tools, code-base indexers (such as SourceGraph), documentation viewers (such as godoc), batch pipelines for large code bases, and so on. Analyzer ¶The primary type in the API is Analyzer. An Analyzer statically describes an analysis function: its name, documentation, flags, relationship to other analyzers, and of course, its logic. To define an analysis, a user declares a (logically constant) variable of type Analyzer. Here is a typical example from one of the analyzers in the go/analysis/passes/ subdirectory: package unusedresult var Analyzer = &analysis.Analyzer{ Name: "unusedresult", Doc: "check for unused results of calls to some functions", Run: run, ... } func run(pass *analysis.Pass) (interface{}, error) { ... } An analysis driver is a program such as ve...

First seen: 2026-07-26 13:59

Last seen: 2026-07-27 11:26