Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(yaml): end comment in nested mapping #4918

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -61,7 +61,7 @@
"unicode-regex": "1.0.1",
"unified": "6.1.6",
"yaml": "1.0.0-rc.7",
"yaml-unist-parser": "1.0.0-rc.2"
"yaml-unist-parser": "1.0.0-rc.3"
},
"devDependencies": {
"@babel/cli": "7.0.0-beta.49",
Expand Down
2 changes: 2 additions & 0 deletions src/language-yaml/printer-yaml.js
Expand Up @@ -360,6 +360,8 @@ function _print(node, parentNode, path, options, print) {
needsSpaceInFrontOfMappingValue(node) ? " " : "",
":",
hasLeadingComments(node.value.node) ||
(hasEndComments(node.value) &&
node.value.node.type !== "null") ||
(parentNode.type === "mapping" &&
hasTrailingComments(node.key.node) &&
isInlineNode(node.value.node)) ||
Expand Down
34 changes: 33 additions & 1 deletion tests/yaml_comment/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -31,7 +31,8 @@ f:
empty_content:
# hello world
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: 123
a:
123
# impicitMappginValue

? b
Expand Down Expand Up @@ -62,6 +63,37 @@ empty_content:

`;

exports[`end-comment.yml - yaml-verify 1`] = `
parent:
one: 1
# two: 2

a:
b:
#b
#a

A:
B:
#A
#A
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parent:
one: 1
# two: 2

a:
b:
#b
#a

A:
? B
#A
#A

`;

exports[`root.yml - yaml-verify 1`] = `
#hello world
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
13 changes: 13 additions & 0 deletions tests/yaml_comment/end-comment.yml
@@ -0,0 +1,13 @@
parent:
one: 1
# two: 2

a:
b:
#b
#a

A:
B:
#A
#A
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn’t these have to be at the end of the file to reproduce the bug?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just needs to be at the end of a collection.

2 changes: 1 addition & 1 deletion tests/yaml_root/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -262,7 +262,7 @@ omap:
- aardvark: African pig-like ant eater. Ugly.
- anteater: South-American ant eater. Two species.
- anaconda: South-American constrictor snake. Scaly.
# Etc.
# Etc.
# Flow style
Numbers: !!omap [one: 1, two: 2, three: 3]

Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Expand Up @@ -6008,9 +6008,9 @@ yallist@^3.0.0, yallist@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.2.tgz#8452b4bb7e83c7c188d8041c1a837c773d6d8bb9"

yaml-unist-parser@1.0.0-rc.2:
version "1.0.0-rc.2"
resolved "https://registry.yarnpkg.com/yaml-unist-parser/-/yaml-unist-parser-1.0.0-rc.2.tgz#a9c3597fe8507d7b80c7c51fc1c1ae4773ccdd30"
yaml-unist-parser@1.0.0-rc.3:
version "1.0.0-rc.3"
resolved "https://registry.yarnpkg.com/yaml-unist-parser/-/yaml-unist-parser-1.0.0-rc.3.tgz#d7b396353da92c75bb471a9e65973ba967e0b4f6"
dependencies:
lines-and-columns "^1.1.6"
tslib "^1.9.1"
Expand Down