Skip to content

fix: ensure inline container tightening for deletions - #278

Merged
DecimalTurn merged 3 commits into
latestfrom
dev-fix-spacing-empty-array
Aug 9, 2026
Merged

fix: ensure inline container tightening for deletions#278
DecimalTurn merged 3 commits into
latestfrom
dev-fix-spacing-empty-array

Conversation

@DecimalTurn

Copy link
Copy Markdown
Owner

No description provided.

…ongside InlineTable

When the only item is removed from a single-line InlineArray, mark it
for bracket tightening just like InlineTable. Rename the tracking helpers
from inlineTableNeedingTighten to inlineContainerNeedingTighten and add
the InlineArray case to the post-patch tightening traversal.

Extract tightenInlineContainerEnd() to share the end-column logic between
InlineTable and InlineArray cases.
…iners

Three related issues where removing items from single-line inline arrays
or inline tables left trailing whitespace inside brackets:

1. InlineArray was missing from the "needs tightening" tracking in
   writer.ts — only InlineTable was marked when its last item was
   removed. Generalized the helpers to inlineContainersNeedingTighten.

2. The post-patch tightening traversal in patch.ts only handled
   InlineTable. Added InlineArray case, extracted shared logic into
   tightenInlineContainerEnd().

3. recalcInlineContainerEnds only looked through InlineItems wrapping
   KeyValues (inline table entries), missing InlineItems wrapping
   InlineTable/InlineArray directly (inline array elements like
   `[ {} ]`). Added resolveInnerEndCol() to handle both cases.
Copilot AI lite review requested due to automatic review settings August 9, 2026 08:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR generalizes the “tighten inline container end after deletions” behavior so that it applies to both single-line InlineTable and InlineArray cases, fixing trailing-whitespace artifacts when the only element is removed.

Changes:

  • Generalize writer-side tracking from inline tables to inline containers (tables + arrays) for post-remove tightening.
  • Add shared helpers in patch.ts to tighten container end columns and to correctly recompute parent container ends when nested containers are tightened.
  • Convert previously failing regression tests for these whitespace issues into passing tests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/writer.ts Generalizes “needs tighten” tracking to cover single-line inline arrays as well as inline tables during remove().
src/patch.ts Applies tightening for both inline tables/arrays and refactors end-column recalculation logic via helpers.
src/tests/patch.test.ts Promotes three inline-array/table whitespace regression cases from expected-fail to passing tests.
Suppressed comments (1)

src/patch.ts:1675

  • This docstring still refers specifically to a nested InlineTable, but this code path is now used for both InlineTables and InlineArrays. Updating the wording will keep the comment accurate as the behavior generalizes.
 * After tightening a nested single-line InlineTable (whose only item was
 * removed), recalculate the end positions of any parent single-line InlineTable
 * or InlineArray containers. The remove() call zeroed the offset for the

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/writer.ts
@DecimalTurn DecimalTurn changed the title fix: generalize inline container tightening for deletions fix: ensure inline container tightening for deletions Aug 9, 2026
…ory leaks

Only has/delete are needed, so a WeakSet is sufficient and prevents
retaining CST nodes if an exception occurs before cleanup or if a
caller forgets to delete.
@DecimalTurn
DecimalTurn merged commit dbc9593 into latest Aug 9, 2026
30 checks passed
@DecimalTurn
DecimalTurn deleted the dev-fix-spacing-empty-array branch August 9, 2026 08:26
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.

2 participants