Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: x/tools/go/analysis: Expose something like internal/checker.Run #70152

Closed
cszczepaniak opened this issue Nov 1, 2024 · 5 comments
Closed
Labels
Milestone

Comments

@cszczepaniak
Copy link

cszczepaniak commented Nov 1, 2024

Proposal Details

The analysis package is really great for writing custom analyzers. It has also become my go-to tool for performing large-scale refactors that are more involved than a find/replace, leveraging suggested fixes + -fix. Sometimes find myself wanting to write custom tools which leverage golang.org/x/tools/go/analysis and applying suggested fixes but don't necessarily look exactly like running an analyzer via singlechecker.Main or multichecker.Main from the user's standpoint (i.e. different flags, different handling of os.Stdout, os.Stderr).

It would be really handy if there was a function similar to golang.org/x/tools/go/analysis/internal/checker.Run that I could call from my own code given an analyzer and that would return an error rather than an exit code. It would ideally also not print to os.Stdout or os.Stderr on its own (or at least accept io.Writers for these that I can provide).

Or maybe there's a better/similar way to inspect parsed/type-checked packages and transform the original source in some fashion that I'm not aware of? I've used astutil in the past for this as well, but I find the SuggestedFixes API to be much simpler to use.

@gopherbot gopherbot added this to the Proposal milestone Nov 1, 2024
@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Nov 1, 2024
@ianlancetaylor
Copy link
Member

CC @alandonovan

@cszczepaniak
Copy link
Author

This seems like it was previously accepted in #61324 (after a quick glance I couldn't tell if it specifically supported applying suggested fixes or not, but presumably it would or could) but hasn't moved too much since then -- I see a few other subsequent issues mentioned that original issue as well, so I suppose you can count this as one more vote for getting that to land!

@seankhliao seankhliao changed the title proposal: golang.org/x/tools/go/analysis: Expose something like internal/checker.Run proposal: x/tools/go/analysis: Expose something like internal/checker.Run Nov 1, 2024
@adonovan
Copy link
Member

adonovan commented Nov 1, 2024

Indeed, it has been proposed and accepted, and two years ago I even had a bunch of CLs to do the necessary reorganization, but they have since become stale. I've been meaning to spend a couple of hours to redo them but there had been little sign that anyone was waiting, so it wasn't a priority. I'll try to get to it this month.

@seankhliao
Copy link
Member

I'll close since there's already a proposal and just needs implementation / review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants