YAML: Fix comments in flowMapping and flowSequence (#9669)

This commit is contained in:
fisker Cheung authored and GitHub committed 2020-11-17 21:38:50 +08:00
1 parent 1fb2188eb2
commit 85e5cfaf2f
4 files changed
+184 -1

No files matched your search

+60
View File
@@ -0,0 +1,60 @@
#### Fix comments inside `flowMapping` and `flowSequence` (#9669 by @fisker)
<!-- prettier-ignore -->
```yaml
# Input
a:
[
a, b,
# comment
]
b:
# prettier-ignore
{
a: 1, b: 2,
# comment
}
# Prettier stable
a: [a, b]
# comment
b:
# prettier-ignore
{
a: 1, b: 2,
# comment
}
# comment
# Prettier stable (second format)
a:
[a, b]
# comment
b:
# prettier-ignore
{
a: 1, b: 2,
# comment
}
# comment
# comment
# Prettier master
a: [
a,
b,
# comment
]
b:
# prettier-ignore
{
a: 1, b: 2,
# comment
}
```
+13 -1
View File
@@ -527,6 +527,12 @@ function _print(node, parentNode, path, options, print) {
)
),
ifBreak(",", ""),
hasEndComments(node)
? concat([
hardline,
join(hardline, path.map(print, "endComments")),
])
: "",
])
),
isLastItemEmptyMappingItem ? "" : bracketSpacing,
@@ -703,7 +709,13 @@ function needsSpaceInFrontOfMappingValue(node) {
function shouldPrintEndComments(node) {
return (
hasEndComments(node) && !isNode(node, ["documentHead", "documentBody"])
hasEndComments(node) &&
!isNode(node, [
"documentHead",
"documentBody",
"flowMapping",
"flowSequence",
])
);
}
@@ -108,6 +108,84 @@ A:
================================================================================
`;
exports[`flow-sequence-mapping.yml format 1`] = `
====================================options=====================================
parsers: ["yaml"]
printWidth: 80
| printWidth
=====================================input======================================
a:
[
check-format, check-lint,
check-spelling,
# coverage,
# install-and-run-from-git,
]
b:
{
a: check-format, b: check-lint,
c: check-spelling,
# d: coverage,
# e: install-and-run-from-git,
}
d:
# prettier-ignore
[
check-format, check-lint,
check-spelling,
# coverage,
# install-and-run-from-git,
]
e:
# prettier-ignore
{
a: check-format, b: check-lint,
c: check-spelling,
# d: coverage,
# e: install-and-run-from-git,
}
=====================================output=====================================
a: [
check-format,
check-lint,
check-spelling,
# coverage,
# install-and-run-from-git,
]
b: {
a: check-format,
b: check-lint,
c: check-spelling,
# d: coverage,
# e: install-and-run-from-git,
}
d:
# prettier-ignore
[
check-format, check-lint,
check-spelling,
# coverage,
# install-and-run-from-git,
]
e:
# prettier-ignore
{
a: check-format, b: check-lint,
c: check-spelling,
# d: coverage,
# e: install-and-run-from-git,
}
================================================================================
`;
exports[`in-empty-item-without-newlline.yml format 1`] = `
====================================options=====================================
parsers: ["yaml"]
@@ -0,0 +1,33 @@
a:
[
check-format, check-lint,
check-spelling,
# coverage,
# install-and-run-from-git,
]
b:
{
a: check-format, b: check-lint,
c: check-spelling,
# d: coverage,
# e: install-and-run-from-git,
}
d:
# prettier-ignore
[
check-format, check-lint,
check-spelling,
# coverage,
# install-and-run-from-git,
]
e:
# prettier-ignore
{
a: check-format, b: check-lint,
c: check-spelling,
# d: coverage,
# e: install-and-run-from-git,
}