Skip to content

fix(align): strip field comments from both diff sides#89

Merged
peczenyj merged 2 commits into
develfrom
fix/diff-comment-symmetry
May 29, 2026
Merged

fix(align): strip field comments from both diff sides#89
peczenyj merged 2 commits into
develfrom
fix/diff-comment-symmetry

Conversation

@peczenyj
Copy link
Copy Markdown
Owner

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.

  current                                            │ proposed
  ───────────────────────────────────────────────────┼─────────────────────────
  type Layout struct {                               │ type Layout struct {
      TypeParams string // for a generic type ("[T]")│     TypeParams string
      Note       string // optional caveat shown ... │     Note       string

Root cause

Upstream fieldalignment deliberately clears each field's Doc/Comment when building the suggested-fix text (f.Comment = nil; f.Doc = nil, TODO golang/go#20744). structalign reads Original from raw source (comments intact) but takes Proposed straight 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 without parser.ParseComments, so they never enter the AST) and clears tags only when -tags is unset. Both columns now go through the same reprint, so they stay symmetric and the diff shows only the reordering.

Verification

  • New unit tests: TestNormalizeStructStripsComments, TestFindingsStripsCommentsFromBothSides, TestFindingsKeepTagsStillStripsComments (comments gone on both sides regardless of -tags; tags survive when -tags is set).
  • Existing golden fixtures unchanged (the sample structs have no comments).
  • task ci green; manually reproduced against pkg/common.Layout — both columns now comment-free.

Closes #88

🤖 Generated with Claude Code

peczenyj and others added 2 commits May 29, 2026 11:38
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>
@peczenyj peczenyj merged commit 4d12d6a into devel May 29, 2026
6 checks passed
@peczenyj peczenyj self-assigned this May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Side-by-side diff drops field comments on the proposed side only

1 participant