Skip to content

Fix extra newline added after empty map values#1

Draft
Neutronlul with Copilot wants to merge 2 commits into
mainfrom
copilot/update-dependencies-in-package-json
Draft

Fix extra newline added after empty map values#1
Neutronlul with Copilot wants to merge 2 commits into
mainfrom
copilot/update-dependencies-in-package-json

Conversation

Copilot AI commented Nov 20, 2025

Copy link
Copy Markdown

When parsing YAML with empty map values followed by blank lines, stringification would double the blank lines. The parsed document's spaceBefore property was being incorrectly interpreted during stringify, adding an extra newline on top of the existing one.

const yaml = `map:
  item:

anothermap:
  anotheritem:
`;

parseDocument(yaml).toString()
// Before: "map:\n  item:\n\n\nanothermap:\n  anotheritem:\n\n\n" (doubled blank lines)
// After:  "map:\n  item:\n\nanothermap:\n  anotheritem:\n\n" (preserved correctly)

Changes

  • src/stringify/stringifyPair.ts: Removed the newline-doubling logic for empty values with spaceBefore. The property already represents the blank line; doubling creates an extra one. Exception: empty values with inline comments still get the double newline to preserve blank line before comment.

  • tests/issue-474.test.ts: Added tests covering empty values with blank lines and nested structures.

Original prompt

eemeli#474


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Update dependencies in package.json for security Fix extra newline added after empty map values Nov 20, 2025
Copilot AI requested a review from Neutronlul November 20, 2025 00:42
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