From 7d89a661bf819c5fca291b7e76daafbe8496e85c Mon Sep 17 00:00:00 2001 From: Hossein Mohammadi Date: Fri, 12 Feb 2021 20:09:07 +0330 Subject: [PATCH] fix(description): empty lines issue: https://github.com/hosseinmd/prettier-plugin-jsdoc/issues/75 --- src/descriptionFormatter.ts | 8 ++++---- tests/__snapshots__/paragraph.test.js.snap | 13 ++++++++++++- tests/paragraph.test.js | 21 +++++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/descriptionFormatter.ts b/src/descriptionFormatter.ts index 586531f..22ed60a 100644 --- a/src/descriptionFormatter.ts +++ b/src/descriptionFormatter.ts @@ -93,17 +93,17 @@ function formatDescription( } text = text.replace( - /(\n(\s+|)(---(\s|-)+)\n)/g, // `------- --- --- -` | `----` + /(\n(\s+)?(---(\s|-)+)\n)/g, // `------- --- --- -` | `----` NEW_DASH_LINE, ); text = text.replace( - /(\n(\s+|)\n\s\s\s+)/g, + /(\n([^\S\r\n]+)?\n[^\S\r\n]{2}[^\S\r\n]+)/g, NEW_PARAGRAPH_START_THREE_SPACE_SIGNATURE, ); // Add a signature for new paragraph start with three space text = text.replace( - /(\n\n+(\s+|)-(\s+|))/g, // `\n\n - ` | `\n\n-` | `\n\n -` | `\n\n- ` + /(\n\n+(\s+)?-(\s+)?)/g, // `\n\n - ` | `\n\n-` | `\n\n -` | `\n\n- ` NEW_PARAGRAPH_START_WITH_DASH, ); @@ -112,7 +112,7 @@ function formatDescription( NEW_LINE_START_WITH_DASH, ); - text = text.replace(/(\n\n)|(\n\s+\n)/g, EMPTY_LINE_SIGNATURE); // Add a signature for empty line and use that later + text = text.replace(/(\n(\s+)?\n+)/g, EMPTY_LINE_SIGNATURE); // Add a signature for empty line and use that later // text = text.replace(/\n\s\s\s+/g, NEW_LINE_START_THREE_SPACE_SIGNATURE); // Add a signature for new line start with three space text = capitalizer(text); diff --git a/tests/__snapshots__/paragraph.test.js.snap b/tests/__snapshots__/paragraph.test.js.snap index e5acd76..d50dc1a 100644 --- a/tests/__snapshots__/paragraph.test.js.snap +++ b/tests/__snapshots__/paragraph.test.js.snap @@ -278,7 +278,7 @@ exports[`description new line with dash 3`] = ` * ------------------------------------- * {expected token stream} * - * or of three parts: + * Or of three parts: * * {source code} * ------------------------------------- @@ -301,6 +301,17 @@ exports[`description start underscores 1`] = ` " `; +exports[`empty lines 1`] = ` +"/** + * Foo + * + * Bar + * + * @param a Baz + */ +" +`; + exports[`numbers and code in description 1`] = ` "/** * =========================== PressResponder Tutorial =========================== diff --git a/tests/paragraph.test.js b/tests/paragraph.test.js index 37bf463..7c77abf 100644 --- a/tests/paragraph.test.js +++ b/tests/paragraph.test.js @@ -423,6 +423,27 @@ test("`#` in text", () => { expect(result1).toMatchSnapshot(); }); +test("empty lines", () => { + const result1 = subject( + `/** +* Foo +* +* +* +* +* +* Bar +* +* +* +* +* @param a Baz +*/`, + ); + + expect(result1).toMatchSnapshot(); +}); + /** * If this is a vertical ScrollView scrolls to the bottom. * If this is a horizontal ScrollView scrolls to the right.