x/tools/go/analysis/analysistest: Functionality for verifying SuggestedFixes and TextEdits #38044
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, but this is also a feature request. 😄
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Attempting to test an
*analysis.Analyzer
that reports aDiagnostic
withSuggestedFixes
andTextEdits
, e.g.What did you expect to see?
The ability or the framework to verify potential code changes via
TextEdits
.What did you see instead?
Seems like there is not a native or built-in way to test these. I wrote together a proof of concept implementation that does the following:
testdata/src/a
) and copies to a temporary directoryAnalyzer
in asinglechecker.Main
and re-executes the test with the-fix
flagtestdata/src/a_fixed
) file contents with "fixed" temporary directory file contentsFull code: https://github.com/bflad/tfproviderlint/blob/master/helper/analysisfixtest/analysisfixtest.go
Testing implementation matches
analysistest.Run
:Since the
-fix
flag is only handled by the multichecker/singlechecker drivers, this would be improved with #31897 (x/tools/go/analysis: provide driver for running analysis programmatically), rather than wrapping theAnalyzer
in a self-executing a child process.It would be wonderful if functionality like this could be baked into
go/analysis
though! Thank you for your consideration.The text was updated successfully, but these errors were encountered: