Skip to content

Commit

Permalink
fix: dash lines
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinmd committed Jan 31, 2021
1 parent 3ef160d commit 33df06d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
59 changes: 37 additions & 22 deletions src/descriptionFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { capitalizer } from "./utils";

const EMPTY_LINE_SIGNATURE = "2@^5!~#sdE!_EMPTY_LINE_SIGNATURE";
const NEW_LINE_START_WITH_DASH = "2@^5!~#sdE!_NEW_LINE_START_WITH_DASH";
const NEW_DASH_LINE = "2@^5!~#sdE!_NEW_LINE_WITH_DASH";
const NEW_LINE_START_WITH_NUMBER = "2@^5!~#sdE!_NEW_LINE_START_WITH_NUMBER";
const NEW_PARAGRAPH_START_WITH_DASH =
"2@^5!~#sdE!_NEW_PARAGRAPH_START_WITH_DASH";
Expand Down Expand Up @@ -94,6 +95,11 @@ function formatDescription(
});
}

text = text.replace(
/(\n(\s+|)(---(\s|-)+)\n)/g, // `\n\n - ` | `\n\n-` | `\n\n -` | `\n\n- `
NEW_DASH_LINE,
);

text = text.replace(
/(\n\n\s\s\s+)|(\n\s+\n\s\s\s+)/g,
NEW_PARAGRAPH_START_THREE_SPACE_SIGNATURE,
Expand Down Expand Up @@ -137,30 +143,39 @@ function formatDescription(
.map(
(newLineWithNumber) =>
newLineWithNumber
.split(NEW_PARAGRAPH_START_WITH_DASH)
.split(NEW_DASH_LINE)
.map(
(newLineWithDash) =>
newLineWithDash
.split(NEW_LINE_START_WITH_DASH)
.map((paragraph) => {
paragraph = paragraph.replace(/[\n\s]+/g, " "); // Make single line

paragraph = capitalizer(paragraph);
if (options.jsdocDescriptionWithDot)
paragraph = paragraph.replace(
/(\w)(?=$)/g,
"$1.",
); // Insert dot if needed

return breakDescriptionToLines(
paragraph,
maxWidth,
beginningSpace,
);
})
.join("\n- "), // NEW_LINE_START_WITH_DASH
(newDashLine) =>
newDashLine
.split(NEW_PARAGRAPH_START_WITH_DASH)
.map(
(newLineWithDash) =>
newLineWithDash
.split(NEW_LINE_START_WITH_DASH)
.map((paragraph) => {
paragraph = paragraph.replace(
/[\n\s]+/g,
" ",
); // Make single line

paragraph = capitalizer(paragraph);
if (options.jsdocDescriptionWithDot)
paragraph = paragraph.replace(
/(\w)(?=$)/g,
"$1.",
); // Insert dot if needed

return breakDescriptionToLines(
paragraph,
maxWidth,
beginningSpace,
);
})
.join("\n- "), // NEW_LINE_START_WITH_DASH
)
.join("\n\n- "), // NEW_PARAGRAPH_START_WITH_DASH
)
.join("\n\n- "), // NEW_PARAGRAPH_START_WITH_DASH
.join(`\n ${"-".repeat(printWidth / 2)}\n`), // NEW_DASH_LINE
)
.join("\n"), // NEW_LINE_START_WITH_NUMBER
)
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { format, Options } from "prettier";

function convertToModernArray(type: string): string {
if (!type) {
return type;
Expand Down

0 comments on commit 33df06d

Please sign in to comment.