Preserve empty line before endComment (#17843)
Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
1 parent
a068b80168
commit
94b9a058eb
4 files changed
+46
-1
No files matched your search
@@ -0,0 +1,18 @@
|
||||
#### Preserve empty line between map and comment (#17843 by @kovsu)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```yaml
|
||||
# Input
|
||||
only: issues
|
||||
|
||||
# Comment
|
||||
|
||||
# Prettier stable
|
||||
only: issues
|
||||
# Comment
|
||||
|
||||
# Prettier main
|
||||
only: issues
|
||||
|
||||
# Comment
|
||||
```
|
||||
@@ -211,7 +211,13 @@ function printNode(path, options, print) {
|
||||
separator = [hardline, hardline];
|
||||
}
|
||||
} else {
|
||||
separator = hardline;
|
||||
// Check if we need to preserve empty line before end comments
|
||||
const lastChild = children.at(-1);
|
||||
const shouldPreserveEmptyLine =
|
||||
isNode(lastChild, ["mapping"]) &&
|
||||
isPreviousLineEmpty(options.originalText, locStart(endComments[0]));
|
||||
|
||||
separator = shouldPreserveEmptyLine ? [hardline, hardline] : hardline;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -253,6 +253,24 @@ printWidth: 80
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`issue-10922.yml format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["yaml"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
foo: bar
|
||||
|
||||
# End Comment - Don't remove previous empty line
|
||||
|
||||
=====================================output=====================================
|
||||
foo: bar
|
||||
|
||||
# End Comment - Don't remove previous empty line
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`issue-16074.yml format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["yaml"]
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
foo: bar
|
||||
|
||||
# End Comment - Don't remove previous empty line
|
||||
Reference in new issue
Block a user