Impact
After --reorder-code, a trailing (same-line) comment on a top-level declaration is moved to its own line below the declaration — which places it directly above the next declaration. The comment now reads as documentation for the wrong member, silently corrupting comment ownership across a codebase-wide reorder (e.g. a # read-only — do not mutate note ends up appearing to document the unrelated next field).
This looks like a --reorder-code-path sibling of #83 (fixed long ago for plain formatting — plain formatting preserves these comments correctly today).
Minimal repro
repro.gd:
extends Node
const A := 1 # comment for A
const B := 2
gdscript-formatter --reorder-code repro.gd
Actual output
extends Node
const A := 1
# comment for A
const B := 2
# comment for A is now visually (and for doc tooling, semantically) attached to const B.
Expected
extends Node
const A := 1 # comment for A
const B := 2
Trailing comments should stay on their declaration's line — exactly what plain formatting (without --reorder-code) already does.
Boundary (verified individually on 0.21.0)
Does NOT detach:
- Plain formatting without
--reorder-code
- A trailing comment on the last declaration of the file (nothing follows it)
- Trailing comments on statements inside function bodies
DOES detach:
- Trailing comments on top-level
const / var declarations followed by another declaration (also observed landing above a following func)
Impact
After
--reorder-code, a trailing (same-line) comment on a top-level declaration is moved to its own line below the declaration — which places it directly above the next declaration. The comment now reads as documentation for the wrong member, silently corrupting comment ownership across a codebase-wide reorder (e.g. a# read-only — do not mutatenote ends up appearing to document the unrelated next field).This looks like a
--reorder-code-path sibling of #83 (fixed long ago for plain formatting — plain formatting preserves these comments correctly today).Minimal repro
repro.gd:Actual output
# comment for Ais now visually (and for doc tooling, semantically) attached toconst B.Expected
Trailing comments should stay on their declaration's line — exactly what plain formatting (without
--reorder-code) already does.Boundary (verified individually on 0.21.0)
Does NOT detach:
--reorder-codeDOES detach:
const/vardeclarations followed by another declaration (also observed landing above a followingfunc)