Fix YAML formatting: preserve empty line after block scalar (#19205)
Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
1 parent
eb0155289f
commit
80cdddb79b
4 files changed
+81
-2
No files matched your search
@@ -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
|
||||
```
|
||||
@@ -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
|
||||
Reference in new issue
Block a user