Skip to content

Commit

Permalink
fix(yaml): prefer dash as document separator (#4921)
Browse files Browse the repository at this point in the history
* test: add tests

* fix(yaml): prefer dash as document separator
  • Loading branch information
ikatyang authored and azz committed Aug 1, 2018
1 parent 4b8e18f commit d83ca5a
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 44 deletions.
7 changes: 6 additions & 1 deletion src/language-yaml/printer-yaml.js
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tests/yaml_block_folded/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions tests/yaml_document/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -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
`;
16 changes: 16 additions & 0 deletions tests/yaml_document/separator.yml
@@ -0,0 +1,16 @@
a
---
b
...
c
... #
d
...
---
e
...
#
---
f
--- #
g
2 changes: 1 addition & 1 deletion tests/yaml_root/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -8,7 +8,7 @@ exports[`documents.yml - yaml-verify 1`] = `
456
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123
...
---
456
`;
Expand Down
80 changes: 40 additions & 40 deletions tests/yaml_spec/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -269,7 +269,7 @@ scalar1
key: value
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scalar1
...
---
key: value
`;
Expand All @@ -281,7 +281,7 @@ scalar1
key: value
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scalar1
...
---
key: value
`;
Expand Down Expand Up @@ -694,7 +694,7 @@ a: b
---
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: b
...
---
`;
Expand All @@ -705,7 +705,7 @@ a: b
---
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: b
...
---
`;
Expand Down Expand Up @@ -1518,7 +1518,7 @@ string"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"quoted
string"
...
---
&node foo
`;
Expand All @@ -1529,7 +1529,7 @@ string"
--- &node foo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"quoted string"
...
---
&node foo
`;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -4867,9 +4867,9 @@ document
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bare
document
...
---
# No document
...
---
|
%!PS-Adobe-2.0 # Not the first line
Expand All @@ -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
Expand All @@ -4905,7 +4905,7 @@ exports[`spec-example-9-4-explicit-documents.yml - yaml-verify 1`] = `
{ ? matches
%
: 20 }
...
---
# Empty
`;
Expand All @@ -4920,7 +4920,7 @@ exports[`spec-example-9-4-explicit-documents.yml - yaml-verify 2`] = `
...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{ matches %: 20 }
...
---
# Empty
`;
Expand Down Expand Up @@ -4977,7 +4977,7 @@ Document
matches %: 20
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Document
...
---
# Empty
...
%YAML 1.2
Expand All @@ -4996,7 +4996,7 @@ Document
matches %: 20
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Document
...
---
# Empty
...
%YAML 1.2
Expand Down Expand Up @@ -5091,10 +5091,10 @@ e
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!map
a: b
...
---
!!seq
- !!str c
...
---
!!str d
e
Expand All @@ -5112,10 +5112,10 @@ e
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!map
a: b
...
---
!!seq
- !!str c
...
---
!!str d e
`;
Expand Down Expand Up @@ -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
`;
Expand Down Expand Up @@ -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
`;
Expand Down

0 comments on commit d83ca5a

Please sign in to comment.