Skip to content

x/tools/go/analysis: provide driver for running analysis programmatically #31897

Closed
@muirdm

Description

@muirdm

Currently there is no driver suitable for running analyzers from a go test (or from code, in general). The multichecker and singlechecker drivers are meant for cli tools and call os.Exit(), so they cannot be used.

We want to be able to run analysis from a go test rather than a separate binary. It is easier to integrate into our CI system if is a normal test.

My first thought was something that looks like this:

func Run(args []string, analyzers []*analysis.Analyzer) ([]analysis.Diagnostic, error)

Returning Diagnostic is not quite right though since the user doesn't have the FileSet to translate the diagnostics' token.Pos. I also assume something would have to be done for passing analyzer flags programatically.

/cc @ianthehat since you responded briefly in Slack regarding this feature request

Metadata

Metadata

Assignees

Labels

AnalysisIssues related to static analysis (vet, x/tools/go/analysis)NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions