feat(yaml): prefer implicit key for empty value (#4972)

* feat(yaml): prefer implicit key for empty value

* fix: prefer `?` for `!!set`

* refactor
This commit is contained in:
Ika authored and GitHub committed 2018-08-12 13:38:14 +08:00
1 parent 82a12a58a8
commit 6ba6138d09
4 files changed
+25 -11

No files matched your search

+15 -1
View File
@@ -323,7 +323,21 @@ function _print(node, parentNode, path, options, print) {
return node.type === "flowMappingItem" &&
path.getParentNode().type !== "flowSequence"
? key
: concat(["? ", align(2, key)]);
: node.type === "mappingItem" &&
node.key.type !== "null" &&
isAbsolutelyPrintedAsSingleLineNode(node.key.node, options) &&
!hasTrailingComments(node.key.node) &&
!(
parentNode.tag.type === "shorthandTag" &&
parentNode.tag.handle === "!!" &&
parentNode.tag.suffix === "set"
)
? concat([
key,
needsSpaceInFrontOfMappingValue(node) ? " " : "",
":"
])
: concat(["? ", align(2, key)]);
}
if (node.key.type === "null") {
@@ -88,7 +88,7 @@ a:
#a
A:
? B
B:
#A
#A
@@ -382,7 +382,7 @@ merge:
null:
# This mapping has four keys,
# one has a value.
? empty
empty:
canonical: ~
english: null
~: null key
@@ -349,9 +349,9 @@ exports[`block-mapping-with-missing-values.yml - yaml-verify 1`] = `
? b
c:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
? a
? b
? c
a:
b:
c:
`;
@@ -360,9 +360,9 @@ exports[`block-mapping-with-missing-values.yml - yaml-verify 2`] = `
? b
c:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
? a
? b
? c
a:
b:
c:
`;
@@ -954,7 +954,7 @@ a: 1
&anchor c: 3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: 1
? b
b:
&anchor c: 3
`;
@@ -966,7 +966,7 @@ a: 1
&anchor c: 3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: 1
? b
b:
&anchor c: 3
`;