x/tools/go/analysis/analysistest: support multiple, mutually exclusive suggested fixes #38431
Labels
FrozenDueToAge
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
A single diagnostic may have multiple suggested fixes. For example, staticcheck has an analysis that finds double negations (
!!x
) and provides two suggested fixes: turn into a single negation, or remove the double negation.analysistest doesn't support testing such an analysis. Currently, all suggested fixes get applied to the same source, and the result is compared against a single golden file. For example,
!!x
turns into!xx
. In the worst case, the final result will not even be syntactically valid.When dealing with just one diagnostic per analysis run, it would be pretty straightforward to adopt a file format like the one used by the Playground to support multiple files (https://play.golang.org/p/KLZR7NlVZNX). The virtual files could be named according to the descriptions of the suggested fixes, to avoid depending on the order of suggested fixes. This would result in a golden file looking something like this:
This, however, doesn't really work if an analysis produces multiple diagnostics, especially if different diagnostics have different sets of suggested fixes. If d1 has the fixes f1 and f2, and d2 has the fixes f1 and f3, what should the golden file look like? Should there be one virtual file for every unique suggested fix, identified by the fixes' descriptions?
I'm very open to better ideas.
/cc @matloob @ridersofrohan
The text was updated successfully, but these errors were encountered: