From d83ca5a6c61358de7a8efaab41a34680b628cf2e Mon Sep 17 00:00:00 2001 From: Ika Date: Wed, 1 Aug 2018 12:10:06 +0800 Subject: [PATCH] fix(yaml): prefer dash as document separator (#4921) * test: add tests * fix(yaml): prefer dash as document separator --- src/language-yaml/printer-yaml.js | 7 +- .../__snapshots__/jsfmt.spec.js.snap | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 37 +++++++++ tests/yaml_document/separator.yml | 16 ++++ .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 80 +++++++++---------- 6 files changed, 102 insertions(+), 44 deletions(-) create mode 100644 tests/yaml_document/separator.yml diff --git a/src/language-yaml/printer-yaml.js b/src/language-yaml/printer-yaml.js index ea69da108..8d87a8f0e 100644 --- a/src/language-yaml/printer-yaml.js +++ b/src/language-yaml/printer-yaml.js @@ -129,7 +129,12 @@ function _print(node, parentNode, path, options, print) { options.originalText )) ? "" - : concat([hardline, "..."]), + : concat([ + hardline, + node.children[index + 1].head.children.length === 0 + ? "---" + : "..." + ]), hardline ]), "children" diff --git a/tests/yaml_block_folded/__snapshots__/jsfmt.spec.js.snap b/tests/yaml_block_folded/__snapshots__/jsfmt.spec.js.snap index 8673df47b..23154b2a6 100644 --- a/tests/yaml_block_folded/__snapshots__/jsfmt.spec.js.snap +++ b/tests/yaml_block_folded/__snapshots__/jsfmt.spec.js.snap @@ -545,7 +545,7 @@ exports[`prose.yml - yaml-verify 1`] = ` 123 456 789 123 456 789 123 456 789 -... +--- > 123 456 789 123 456 789 @@ -616,7 +616,7 @@ exports[`prose.yml - yaml-verify 2`] = ` 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 -... +--- > 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 123 456 789 diff --git a/tests/yaml_document/__snapshots__/jsfmt.spec.js.snap b/tests/yaml_document/__snapshots__/jsfmt.spec.js.snap index 6043d2532..4f02bd829 100644 --- a/tests/yaml_document/__snapshots__/jsfmt.spec.js.snap +++ b/tests/yaml_document/__snapshots__/jsfmt.spec.js.snap @@ -18,3 +18,40 @@ test # 000 `; + +exports[`separator.yml - yaml-verify 1`] = ` +a +--- +b +... +c +... # +d +... +--- +e +... +# +--- +f +--- # +g +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +a +--- +b +--- +c +... # +d +--- +e +... +# +--- +f +--- +# +g + +`; diff --git a/tests/yaml_document/separator.yml b/tests/yaml_document/separator.yml new file mode 100644 index 000000000..a0f640d23 --- /dev/null +++ b/tests/yaml_document/separator.yml @@ -0,0 +1,16 @@ +a +--- +b +... +c +... # +d +... +--- +e +... +# +--- +f +--- # +g diff --git a/tests/yaml_root/__snapshots__/jsfmt.spec.js.snap b/tests/yaml_root/__snapshots__/jsfmt.spec.js.snap index b2ab17687..7ea0afb04 100644 --- a/tests/yaml_root/__snapshots__/jsfmt.spec.js.snap +++ b/tests/yaml_root/__snapshots__/jsfmt.spec.js.snap @@ -8,7 +8,7 @@ exports[`documents.yml - yaml-verify 1`] = ` 456 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 123 -... +--- 456 `; diff --git a/tests/yaml_spec/__snapshots__/jsfmt.spec.js.snap b/tests/yaml_spec/__snapshots__/jsfmt.spec.js.snap index 7720b221b..b9f97fd5f 100644 --- a/tests/yaml_spec/__snapshots__/jsfmt.spec.js.snap +++ b/tests/yaml_spec/__snapshots__/jsfmt.spec.js.snap @@ -269,7 +269,7 @@ scalar1 key: value ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ scalar1 -... +--- key: value `; @@ -281,7 +281,7 @@ scalar1 key: value ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ scalar1 -... +--- key: value `; @@ -694,7 +694,7 @@ a: b --- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a: b -... +--- `; @@ -705,7 +705,7 @@ a: b --- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a: b -... +--- `; @@ -1518,7 +1518,7 @@ string" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "quoted string" -... +--- &node foo `; @@ -1529,7 +1529,7 @@ string" --- &node foo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "quoted string" -... +--- &node foo `; @@ -1838,7 +1838,7 @@ exports[`spec-example-2-7-two-documents-in-a-stream.yml - yaml-verify 1`] = ` - Ken Griffey # Team ranking -... +--- - Chicago Cubs - St Louis Cardinals @@ -1863,7 +1863,7 @@ exports[`spec-example-2-7-two-documents-in-a-stream.yml - yaml-verify 2`] = ` - Ken Griffey # Team ranking -... +--- - Chicago Cubs - St Louis Cardinals @@ -1884,7 +1884,7 @@ action: grand slam time: 20:03:20 player: Sammy Sosa action: strike (miss) -... +--- time: 20:03:47 player: Sammy Sosa action: grand slam @@ -1906,7 +1906,7 @@ action: grand slam time: 20:03:20 player: Sammy Sosa action: strike (miss) -... +--- time: 20:03:47 player: Sammy Sosa action: grand slam @@ -2631,12 +2631,12 @@ Time: 2001-11-23 15:01:42 -5 User: ed Warning: This is an error message for the log file -... +--- Time: 2001-11-23 15:02:31 -5 User: ed Warning: A slightly different error message. -... +--- Date: 2001-11-23 15:03:17 -5 User: ed Fatal: Unknown variable "bar" @@ -2683,11 +2683,11 @@ Stack: Time: 2001-11-23 15:01:42 -5 User: ed Warning: This is an error message for the log file -... +--- Time: 2001-11-23 15:02:31 -5 User: ed Warning: A slightly different error message. -... +--- Date: 2001-11-23 15:03:17 -5 User: ed Fatal: Unknown variable "bar" @@ -4867,9 +4867,9 @@ document ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Bare document -... +--- # No document -... +--- | %!PS-Adobe-2.0 # Not the first line @@ -4885,9 +4885,9 @@ document %!PS-Adobe-2.0 # Not the first line ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Bare document -... +--- # No document -... +--- | %!PS-Adobe-2.0 # Not the first line @@ -4905,7 +4905,7 @@ exports[`spec-example-9-4-explicit-documents.yml - yaml-verify 1`] = ` { ? matches % : 20 } -... +--- # Empty `; @@ -4920,7 +4920,7 @@ exports[`spec-example-9-4-explicit-documents.yml - yaml-verify 2`] = ` ... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ { matches %: 20 } -... +--- # Empty `; @@ -4977,7 +4977,7 @@ Document matches %: 20 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Document -... +--- # Empty ... %YAML 1.2 @@ -4996,7 +4996,7 @@ Document matches %: 20 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Document -... +--- # Empty ... %YAML 1.2 @@ -5091,10 +5091,10 @@ e ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!map a: b -... +--- !!seq - !!str c -... +--- !!str d e @@ -5112,10 +5112,10 @@ e ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!map a: b -... +--- !!seq - !!str c -... +--- !!str d e `; @@ -5272,23 +5272,23 @@ a6: 1 value11 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!str &a1 scalar1 -... +--- !!str &a2 scalar2 -... +--- !!str &a3 scalar3 -... +--- !!map &a4 !!str &a5 key5: value4 -... +--- a6: 1 &anchor6 b6: 2 -... +--- !!map !!str &a8 key8: value7 -... +--- !!map !!str &a10 key10: value9 -... +--- !!str &a11 value11 `; @@ -5322,23 +5322,23 @@ a6: 1 value11 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!str &a1 scalar1 -... +--- !!str &a2 scalar2 -... +--- !!str &a3 scalar3 -... +--- !!map &a4 !!str &a5 key5: value4 -... +--- a6: 1 &anchor6 b6: 2 -... +--- !!map !!str &a8 key8: value7 -... +--- !!map !!str &a10 key10: value9 -... +--- !!str &a11 value11 `;