fix(align): strip field comments from both diff sides#89
Merged
Conversation
Upstream fieldalignment clears each field's Doc/Comment when building the suggested-fix text (golang/go#20744), so the proposed side of the diff never carried comments while the original side — read from raw source — did. A pure reordering therefore looked like it also deleted the field comments. Normalize both sides through a shared reprint helper that drops comments (by parsing without ParseComments) and keeps tags only when -tags is set, so the side-by-side diff shows only the reordering. Closes #88 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In side-by-side (and unified) diff mode, the current column showed trailing/doc comments after field definitions while the proposed column omitted them — making a pure reordering look like it also deleted the field comments.
Root cause
Upstream
fieldalignmentdeliberately clears each field'sDoc/Commentwhen building the suggested-fix text (f.Comment = nil; f.Doc = nil, TODO golang/go#20744). structalign readsOriginalfrom raw source (comments intact) but takesProposedstraight from that comment-less fix text — hence the asymmetry.Fix
Replace the conditional tag-strip with a single
normalizeStruct(src, keepTags)helper applied to both sides. It drops per-field comments (by parsing withoutparser.ParseComments, so they never enter the AST) and clears tags only when-tagsis unset. Both columns now go through the same reprint, so they stay symmetric and the diff shows only the reordering.Verification
TestNormalizeStructStripsComments,TestFindingsStripsCommentsFromBothSides,TestFindingsKeepTagsStillStripsComments(comments gone on both sides regardless of-tags; tags survive when-tagsis set).task cigreen; manually reproduced againstpkg/common.Layout— both columns now comment-free.Closes #88
🤖 Generated with Claude Code