Skip to content

Commit

Permalink
fix(description): empty lines
Browse files Browse the repository at this point in the history
issue: #75
  • Loading branch information
hosseinmd committed Feb 12, 2021
1 parent d9a5617 commit 7d89a66
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/descriptionFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand All @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion tests/__snapshots__/paragraph.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ exports[`description new line with dash 3`] = `
* -------------------------------------
* {expected token stream}
*
* or of three parts:
* Or of three parts:
*
* {source code}
* -------------------------------------
Expand All @@ -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 ===========================
Expand Down
21 changes: 21 additions & 0 deletions tests/paragraph.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7d89a66

Please sign in to comment.