In -inspect -format=json, the tag field on each layout field is emitted unconditionally (with omitempty only as a guard against empty strings), regardless of whether -tags was passed. This is asymmetric with text inspect mode, where -tags gates tag visibility.
Reproduction
$ ./structalign -inspect -type=Tagged ./_example/
type Tagged struct { // ...
Flag bool // ... ← no tag shown
ID string // ...
}
$ ./structalign -inspect -type=Tagged -tags ./_example/
type Tagged struct { // ...
Flag bool `json:"flag"` // ... ← tag shown
}
$ diff \
<(./structalign -inspect -type=Tagged -format=json ./_example/) \
<(./structalign -inspect -type=Tagged -format=json -tags ./_example/)
# (byte-identical — both contain `"tag": "json:\"flag\""`)
Cause
internal/ui/json.go:82-91 populates Tag: f.Tag directly from the common.LayoutField. The RenderJSON method doesn't take an opt.tags parameter, and the layout phase always populates Field.Tag (internal/layout/layout.go:177).
Fix
Plumb the -tags (i.e. KeepTags) choice into RenderJSON and clear the Tag on jsonLayoutField when !keepTags, mirroring the text path. Trade-off: tooling consumers lose tag data by default — but they can opt in with -tags (or STRUCTALIGN_TAGS=true, or tags = true in .structalignrc), which is consistent with text mode.
This also means the diff-mode JSON (where original/proposed already honor -tags via align.go:90-94) becomes the natural model: -tags is the single global "include tags in output" knob, regardless of mode or format.
Scope
- Update
RenderJSON signature to accept the keep-tags choice (or pass via Printer field — match existing patterns).
- Update
app.go:300-307 call sites.
- Add a JSON inspect golden test case
inspect_tags_tagged.json.golden with and without -tags.
- Document in README's Configuration Reference table that
-tags affects both text and JSON.
In
-inspect -format=json, thetagfield on each layout field is emitted unconditionally (withomitemptyonly as a guard against empty strings), regardless of whether-tagswas passed. This is asymmetric with text inspect mode, where-tagsgates tag visibility.Reproduction
Cause
internal/ui/json.go:82-91populatesTag: f.Tagdirectly from thecommon.LayoutField. TheRenderJSONmethod doesn't take anopt.tagsparameter, and the layout phase always populatesField.Tag(internal/layout/layout.go:177).Fix
Plumb the
-tags(i.e.KeepTags) choice intoRenderJSONand clear theTagonjsonLayoutFieldwhen!keepTags, mirroring the text path. Trade-off: tooling consumers lose tag data by default — but they can opt in with-tags(orSTRUCTALIGN_TAGS=true, ortags = truein.structalignrc), which is consistent with text mode.This also means the diff-mode JSON (where
original/proposedalready honor-tagsviaalign.go:90-94) becomes the natural model:-tagsis the single global "include tags in output" knob, regardless of mode or format.Scope
RenderJSONsignature to accept the keep-tags choice (or pass viaPrinterfield — match existing patterns).app.go:300-307call sites.inspect_tags_tagged.json.goldenwith and without-tags.-tagsaffects both text and JSON.