feat(yaml): support proseWrap (#4742)

- support `proseWrap` in `yaml`
- move `proseWrap` to `commonOptions`
- update to `yaml@1.0.0-rc.4` and `yaml-unist-parser@1.0.0-rc.1`
This commit is contained in:
Ika authored and GitHub committed 2018-07-04 00:28:47 +08:00
1 parent 51b7c02e12
commit 432c9d7d04
24 files changed
+4395 -168

No files matched your search

+2 -2
View File
@@ -60,8 +60,8 @@
"typescript-eslint-parser": "eslint/typescript-eslint-parser#42f29a1db5c51262fd9ed2d6105015da8925ba2d",
"unicode-regex": "1.0.1",
"unified": "6.1.6",
"yaml": "1.0.0-beta.7",
"yaml-unist-parser": "1.0.0-beta.4"
"yaml": "1.0.0-rc.4",
"yaml-unist-parser": "1.0.0-rc.1"
},
"devDependencies": {
"@babel/cli": "7.0.0-beta.49",
+29
View File
@@ -18,5 +18,34 @@ module.exports = {
type: "boolean",
default: false,
description: "Use single quotes instead of double quotes."
},
proseWrap: {
since: "1.8.2",
category: CATEGORY_COMMON,
type: "choice",
default: [
{ since: "1.8.2", value: true },
{ since: "1.9.0", value: "preserve" }
],
description: "How to wrap prose.",
choices: [
{
since: "1.9.0",
value: "always",
description: "Wrap prose if it exceeds the print width."
},
{
since: "1.9.0",
value: "never",
description: "Do not wrap prose."
},
{
since: "1.9.0",
value: "preserve",
description: "Wrap prose as-is."
},
{ value: false, deprecated: "1.9.0", redirect: "never" },
{ value: true, deprecated: "1.9.0", redirect: "always" }
]
}
};
+1 -31
View File
@@ -2,38 +2,8 @@
const commonOptions = require("../common/common-options");
const CATEGORY_MARKDOWN = "Markdown";
// format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
module.exports = {
proseWrap: {
since: "1.8.2",
category: CATEGORY_MARKDOWN,
type: "choice",
default: [
{ since: "1.8.2", value: true },
{ since: "1.9.0", value: "preserve" }
],
description: "How to wrap prose. (markdown)",
choices: [
{
since: "1.9.0",
value: "always",
description: "Wrap prose if it exceeds the print width."
},
{
since: "1.9.0",
value: "never",
description: "Do not wrap prose."
},
{
since: "1.9.0",
value: "preserve",
description: "Wrap prose as-is."
},
{ value: false, deprecated: "1.9.0", redirect: "never" },
{ value: true, deprecated: "1.9.0", redirect: "always" }
]
},
proseWrap: commonOptions.proseWrap,
singleQuote: commonOptions.singleQuote
};
+3 -1
View File
@@ -4,5 +4,7 @@ const commonOptions = require("../common/common-options");
// format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
module.exports = {
bracketSpacing: commonOptions.bracketSpacing
bracketSpacing: commonOptions.bracketSpacing,
singleQuote: commonOptions.singleQuote,
proseWrap: commonOptions.proseWrap
};
+95 -83
View File
@@ -3,6 +3,8 @@
const { insertPragma, isPragma } = require("./pragma");
const {
getAncestorCount,
getBlockValueLineContents,
getFlowScalarLineContents,
getLast,
getLastDescendantNode,
hasExplicitDocumentEndMarker,
@@ -13,8 +15,7 @@ const {
isLastDescendantNode,
isNextLineEmpty,
isNode,
isBlockValue,
restoreBlockFoldedValue
isBlockValue
} = require("./utils");
const docBuilders = require("../doc").builders;
const {
@@ -130,9 +131,7 @@ function _print(node, parentNode, path, options, print) {
node.children.length === 0 ||
(lastDescendantNode =>
isBlockValue(lastDescendantNode) &&
(/[^\S\n]\n?$/.test(lastDescendantNode.value) ||
(lastDescendantNode.chomping === "keep" &&
lastDescendantNode.value === "\n")))(getLastDescendantNode(node))
lastDescendantNode.chomping === "keep")(getLastDescendantNode(node))
? ""
: hardline
]);
@@ -168,7 +167,14 @@ function _print(node, parentNode, path, options, print) {
case "anchor":
return concat(["&", node.value]);
case "plain":
return join(hardline, node.value.replace(/\n/g, "\n\n").split("\n"));
return printFlowScalarContent(
node.type,
options.originalText.slice(
node.position.start.offset,
node.position.end.offset
),
options
);
case "quoteDouble":
case "quoteSingle": {
const singleQuote = "'";
@@ -187,44 +193,56 @@ function _print(node, parentNode, path, options, print) {
// and quoteSingle do not need to escape backslashes
const originalQuote =
node.type === "quoteDouble" ? doubleQuote : singleQuote;
return originalQuote + raw + originalQuote;
return concat([
originalQuote,
printFlowScalarContent(node.type, raw, options),
originalQuote
]);
} else if (raw.includes(doubleQuote)) {
return (
singleQuote +
(node.type === "quoteDouble"
? // double quote needs to be escaped by backslash in quoteDouble
raw.replace(/\\"/g, doubleQuote)
: raw) +
return concat([
singleQuote,
printFlowScalarContent(
node.type,
node.type === "quoteDouble"
? // double quote needs to be escaped by backslash in quoteDouble
raw.replace(/\\"/g, doubleQuote)
: raw,
options
),
singleQuote
);
]);
}
if (raw.includes(singleQuote)) {
return (
doubleQuote +
(node.type === "quoteSingle"
? // single quote needs to be escaped by 2 single quotes in quoteSingle
raw.replace(/''/g, singleQuote)
: raw) +
return concat([
doubleQuote,
printFlowScalarContent(
node.type,
node.type === "quoteSingle"
? // single quote needs to be escaped by 2 single quotes in quoteSingle
raw.replace(/''/g, singleQuote)
: raw,
options
),
doubleQuote
);
]);
}
const quote = options.singleQuote ? singleQuote : doubleQuote;
return quote + raw + quote;
return concat([
quote,
printFlowScalarContent(node.type, raw, options),
quote
]);
}
case "blockFolded": // TODO: --prose-wrap
case "blockFolded":
case "blockLiteral": {
const value =
node.chomping === "strip" ||
(node.chomping === "clip" &&
options.originalText.slice(
node.position.end.offset - 2,
node.position.end.offset
) === "\n\n") ||
(node.chomping === "keep" && node.value === "\n")
? node.value
: node.value.replace(/\n$/, "");
const parentIndent = getAncestorCount(
path,
ancestorNode =>
ancestorNode.type === "sequence" || ancestorNode.type === "mapping"
);
const isLastDescendant = isLastDescendantNode(path);
return concat([
node.type === "blockFolded" ? ">" : "|",
node.indent === null ? "" : node.indent.toString(),
@@ -232,58 +250,42 @@ function _print(node, parentNode, path, options, print) {
hasTrailingComments(node)
? concat([" ", join(hardline, path.map(print, "trailingComments"))])
: "",
value === ""
? ""
: (node.indent === null ? dedent : dedentToRoot)(
align(
node.indent === null
? options.tabWidth
: node.indent -
1 +
getAncestorCount(
path,
ancestorNode =>
ancestorNode.type === "sequence" ||
ancestorNode.type === "mapping"
),
(node.chomping === "keep" && node.value === "\n"
? dedentToRoot
: markAsRoot)(
concat(
(node.type === "blockLiteral"
? value
: restoreBlockFoldedValue(value)
)
.split("\n")
.reduce(
(reduced, lineContent, index, lines) =>
reduced.concat(
node.type === "blockLiteral"
? lineContent
: fill(
join(
line,
lineContent
// split by single space
.replace(/(^|[^ ]) ([^ ]|$)/g, "$1\n$2")
.split("\n")
).parts
),
index === lines.length - 1 &&
!/\s$/.test(lineContent)
? []
: /\s$/.test(lineContent)
? index === lines.length - 1
? dedentToRoot(literalline)
: literalline
: hardline
),
[hardline]
)
)
)
(node.indent === null ? dedent : dedentToRoot)(
align(
node.indent === null
? options.tabWidth
: node.indent - 1 + parentIndent,
concat(
getBlockValueLineContents(node, {
parentIndent,
isLastDescendant,
options
}).reduce(
(reduced, lineWords, index, lineContents) =>
reduced.concat(
index === 0
? hardline
: lineContents[index - 1].length === 0
? hardline
: index === lineContents.length - 1 &&
lineWords.length === 0
? dedentToRoot(literalline)
: markAsRoot(literalline),
fill(join(line, lineWords).parts),
index === lineContents.length - 1 &&
node.chomping === "keep" &&
isLastDescendant
? lineWords.length === 0 ||
!getLast(lineWords).endsWith(" ")
? dedentToRoot(hardline)
: dedentToRoot(literalline)
: []
),
[]
)
)
)
)
]);
}
case "sequence":
@@ -481,6 +483,16 @@ function printNextEmptyLine(path, originalText) {
return "";
}
function printFlowScalarContent(nodeType, content, options) {
const lineContents = getFlowScalarLineContents(nodeType, content, options);
return join(
hardline,
lineContents.map(lineContentWords =>
fill(join(line, lineContentWords).parts)
)
);
}
function clean(node, newNode /*, parent */) {
if (isNode(newNode)) {
delete newNode.position;
+171 -29
View File
@@ -137,33 +137,6 @@ function hasExplicitDocumentEndMarker(document, text) {
);
}
function restoreBlockFoldedValue(value) {
const lines = value.split("\n");
let hasChecked = false;
let isIndented = false;
for (let i = 0; i < lines.length; i++) {
const lineContent = lines[i];
if (!lineContent) {
continue;
}
if (/^\s/.test(lineContent[0])) {
isIndented = true;
} else {
if (!isIndented && i !== 0 && hasChecked) {
lines[i] = "\n" + lineContent;
}
isIndented = false;
}
hasChecked = true;
}
return lines.join("\n");
}
function isBlockValue(node) {
switch (node.type) {
case "blockFolded":
@@ -186,6 +159,174 @@ function hasTrailingComments(node) {
return "trailingComments" in node && node.trailingComments.length !== 0;
}
/**
* " a b c d e f " -> [" a b", "c d", "e f "]
*/
function splitWithSingleSpace(text) {
const parts = [];
let lastPart = undefined;
for (const part of text.split(/( +)/g)) {
if (part !== " ") {
if (lastPart === " ") {
parts.push(part);
} else {
parts.push((parts.pop() || "") + part);
}
} else if (lastPart === undefined) {
parts.unshift("");
}
lastPart = part;
}
if (lastPart === " ") {
parts.push((parts.pop() || "") + " ");
}
if (parts[0] === "") {
parts.shift();
parts.unshift(" " + (parts.shift() || ""));
}
return parts;
}
function getFlowScalarLineContents(nodeType, content, options) {
const rawLineContents = content
.split("\n")
.map(
(lineContent, index, lineContents) =>
index === 0 && index === lineContents.length - 1
? lineContent
: index !== 0 && index !== lineContents.length - 1
? lineContent.trim()
: index === 0
? lineContent.trimRight()
: lineContent.trimLeft()
);
if (options.proseWrap === "preserve") {
return rawLineContents.map(
lineContent => (lineContent.length === 0 ? [] : [lineContent])
);
}
return rawLineContents
.map(
lineContent =>
lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent)
)
.reduce(
(reduced, lineContentWords, index) =>
index !== 0 &&
rawLineContents[index - 1].length !== 0 &&
lineContentWords.length !== 0 &&
!// trailing backslash in quoteDouble should be preserved
(nodeType === "quoteDouble" && getLast(getLast(reduced)).endsWith("\\"))
? reduced.concat([reduced.pop().concat(lineContentWords)])
: reduced.concat([lineContentWords]),
[]
)
.map(
lineContentWords =>
options.proseWrap === "never"
? [lineContentWords.join(" ")]
: lineContentWords
);
}
function getBlockValueLineContents(
node,
{ parentIndent, isLastDescendant, options }
) {
const content =
node.position.start.line === node.position.end.line
? ""
: options.originalText
.slice(node.position.start.offset, node.position.end.offset)
// exclude open line `>` or `|`
.match(/^[^\n]*?\n([\s\S]*)$/)[1];
const leadingSpaceCount =
node.indent === null
? (match => (match ? match[1].length : Infinity))(
content.match(/^( *)\S/m)
)
: node.indent - 1 + parentIndent;
const rawLineContents = content
.split("\n")
.map(lineContent => lineContent.slice(leadingSpaceCount));
if (options.proseWrap === "preserve" || node.type === "blockLiteral") {
return removeUnnecessaryTrailingNewlines(
rawLineContents.map(
lineContent => (lineContent.length === 0 ? [] : [lineContent])
)
);
}
return removeUnnecessaryTrailingNewlines(
rawLineContents
.map(
lineContent =>
lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent)
)
.reduce(
(reduced, lineContentWords, index) =>
index !== 0 &&
rawLineContents[index - 1].length !== 0 &&
lineContentWords.length !== 0 &&
!/^\s/.test(lineContentWords[0]) &&
!/^\s|\s$/.test(getLast(reduced))
? reduced.concat([reduced.pop().concat(lineContentWords)])
: reduced.concat([lineContentWords]),
[]
)
.map(lineContentWords =>
lineContentWords.reduce(
(reduced, word) =>
// disallow trailing spaces
reduced.length !== 0 && /\s$/.test(getLast(reduced))
? reduced.concat(reduced.pop() + " " + word)
: reduced.concat(word),
[]
)
)
.map(
lineContentWords =>
options.proseWrap === "never"
? [lineContentWords.join(" ")]
: lineContentWords
)
);
function removeUnnecessaryTrailingNewlines(lineContents) {
if (node.chomping === "keep") {
return getLast(lineContents).length === 0
? lineContents.slice(0, -1)
: lineContents;
}
let trailingNewlineCount = 0;
for (let i = lineContents.length - 1; i >= 0; i--) {
if (lineContents[i].length === 0) {
trailingNewlineCount++;
} else {
break;
}
}
return trailingNewlineCount === 0
? lineContents
: trailingNewlineCount >= 2 && !isLastDescendant
? // next empty line
lineContents.slice(0, -(trailingNewlineCount - 1))
: lineContents.slice(0, -trailingNewlineCount);
}
}
module.exports = {
getLast,
getAncestorCount,
@@ -196,11 +337,12 @@ module.exports = {
createNull,
isNextLineEmpty,
isLastDescendantNode,
getBlockValueLineContents,
getFlowScalarLineContents,
getLastDescendantNode,
hasPrettierIgnore,
hasLeadingComments,
hasMiddleComments,
hasTrailingComments,
hasExplicitDocumentEndMarker,
restoreBlockFoldedValue
hasExplicitDocumentEndMarker
};
+1 -1
View File
@@ -58,7 +58,7 @@ function attachComments(text, ast, opts) {
comments.attach(astComments, ast, text, opts);
}
ast.tokens = [];
opts.originalText = text.trimRight();
opts.originalText = opts.parser === "yaml" ? text : text.trimRight();
return astComments;
}
@@ -7,6 +7,21 @@ exports[`clip.yml - yaml-verify 1`] = `
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
123
456
789
`;
exports[`clip.yml - yaml-verify 2`] = `
>
123
456
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
123 456 789
@@ -20,6 +35,21 @@ exports[`indent.yml - yaml-verify 1`] = `
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>2-
123
456
789
`;
exports[`indent.yml - yaml-verify 2`] = `
>2-
123
456
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>2-
123
@@ -35,6 +65,23 @@ exports[`keep.yml - yaml-verify 1`] = `
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>+
123
456
789
`;
exports[`keep.yml - yaml-verify 2`] = `
>+
123
456
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>+
123 456 789
@@ -57,6 +104,39 @@ d: >
456
789
c: 0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: >
123
456
789
b: >1
123
456
789
d: >
123
456
789
c: 0
`;
exports[`map.yml - yaml-verify 2`] = `
a: >
123
456
789
b: >1
123
456
789
d: >
123
456
789
c: 0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: >
@@ -83,6 +163,17 @@ exports[`middle-comment.yml - yaml-verify 1`] = `
`;
exports[`middle-comment.yml - yaml-verify 2`] = `
!!str #comment
>
123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!str #comment
>
123
`;
exports[`middle-comments.yml - yaml-verify 1`] = `
!!str # comment 1
# comment 2
@@ -97,6 +188,20 @@ exports[`middle-comments.yml - yaml-verify 1`] = `
`;
exports[`middle-comments.yml - yaml-verify 2`] = `
!!str # comment 1
# comment 2
>
123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!str
# comment 1
# comment 2
>
123
`;
exports[`newline.yml - yaml-verify 1`] = `
- >+
123
@@ -113,6 +218,71 @@ exports[`newline.yml - yaml-verify 1`] = `
789
- >2+
123
456
789
123
456
789
123
456
789
- 0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- >+
123
456
789
123
456
789
123
456
789
- >2+
123
456
789
123
456
789
123
456
789
- 0
`;
exports[`newline.yml - yaml-verify 2`] = `
- >+
123
456
789
123
456
789
123
456
789
- >2+
123
456
@@ -167,6 +337,73 @@ exports[`newline-unaligned.yml - yaml-verify 1`] = `
6
1
2
3
4
5
6
1
2
3
4
5
6
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
1
2
3
4
5
6
1
2
3
4
5
6
1
2
3
4
5
6
1
2
3
4
5
6
`;
exports[`newline-unaligned.yml - yaml-verify 2`] = `
>
1
2
3
4
5
6
1
2
3
4
5
6
1
2
3
@@ -218,6 +455,15 @@ exports[`props.yml - yaml-verify 1`] = `
`;
exports[`props.yml - yaml-verify 2`] = `
!!str &anchor >
123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!str &anchor >
123
`;
exports[`props-in-map.yml - yaml-verify 1`] = `
a: !!str &anchor >
123
@@ -227,6 +473,15 @@ a: !!str &anchor >
`;
exports[`props-in-map.yml - yaml-verify 2`] = `
a: !!str &anchor >
123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: !!str &anchor >
123
`;
exports[`prose.yml - yaml-verify 1`] = `
>
123 456 789
@@ -270,6 +525,93 @@ exports[`prose.yml - yaml-verify 1`] = `
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
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
`;
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
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
@@ -295,6 +637,29 @@ exports[`seq.yml - yaml-verify 1`] = `
789
- 0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- >
123
456
789
- >1
123
456
789
- 0
`;
exports[`seq.yml - yaml-verify 2`] = `
- >
123
456
789
- >1
123
456
789
- 0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- >
123 456 789
- >1
@@ -312,6 +677,21 @@ exports[`strip.yml - yaml-verify 1`] = `
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>-
123
456
789
`;
exports[`strip.yml - yaml-verify 2`] = `
>-
123
456
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>-
123 456 789
@@ -326,3 +706,12 @@ a: !!str > # hello
hello
`;
exports[`trailing-comment.yml - yaml-verify 2`] = `
a: !!str > # hello
hello
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: !!str > # hello
hello
`;
+1
View File
@@ -1 +1,2 @@
run_spec(__dirname, ["yaml"]);
run_spec(__dirname, ["yaml"], { proseWrap: "always" });
@@ -7,6 +7,21 @@ exports[`clip.yml - yaml-verify 1`] = `
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
123
456
789
`;
exports[`clip.yml - yaml-verify 2`] = `
|
123
456
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
123
@@ -22,6 +37,21 @@ exports[`indent.yml - yaml-verify 1`] = `
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|2-
123
456
789
`;
exports[`indent.yml - yaml-verify 2`] = `
|2-
123
456
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|2-
123
@@ -45,6 +75,23 @@ exports[`keep.yml - yaml-verify 1`] = `
`;
exports[`keep.yml - yaml-verify 2`] = `
|+
123
456
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|+
123
456
789
`;
exports[`map.yml - yaml-verify 1`] = `
@@ -80,6 +127,39 @@ c: 0
`;
exports[`map.yml - yaml-verify 2`] = `
a: |
123
456
789
b: |1
123
456
789
d: |
123
456
789
c: 0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: |
123
456
789
b: |1
123
456
789
d: |
123
456
789
c: 0
`;
exports[`middle-comment.yml - yaml-verify 1`] = `
!!str #comment
|
@@ -91,6 +171,17 @@ exports[`middle-comment.yml - yaml-verify 1`] = `
`;
exports[`middle-comment.yml - yaml-verify 2`] = `
!!str #comment
|
123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!str #comment
|
123
`;
exports[`middle-comments.yml - yaml-verify 1`] = `
!!str # comment 1
# comment 2
@@ -105,6 +196,20 @@ exports[`middle-comments.yml - yaml-verify 1`] = `
`;
exports[`middle-comments.yml - yaml-verify 2`] = `
!!str # comment 1
# comment 2
|
123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!str
# comment 1
# comment 2
|
123
`;
exports[`newline.yml - yaml-verify 1`] = `
- |+
123
@@ -122,6 +227,27 @@ exports[`newline.yml - yaml-verify 1`] = `
- 0
`;
exports[`newline.yml - yaml-verify 2`] = `
- |+
123
456
789
- 0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- |+
123
456
789
- 0
`;
@@ -193,6 +319,73 @@ exports[`newline-unaligned.yml - yaml-verify 1`] = `
`;
exports[`newline-unaligned.yml - yaml-verify 2`] = `
|
1
2
3
4
5
6
1
2
3
4
5
6
1
2
3
4
5
6
1
2
3
4
5
6
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
1
2
3
4
5
6
1
2
3
4
5
6
1
2
3
4
5
6
1
2
3
4
5
6
`;
exports[`props.yml - yaml-verify 1`] = `
!!str &anchor |
123
@@ -202,6 +395,15 @@ exports[`props.yml - yaml-verify 1`] = `
`;
exports[`props.yml - yaml-verify 2`] = `
!!str &anchor |
123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!str &anchor |
123
`;
exports[`props-in-map.yml - yaml-verify 1`] = `
a: !!str &anchor |
123
@@ -211,6 +413,15 @@ a: !!str &anchor |
`;
exports[`props-in-map.yml - yaml-verify 2`] = `
a: !!str &anchor |
123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: !!str &anchor |
123
`;
exports[`seq.yml - yaml-verify 1`] = `
- |
123
@@ -234,6 +445,29 @@ exports[`seq.yml - yaml-verify 1`] = `
`;
exports[`seq.yml - yaml-verify 2`] = `
- |
123
456
789
- |1
123
456
789
- 0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- |
123
456
789
- |1
123
456
789
- 0
`;
exports[`strip.yml - yaml-verify 1`] = `
|-
123
@@ -241,6 +475,21 @@ exports[`strip.yml - yaml-verify 1`] = `
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|-
123
456
789
`;
exports[`strip.yml - yaml-verify 2`] = `
|-
123
456
789
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|-
123
@@ -257,3 +506,12 @@ a: !!str | # hello
hello
`;
exports[`trailing-comment.yml - yaml-verify 2`] = `
a: !!str | # hello
hello
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: !!str | # hello
hello
`;
+1
View File
@@ -1 +1,2 @@
run_spec(__dirname, ["yaml"]);
run_spec(__dirname, ["yaml"], { proseWrap: "always" });
@@ -9,6 +9,24 @@ hello
`;
exports[`middle-comment.yml - yaml-verify 2`] = `
!!str # comment
hello
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!str # comment
hello
`;
exports[`middle-comment.yml - yaml-verify 3`] = `
!!str # comment
hello
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!str # comment
hello
`;
exports[`middle-comments.yml - yaml-verify 1`] = `
!!str # comment 1
# comment 2
@@ -21,6 +39,145 @@ hello
`;
exports[`middle-comments.yml - yaml-verify 2`] = `
!!str # comment 1
# comment 2
hello
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!str
# comment 1
# comment 2
hello
`;
exports[`middle-comments.yml - yaml-verify 3`] = `
!!str # comment 1
# comment 2
hello
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!str
# comment 1
# comment 2
hello
`;
exports[`multiline.yml - yaml-verify 1`] = `
b:
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
b: 123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
`;
exports[`multiline.yml - yaml-verify 2`] = `
b:
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
b:
123123123123123123123123123 123123123123123123123123123 123123123123123123123123123 123123123123123123123123123 123123123123123123123123123 123123123123123123123123123 123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
`;
exports[`multiline.yml - yaml-verify 3`] = `
b:
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
b: 123123123123123123123123123 123123123123123123123123123
123123123123123123123123123 123123123123123123123123123
123123123123123123123123123 123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
`;
exports[`true.yml - yaml-verify 1`] = `
hello
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -28,9 +185,37 @@ hello
`;
exports[`true.yml - yaml-verify 2`] = `
hello
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hello
`;
exports[`true.yml - yaml-verify 3`] = `
hello
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hello
`;
exports[`verbatim.yml - yaml-verify 1`] = `
!<hello> hello
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!<hello> hello
`;
exports[`verbatim.yml - yaml-verify 2`] = `
!<hello> hello
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!<hello> hello
`;
exports[`verbatim.yml - yaml-verify 3`] = `
!<hello> hello
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!<hello> hello
`;
+2
View File
@@ -1 +1,3 @@
run_spec(__dirname, ["yaml"]);
run_spec(__dirname, ["yaml"], { proseWrap: "never" });
run_spec(__dirname, ["yaml"], { proseWrap: "always" });
+19
View File
@@ -0,0 +1,19 @@
b:
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
@@ -1,5 +1,311 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`multiline.yml - yaml-verify 1`] = `
a: "
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
"
b: '
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: "
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
"
b: "
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
"
`;
exports[`multiline.yml - yaml-verify 2`] = `
a: "
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
"
b: '
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: '
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
'
b: '
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
'
`;
exports[`multiline.yml - yaml-verify 3`] = `
a: "
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
"
b: '
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: "
123123123123123123123123123 123123123123123123123123123 123123123123123123123123123 123123123123123123123123123 123123123123123123123123123 123123123123123123123123123 123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
"
b: "
123123123123123123123123123 123123123123123123123123123 123123123123123123123123123 123123123123123123123123123 123123123123123123123123123 123123123123123123123123123 123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
"
`;
exports[`multiline.yml - yaml-verify 4`] = `
a: "
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
"
b: '
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: "
123123123123123123123123123 123123123123123123123123123
123123123123123123123123123 123123123123123123123123123
123123123123123123123123123 123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
"
b: "
123123123123123123123123123 123123123123123123123123123
123123123123123123123123123 123123123123123123123123123
123123123123123123123123123 123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
"
`;
exports[`quote.yml - yaml-verify 1`] = `
- "123"
- '123'
@@ -41,3 +347,45 @@ exports[`quote.yml - yaml-verify 2`] = `
- "\\n123"
`;
exports[`quote.yml - yaml-verify 3`] = `
- "123"
- '123'
- "''"
- '""'
- ''''
- "\\"\\""
- '\\n123'
- "\\n123"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- "123"
- "123"
- "''"
- '""'
- "'"
- '""'
- '\\n123'
- "\\n123"
`;
exports[`quote.yml - yaml-verify 4`] = `
- "123"
- '123'
- "''"
- '""'
- ''''
- "\\"\\""
- '\\n123'
- "\\n123"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- "123"
- "123"
- "''"
- '""'
- "'"
- '""'
- '\\n123'
- "\\n123"
`;
+2
View File
@@ -1,2 +1,4 @@
run_spec(__dirname, ["yaml"]);
run_spec(__dirname, ["yaml"], { singleQuote: true });
run_spec(__dirname, ["yaml"], { proseWrap: "never" });
run_spec(__dirname, ["yaml"], { proseWrap: "always" });
+38
View File
@@ -0,0 +1,38 @@
a: "
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
"
b: '
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
123123123123123123123123123
'
File diff suppressed because it is too large. Load diff
+1
View File
@@ -1 +1,2 @@
run_spec(__dirname, ["yaml"], { useTabs: true });
run_spec(__dirname, ["yaml"], { proseWrap: "always" });
@@ -67,7 +67,7 @@ Format options:
--print-width <int> The line length where Prettier will try wrap.
Defaults to 80.
--prose-wrap <always|never|preserve>
How to wrap prose. (markdown)
How to wrap prose.
Defaults to preserve.
--no-semi Do not print semicolons, except at the beginning of lines which may need them.
--single-quote Use single quotes instead of double quotes.
@@ -217,7 +217,7 @@ Format options:
--print-width <int> The line length where Prettier will try wrap.
Defaults to 80.
--prose-wrap <always|never|preserve>
How to wrap prose. (markdown)
How to wrap prose.
Defaults to preserve.
--no-semi Do not print semicolons, except at the beginning of lines which may need them.
--single-quote Use single quotes instead of double quotes.
@@ -337,7 +337,7 @@ exports[`show detailed usage with --help prose-wrap (stderr) 1`] = `""`;
exports[`show detailed usage with --help prose-wrap (stdout) 1`] = `
"--prose-wrap <always|never|preserve>
How to wrap prose. (markdown)
How to wrap prose.
Valid options:
@@ -161,7 +161,7 @@ Multiple values are accepted.",
},
"proseWrap": Object {
"default": "preserve",
"description": "How to wrap prose. (markdown)",
"description": "How to wrap prose.",
"oneOf": Array [
Object {
"description": "Wrap prose if it exceeds the print width.",
@@ -884,7 +884,7 @@ exports[`CLI --support-info (stdout) 1`] = `
\\"type\\": \\"int\\"
},
{
\\"category\\": \\"Markdown\\",
\\"category\\": \\"Common\\",
\\"choices\\": [
{
\\"description\\": \\"Wrap prose if it exceeds the print width.\\",
@@ -903,7 +903,7 @@ exports[`CLI --support-info (stdout) 1`] = `
}
],
\\"default\\": \\"preserve\\",
\\"description\\": \\"How to wrap prose. (markdown)\\",
\\"description\\": \\"How to wrap prose.\\",
\\"name\\": \\"proseWrap\\",
\\"pluginDefaults\\": {},
\\"since\\": \\"1.8.2\\",
+6 -6
View File
@@ -5965,16 +5965,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-beta.4:
version "1.0.0-beta.4"
resolved "https://registry.yarnpkg.com/yaml-unist-parser/-/yaml-unist-parser-1.0.0-beta.4.tgz#6603d017ec1396466825a141de33637bf2e9e0c2"
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"
dependencies:
lines-and-columns "^1.1.6"
tslib "^1.9.1"
yaml@1.0.0-beta.7:
version "1.0.0-beta.7"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.0.0-beta.7.tgz#681937c5b2d85b6eb474d47e877f5e63a7efe20c"
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"
yargs-parser@^7.0.0:
version "7.0.0"