-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
Comments
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
CC @alandonovan |
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! |
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. |
I'll close since there's already a proposal and just needs implementation / review. |
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 leveragegolang.org/x/tools/go/analysis
and applying suggested fixes but don't necessarily look exactly like running an analyzer viasinglechecker.Main
ormultichecker.Main
from the user's standpoint (i.e. different flags, different handling ofos.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 toos.Stdout
oros.Stderr
on its own (or at least acceptio.Writer
s 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.The text was updated successfully, but these errors were encountered: