diff --git a/src/cli-constant.js b/src/cli-constant.js index 12f199f94..92ce7e371 100644 --- a/src/cli-constant.js +++ b/src/cli-constant.js @@ -219,6 +219,13 @@ const detailedOptions = normalizeDetailedOptions({ forwardToApi: true, description: "The line length where Prettier will try wrap." }, + "prose-wrap": { + type: "boolean", + category: CATEGORY_FORMAT, + forwardToApi: true, + description: "Wrap prose if it exceeds the print width. (markdown)", + oppositeDescription: "Do not wrap prose. (markdown)" + }, "range-end": { type: "int", category: CATEGORY_EDITOR, diff --git a/src/options.js b/src/options.js index d981e2a1f..19c34ab80 100644 --- a/src/options.js +++ b/src/options.js @@ -20,7 +20,8 @@ const defaults = { parser: "babylon", insertPragma: false, requirePragma: false, - semi: true + semi: true, + proseWrap: true }; const exampleConfig = Object.assign({}, defaults, { diff --git a/src/printer-markdown.js b/src/printer-markdown.js index da68a8719..ac9c0806a 100644 --- a/src/printer-markdown.js +++ b/src/printer-markdown.js @@ -60,7 +60,7 @@ function genericPrint(path, options, print) { node => node.type === "word" ? node.value - : node.value === "" ? "" : printLine(path, line) + : node.value === "" ? "" : printLine(path, line, options) ) ); } @@ -92,7 +92,7 @@ function genericPrint(path, options, print) { return node.value === "" ? "" : " "; } - return printLine(path, node.value === "" ? softline : line); + return printLine(path, node.value === "" ? softline : line, options); } case "emphasis": { const parentNode = path.getParentNode(); @@ -125,7 +125,7 @@ function genericPrint(path, options, print) { case "inlineCode": { const backtickCount = util.getMaxContinuousCount(node.value, "`"); const style = backtickCount === 1 ? "``" : "`"; - const gap = backtickCount ? printLine(path, line) : ""; + const gap = backtickCount ? printLine(path, line, options) : ""; return concat([ style, gap, @@ -354,8 +354,9 @@ function getAncestorNode(path, typeOrTypes) { return counter === -1 ? null : path.getParentNode(counter); } -function printLine(path, lineOrSoftline) { - const isBreakable = !getAncestorNode(path, SINGLE_LINE_NODE_TYPES); +function printLine(path, lineOrSoftline, options) { + const isBreakable = + options.proseWrap && !getAncestorNode(path, SINGLE_LINE_NODE_TYPES); return lineOrSoftline === line ? isBreakable ? line : " " : isBreakable ? softline : ""; diff --git a/tests/markdown_paragraph/__snapshots__/jsfmt.spec.js.snap b/tests/markdown_paragraph/__snapshots__/jsfmt.spec.js.snap index 836c87132..aae56f7f3 100644 --- a/tests/markdown_paragraph/__snapshots__/jsfmt.spec.js.snap +++ b/tests/markdown_paragraph/__snapshots__/jsfmt.spec.js.snap @@ -26,6 +26,21 @@ English 混合著中文的一段 Paragraph! `; +exports[`cjk.md 2`] = ` +這是一段很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長的段落 + +這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph! + +全  形 空白全  形 空白全  形 空白全  形 空白全  形 空白全  形 空白全  形 空白全  形 空白 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +這是一段很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長的段落 + +這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph! + +全  形 空白全  形 空白全  形 空白全  形 空白全  形 空白全  形 空白全  形 空白全  形 空白 + +`; + exports[`inline-nodes.md 1`] = ` It removes all original styling[*](#styling-footnote) and ensures that all outputted code conforms to a consistent style. (See this [blog post](http://jlongster.com/A-Prettier-Formatter)) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -35,6 +50,13 @@ post](http://jlongster.com/A-Prettier-Formatter)) `; +exports[`inline-nodes.md 2`] = ` +It removes all original styling[*](#styling-footnote) and ensures that all outputted code conforms to a consistent style. (See this [blog post](http://jlongster.com/A-Prettier-Formatter)) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +It removes all original styling[\\*](#styling-footnote) and ensures that all outputted code conforms to a consistent style. (See this [blog post](http://jlongster.com/A-Prettier-Formatter)) + +`; + exports[`simple.md 1`] = ` This is a long long long long long long long long long long long long long long long paragraph. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -43,6 +65,13 @@ long paragraph. `; +exports[`simple.md 2`] = ` +This is a long long long long long long long long long long long long long long long paragraph. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +This is a long long long long long long long long long long long long long long long paragraph. + +`; + exports[`special-prefix.md 1`] = ` abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc - abc abc abc @@ -90,3 +119,45 @@ abc - abc abc abc ensure expect is called correctly. `; + +exports[`special-prefix.md 2`] = ` +abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc - abc abc abc + +## Supported Rules + +- [no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md) - disallow disabled tests. +- [no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md) - disallow focused tests. +- [no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md) - disallow identical titles. +- [valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md) - ensure expect is called correctly. + +## Supported Rules + +* [no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md) + - disallow disabled tests. +* [no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md) + - disallow focused tests. +* [no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md) + - disallow identical titles. +* [valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md) - + ensure expect is called correctly. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc - abc abc abc + +## Supported Rules + +* [no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md) - disallow disabled tests. +* [no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md) - disallow focused tests. +* [no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md) - disallow identical titles. +* [valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md) - ensure expect is called correctly. + +## Supported Rules + +* [no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md) + * disallow disabled tests. +* [no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md) + * disallow focused tests. +* [no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md) + * disallow identical titles. +* [valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md) - ensure expect is called correctly. + +`; diff --git a/tests/markdown_paragraph/jsfmt.spec.js b/tests/markdown_paragraph/jsfmt.spec.js index 552a6a92a..bf68bfb8f 100644 --- a/tests/markdown_paragraph/jsfmt.spec.js +++ b/tests/markdown_paragraph/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname, { parser: "markdown" }); +run_spec(__dirname, { parser: "markdown", proseWrap: false }); diff --git a/tests_integration/__tests__/__snapshots__/early-exit.js.snap b/tests_integration/__tests__/__snapshots__/early-exit.js.snap index 184fcd149..681c3baed 100644 --- a/tests_integration/__tests__/__snapshots__/early-exit.js.snap +++ b/tests_integration/__tests__/__snapshots__/early-exit.js.snap @@ -208,6 +208,17 @@ exports[`show detailed usage with --help no-config (stdout) 1`] = ` exports[`show detailed usage with --help no-config (write) 1`] = `Array []`; +exports[`show detailed usage with --help no-prose-wrap (stderr) 1`] = `""`; + +exports[`show detailed usage with --help no-prose-wrap (stdout) 1`] = ` +"--no-prose-wrap + + Do not wrap prose. (markdown) +" +`; + +exports[`show detailed usage with --help no-prose-wrap (write) 1`] = `Array []`; + exports[`show detailed usage with --help no-semi (stderr) 1`] = `""`; exports[`show detailed usage with --help no-semi (stdout) 1`] = ` @@ -257,6 +268,19 @@ Default: 80 exports[`show detailed usage with --help print-width (write) 1`] = `Array []`; +exports[`show detailed usage with --help prose-wrap (stderr) 1`] = `""`; + +exports[`show detailed usage with --help prose-wrap (stdout) 1`] = ` +"--prose-wrap + + Wrap prose if it exceeds the print width. (markdown) + +Default: true +" +`; + +exports[`show detailed usage with --help prose-wrap (write) 1`] = `Array []`; + exports[`show detailed usage with --help range-end (stderr) 1`] = `""`; exports[`show detailed usage with --help range-end (stdout) 1`] = ` @@ -461,6 +485,7 @@ Format options: Defaults to babylon. --print-width The line length where Prettier will try wrap. Defaults to 80. + --no-prose-wrap Do not wrap prose. (markdown) --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. Defaults to false. @@ -593,6 +618,7 @@ Format options: Defaults to babylon. --print-width The line length where Prettier will try wrap. Defaults to 80. + --no-prose-wrap Do not wrap prose. (markdown) --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. Defaults to false.