diff --git a/package.json b/package.json index 4d8597e9daca..f6d01d237e7a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/language-yaml/printer-yaml.js b/src/language-yaml/printer-yaml.js index a7d985688421..2762b084d1fd 100644 --- a/src/language-yaml/printer-yaml.js +++ b/src/language-yaml/printer-yaml.js @@ -381,6 +381,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)) || diff --git a/tests/yaml_comment/__snapshots__/jsfmt.spec.js.snap b/tests/yaml_comment/__snapshots__/jsfmt.spec.js.snap index d8bb44387c25..556811bf126b 100644 --- a/tests/yaml_comment/__snapshots__/jsfmt.spec.js.snap +++ b/tests/yaml_comment/__snapshots__/jsfmt.spec.js.snap @@ -31,7 +31,8 @@ f: empty_content: # hello world ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -a: 123 +a: + 123 # impicitMappginValue ? b @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/yaml_comment/end-comment.yml b/tests/yaml_comment/end-comment.yml new file mode 100644 index 000000000000..ad7b19fc1102 --- /dev/null +++ b/tests/yaml_comment/end-comment.yml @@ -0,0 +1,13 @@ +parent: + one: 1 + # two: 2 + +a: + b: + #b + #a + +A: + B: + #A + #A diff --git a/tests/yaml_root/__snapshots__/jsfmt.spec.js.snap b/tests/yaml_root/__snapshots__/jsfmt.spec.js.snap index 7ea0afb04aae..3da71668d2ef 100644 --- a/tests/yaml_root/__snapshots__/jsfmt.spec.js.snap +++ b/tests/yaml_root/__snapshots__/jsfmt.spec.js.snap @@ -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] diff --git a/yarn.lock b/yarn.lock index 89b47ccfa23c..75ad0c20ae35 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"