fix(yaml): support end comments (#4854)
parent
ed0ecdad18
commit
cb7fe00863
|
@ -60,8 +60,8 @@
|
|||
"typescript-eslint-parser": "eslint/typescript-eslint-parser#6eec85b1466fbef087838203b246f70fa71ac0ac",
|
||||
"unicode-regex": "1.0.1",
|
||||
"unified": "6.1.6",
|
||||
"yaml": "1.0.0-rc.4",
|
||||
"yaml-unist-parser": "1.0.0-rc.1"
|
||||
"yaml": "1.0.0-rc.7",
|
||||
"yaml-unist-parser": "1.0.0-rc.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.0.0-beta.49",
|
||||
|
|
|
@ -32,7 +32,8 @@ function parse(text) {
|
|||
(node.type === "mappingKey" || node.type === "mappingValue") &&
|
||||
node.children[0].type === "null" &&
|
||||
node.leadingComments.length === 0 &&
|
||||
node.trailingComments.length === 0
|
||||
node.trailingComments.length === 0 &&
|
||||
node.endComments.length === 0
|
||||
) {
|
||||
return createNull();
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ const {
|
|||
hasLeadingComments,
|
||||
hasMiddleComments,
|
||||
hasTrailingComments,
|
||||
hasEndComments,
|
||||
hasPrettierIgnore,
|
||||
isLastDescendantNode,
|
||||
isNextLineEmpty,
|
||||
|
@ -100,7 +101,13 @@ function genericPrint(path, options, print) {
|
|||
])
|
||||
)
|
||||
: "",
|
||||
nextEmptyLine
|
||||
nextEmptyLine,
|
||||
hasEndComments(node)
|
||||
? (endComments =>
|
||||
node.type === "sequenceItem" ? align(2, endComments) : endComments)(
|
||||
concat([hardline, join(hardline, path.map(print, "endComments"))])
|
||||
)
|
||||
: ""
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -432,12 +439,12 @@ function _print(node, parentNode, path, options, print) {
|
|||
function indent(doc) {
|
||||
return docBuilders.align(" ".repeat(options.tabWidth), doc);
|
||||
}
|
||||
}
|
||||
|
||||
function align(n, doc) {
|
||||
return typeof n === "number" && n > 0
|
||||
? docBuilders.align(" ".repeat(n), doc)
|
||||
: docBuilders.align(n, doc);
|
||||
}
|
||||
function align(n, doc) {
|
||||
return typeof n === "number" && n > 0
|
||||
? docBuilders.align(" ".repeat(n), doc)
|
||||
: docBuilders.align(n, doc);
|
||||
}
|
||||
|
||||
function isInlineNode(node) {
|
||||
|
|
|
@ -161,6 +161,10 @@ function hasTrailingComments(node) {
|
|||
return "trailingComments" in node && node.trailingComments.length !== 0;
|
||||
}
|
||||
|
||||
function hasEndComments(node) {
|
||||
return "endComments" in node && node.endComments.length !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* " a b c d e f " -> [" a b", "c d", "e f "]
|
||||
*/
|
||||
|
@ -346,5 +350,6 @@ module.exports = {
|
|||
hasLeadingComments,
|
||||
hasMiddleComments,
|
||||
hasTrailingComments,
|
||||
hasEndComments,
|
||||
hasExplicitDocumentEndMarker
|
||||
};
|
||||
|
|
|
@ -1,5 +1,67 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`collection.yml - yaml-verify 1`] = `
|
||||
a:
|
||||
123
|
||||
# impicitMappginValue
|
||||
|
||||
? b
|
||||
# explicitMappingKey
|
||||
: c
|
||||
# explicitMappingValue
|
||||
|
||||
d:
|
||||
- 123
|
||||
# sequence
|
||||
|
||||
e:
|
||||
- 123
|
||||
# sequenceItem
|
||||
|
||||
f:
|
||||
- a
|
||||
# b.leadingComments
|
||||
- b
|
||||
# b.endComments
|
||||
- c
|
||||
# c.endComments
|
||||
# sequence.endComments
|
||||
# documentBody.children
|
||||
|
||||
empty_content:
|
||||
# hello world
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
a: 123
|
||||
# impicitMappginValue
|
||||
|
||||
? b
|
||||
# explicitMappingKey
|
||||
: c
|
||||
# explicitMappingValue
|
||||
|
||||
d:
|
||||
- 123
|
||||
# sequence
|
||||
|
||||
e:
|
||||
- 123
|
||||
# sequenceItem
|
||||
|
||||
f:
|
||||
- a
|
||||
# b.leadingComments
|
||||
- b
|
||||
# b.endComments
|
||||
- c
|
||||
# c.endComments
|
||||
# sequence.endComments
|
||||
# documentBody.children
|
||||
|
||||
empty_content:
|
||||
# hello world
|
||||
|
||||
`;
|
||||
|
||||
exports[`root.yml - yaml-verify 1`] = `
|
||||
#hello world
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -12,6 +74,6 @@ exports[`set.yml - yaml-verify 1`] = `
|
|||
# 456
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
- 123
|
||||
# 456
|
||||
# 456
|
||||
|
||||
`;
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
a:
|
||||
123
|
||||
# impicitMappginValue
|
||||
|
||||
? b
|
||||
# explicitMappingKey
|
||||
: c
|
||||
# explicitMappingValue
|
||||
|
||||
d:
|
||||
- 123
|
||||
# sequence
|
||||
|
||||
e:
|
||||
- 123
|
||||
# sequenceItem
|
||||
|
||||
f:
|
||||
- a
|
||||
# b.leadingComments
|
||||
- b
|
||||
# b.endComments
|
||||
- c
|
||||
# c.endComments
|
||||
# sequence.endComments
|
||||
# documentBody.children
|
||||
|
||||
empty_content:
|
||||
# hello world
|
|
@ -1061,20 +1061,6 @@ exports[`mapping-key-and-flow-sequence-item-anchors.yml - yaml-verify 2`] = `
|
|||
|
||||
`;
|
||||
|
||||
exports[`mapping-with-anchor-on-document-start-line.yml - yaml-verify 1`] = `
|
||||
--- &anchor a: b
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
&anchor a: b
|
||||
|
||||
`;
|
||||
|
||||
exports[`mapping-with-anchor-on-document-start-line.yml - yaml-verify 2`] = `
|
||||
--- &anchor a: b
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
&anchor a: b
|
||||
|
||||
`;
|
||||
|
||||
exports[`mixed-block-mapping-explicit-to-implicit.yml - yaml-verify 1`] = `
|
||||
? a
|
||||
: 13
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
--- &anchor a: b
|
12
yarn.lock
12
yarn.lock
|
@ -6008,16 +6008,16 @@ 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.1:
|
||||
version "1.0.0-rc.1"
|
||||
resolved "https://registry.yarnpkg.com/yaml-unist-parser/-/yaml-unist-parser-1.0.0-rc.1.tgz#c70d0642c800e83535fbf6984a41b38b4d9c777e"
|
||||
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"
|
||||
dependencies:
|
||||
lines-and-columns "^1.1.6"
|
||||
tslib "^1.9.1"
|
||||
|
||||
yaml@1.0.0-rc.4:
|
||||
version "1.0.0-rc.4"
|
||||
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.0.0-rc.4.tgz#850dc77d9b03975b5e5ea8a9b37cde252a8f1f0b"
|
||||
yaml@1.0.0-rc.7:
|
||||
version "1.0.0-rc.7"
|
||||
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.0.0-rc.7.tgz#7cf9dba3c78992542b7a2d7cb9a7eeacbff63f77"
|
||||
|
||||
yargs-parser@^7.0.0:
|
||||
version "7.0.0"
|
||||
|
|
Loading…
Reference in New Issue