Go Analysis Framework: modular static analysis by go team

212 points · 88 comments on HN · read original →

Points and comments are a snapshot, not live.

Go team's modular static analysis framework, the `analysis` package, defines interfaces for composable checkers.

The `go/analysis` package provides a standard interface for modular static analysis of Go code. An `Analyzer` describes a checker (e.g., printf, nilness) with a `Run` function, dependencies via `Requires`, and optional `Fact` types for cross-package information. The `Pass` type delivers the package AST, type info, and a `Report` function for diagnostics. The framework supports parallel analysis, driver integration (vet, IDEs, build systems), and testing via `analysistest`. Subpackages `singlechecker` and `multichecker` simplify building standalone analysis commands.

What commenters are saying

Commenters noted the package is not new, having been used by many linters for years. The thread centered on a debate about Go's verbosity, error handling, and generics. One camp praised Go's explicit error handling and forced formatting as a readability aid. The other camp criticized the verbosity, citing error boilerplate and the lack of built-in generics-based utilities as a performance trap. A specific correction pointed out that a handwritten `Contains` loop copies values, while `slices.Contains` uses an index.