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

Activity

added this to the Unreleased milestone on May 7, 2019
added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on May 8, 2019
matloob

matloob commented on Jun 6, 2019

@matloob
Contributor

Hi, could you provide more information about your use case?

Are you trying to test analyses or are you trying to create a test that runs analyses on other packages in your project?

muirdm

muirdm commented on Jun 6, 2019

@muirdm
Author

The latter: trying to run analyzers against packages in our project via a go test. I tweaked the title to deemphasize the test part since I know it is confusing.

changed the title [-]x/tools/go/analysis: provide driver for running analysis in test[/-] [+]x/tools/go/analysis: provide driver for running analysis programmatically[/+] on Jun 6, 2019
mikesep

mikesep commented on Jun 6, 2019

@mikesep

I'm interested in a similar use case. I'm working on a tool to run my Analyzer against packages to gather information, after which I'll want to do some final overall analysis on the collected data and output a report.

fatih

fatih commented on Jun 7, 2019

@fatih
Member

I just recently stumbled into the same problem. I wanted to run a long running service and not use any of the drivers (i.e: singlechecker) as those abstract more than I want.

matloob

matloob commented on Jun 19, 2019

@matloob
Contributor

I think the best way to move forward on this is to add such a library in an external package (outside of tools) and let it bake a little. I don't think there's anything (other than the obvious visibility and accessibility to potential users) that requires this to be in tools.

Once it's used more and we're happy with it we can move it back to tools.

On a related note, it would be nice if we had some sort of playground with fewer stability requirements than tools to do experiments in. As it is now once we add anything it's pretty much there forever and we can't make any changes.....

added
ToolsThis label describes issues relating to any tools in the x/tools repository.
on Sep 12, 2019
self-assigned this
on Jun 14, 2022
gopherbot

gopherbot commented on Jun 14, 2022

@gopherbot
Contributor

Change https://go.dev/cl/411907 mentions this issue: go/analysis/checker: a go/packages-based driver library

10 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @cce@mikesep@andybons@fatih@Merovius

      Issue actions

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