Fix YAML formatting: preserve empty line after block scalar (#19205)

Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
Antoine Pietriandfisker Cheung authored and GitHub committed 2026-06-04 01:22:42 +08:00
1 parent eb0155289f
commit 80cdddb79b
4 files changed
+81 -2

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
#### Preserve empty line after block scalar (#19205 by @seirl)
<!-- prettier-ignore -->
```yaml
# Input
foo: >
a
b
bar: baz
qux: quux
# Prettier stable
foo: >
a
b
bar: baz
qux: quux
# Prettier main
foo: >
a
b
bar: baz
qux: quux
```
+2 -2
View File
@@ -12,8 +12,8 @@ function printNextEmptyLine(path, originalText) {
() => new Set(),
);
if (!isNextEmptyLinePrintedSet.has(node.position.end.line)) {
isNextEmptyLinePrintedSet.add(node.position.end.line);
if (!isNextEmptyLinePrintedSet.has(node.position.end.offset)) {
isNextEmptyLinePrintedSet.add(node.position.end.offset);
if (
isNextLineEmpty(node, originalText) &&
!shouldPrintEndComments(path.parent)
@@ -125,6 +125,52 @@ parsers: ["yaml"]
================================================================================
`;
exports[`empty-line-after-block-scalar.yml - {"proseWrap":"always"} format 1`] = `
====================================options=====================================
parsers: ["yaml"]
proseWrap: "always"
printWidth: 80 (default) |
=====================================input======================================
foo: >
a
b
bar: baz
qux: quux
=====================================output=====================================
foo: >
a b
bar: baz
qux: quux
================================================================================
`;
exports[`empty-line-after-block-scalar.yml format 1`] = `
====================================options=====================================
parsers: ["yaml"]
printWidth: 80 (default) |
=====================================input======================================
foo: >
a
b
bar: baz
qux: quux
=====================================output=====================================
foo: >
a
b
bar: baz
qux: quux
================================================================================
`;
exports[`indent.yml - {"proseWrap":"always"} format 1`] = `
====================================options=====================================
parsers: ["yaml"]
@@ -0,0 +1,6 @@
foo: >
a
b
bar: baz
qux: quux