Skip to content

Preserve inline property comments during JSONC edits - #133

Open
RKS (rksharma-owg) wants to merge 1 commit into
microsoft:mainfrom
rksharma-owg:codex/fix-property-trailing-comments
Open

RKS (rksharma-owg) wants to merge 1 commit into
microsoft:mainfrom
rksharma-owg:codex/fix-property-trailing-comments

Conversation

@rksharma-owg

Copy link
Copy Markdown

Appending a property with modify() can move the previous property's inline comment onto the new property. Deleting a property can drop the previous property's comment and leave the deleted property's comment attached to its neighbor.

The edit boundaries were based on AST value offsets, which exclude comments. Scan same-line trailing trivia with the existing JSONC scanner so edits preserve the preceding property's comments, remove the deleted property's trailing comments, and place commas correctly. Standalone comments after the line boundary retain the existing behavior.

Validation on Node 22.23.1, macOS arm64:

  • Untouched main: npm test passed compilation, ESLint and 87 tests.
  • All 30 added regression cases failed before the implementation change.
  • Patched npm test: compilation, ESLint and 117 tests passed.
  • Cases cover appending, custom insertion order, deleting last/middle/only properties, line and block comments, trailing commas, LF/CRLF, and edits with/without formatting options.
  • An additional local probe checked 500 combinations of comments, comma placement and formatting, including preservation of surviving comments during first/middle/last deletion. No assertion failed.
  • git diff --check passes.

No new dependency or public API change. This patch is limited to object-property edits. The Windows/Linux CI matrix has not run for this local branch; no performance improvement is claimed.

Fixes #125.

Prepared with Codex assistance; the checks above ran locally.

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.

modify(): trailing inline comment is re-attached to the newly inserted property

1 participant