Skip to content

Commit

Permalink
fix: jsdocDescriptionWithDot with germany words
Browse files Browse the repository at this point in the history
issue: #76
  • Loading branch information
hosseinmd committed Feb 12, 2021
1 parent 7d89a66 commit 041c882
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/descriptionFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function formatDescription(
paragraph = capitalizer(paragraph);
if (options.jsdocDescriptionWithDot)
paragraph = paragraph.replace(
/(\w)$/g,
/([\wäöüÄÖÜß])$/g,

This comment has been minimized.

Copy link
@RunDevelopment

RunDevelopment Feb 12, 2021

Contributor

@hosseinmd My French, Spanish, and Japanese friends won't like this. Consider using a Unicode property escape. I'd use /\p{L}/u.

This comment has been minimized.

Copy link
@hosseinmd

hosseinmd Feb 12, 2021

Author Owner

PR please.

"$1.",
); // Insert dot if needed

Expand Down
11 changes: 4 additions & 7 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,10 @@ function convertCommentDescToDescTag(parsed: commentParser.Comment): void {
let description = parsed.description || "";
parsed.description = "";

parsed.tags = parsed.tags.filter((t) => {
if (t.tag.toLowerCase() === DESCRIPTION) {
// get description from source as some words may be parsed as the type
// or name
const desc = t.source.replace(/^@\w+/, "").trim();
if (desc) {
description += "\n\n" + desc;
parsed.tags = parsed.tags.filter(({ description: _description, tag }) => {
if (tag.toLowerCase() === DESCRIPTION) {
if (_description.trim()) {
description += "\n\n" + _description;
}
return false;
} else {
Expand Down
15 changes: 14 additions & 1 deletion tests/__snapshots__/paragraph.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ exports[`\`#\` in text 1`] = `
"
`;

exports[`Germany description with dot 1`] = `
"/**
* Wir brauchen hier eine effizientere Lösung. Die generierten Dateien sind zu groß.
*
* Wir brauchen hier eine effizientere Lösung. Die generierten Dateien sind zu 3434.
*
* Wir brauchen hier eine effizientere Lösung. Die generierten Dateien sind zu groß.
*
* @param a Ssss.
*/
"
`;

exports[`code in description 1`] = `
"/**
* \`Touchable\`: Taps done right.
Expand Down Expand Up @@ -392,7 +405,7 @@ exports[`numbers and code in description 3`] = `
* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
* tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
* quis nostrud exercitation ullamco laboris nisi ut aliq W3C Software Notice
* and License: https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
* and License: https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document.
*/
"
`;
Expand Down
42 changes: 40 additions & 2 deletions tests/paragraph.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ test("numbers and code in description", () => {
`);
expect(result2).toMatchSnapshot();

const result3 = subject(`
const result3 = subject(
`
/**
* The script uses two heuristics to determine whether the keyboard is being used:
*
Expand All @@ -254,7 +255,18 @@ test("numbers and code in description", () => {
* W3C Software Notice and License: https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
*/
`);
`,
{
jsdocDescriptionWithDot: true,
},
);

expect(
subject(result3, {
jsdocDescriptionWithDot: true,
}),
).toEqual(result3);

expect(result3).toMatchSnapshot();
});

Expand Down Expand Up @@ -444,6 +456,32 @@ test("empty lines", () => {
expect(result1).toMatchSnapshot();
});

test("Germany description with dot", () => {
const result = subject(
`/**
* Wir brauchen hier eine effizientere Lösung. Die generierten Dateien sind zu groß
*
* Wir brauchen hier eine effizientere Lösung. Die generierten Dateien sind zu 3434
*
* @description Wir brauchen hier eine effizientere Lösung. Die generierten Dateien sind zu groß
* @param a ssss
*/`,
{
jsdocDescriptionWithDot: true,
},
);

expect(result).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 041c882

Please sign in to comment.