Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/analysis/internal/checker: implement three-way merge
This CL adds support for three-way merging to the checker's -fix operation. It consists of three parts: 1. a rewritten applyFix function that applies as many changes as can be cleanly merged; 2. a script-based test framework that allows all existing and new tests to be written as txtar files in testdata instead of ad-hoc Go logic; and 3. a data-driven "marker" analyzer that reports diagnostics containing fixes according to //@f comments in the target Go source files. Also, it adds a -diff flag to the checker tools that causes them to print the computed file changes instead of directly applying them. The new applyFix treats each SuggestedFix as an independent change, analogous to a git commit. Fixes are combined by invoking a three-way merge algorithm, diff.Merge, analogous to git merge, except simpler since it works on the list of []diff.Edit instead of text. If any fix does not apply cleanly, we discard it, and report that we did so, with a hint to run the tool again until a fixed point is reached. (This is just a starting point; a better UX would be for the tool to do this itself.) If a diagnostic has multiple suggested fixes, we select the first one. The old behavior of attempting to apply them all makes no sense. The support for filesystem-level aliases (e.g. symbolic and hard links) previously implemented using FileID has been removed, as its interactions with the new logic were tricky. I ran gopls' modernize singlechecker on k8s/... and it was able to cleanly resolved 142 edits across 53 files; the result builds, and symbolic links were not evidently a problem. Update golang/go#68765 Update golang/go#67049 Change-Id: Id3fb55118b3d0612cafe7e86f52589812bd74a96 Reviewed-on: https://go-review.googlesource.com/c/tools/+/644835 Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Alan Donovan <adonovan@google.com>
- Loading branch information