Skip to content

Commit

Permalink
fix: incorrect comment format
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinmd committed Dec 29, 2020
1 parent ccafeda commit 1ac43d1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,27 @@ export const getParser = (parser: any) =>
// Parse only comment blocks
if (comment.type !== "CommentBlock" && comment.type !== "Block") return;

/** Issue: https://github.com/hosseinmd/prettier-plugin-jsdoc/issues/18 */
comment.value = comment.value.replace(/^([*]+)/g, "*");

const commentString = `/*${comment.value}*/`;

// Check if this comment block is a JSDoc. Based on:
// https://github.com/jsdoc/jsdoc/blob/master/packages/jsdoc/plugins/commentsOnly.js
/**
* Check if this comment block is a JSDoc. Based on:
* https://github.com/jsdoc/jsdoc/blob/master/packages/jsdoc/plugins/commentsOnly.js
*/
if (!commentString.match(/\/\*\*[\s\S]+?\*\//g)) return;

const parsed = commentParser(commentString, {
dotted_names: false,
trim: false,
})[0];

if (!parsed) {
// Error on commentParser
return;
}

comment.value = "";

convertCommentDescToDescTag(parsed);
Expand Down
6 changes: 6 additions & 0 deletions tests/__snapshots__/main.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ exports[`Hyphen at the start of description 1`] = `
"
`;

exports[`Incorrect comment 1`] = `
"/** Some comment */
export class Dummy {}
"
`;

exports[`JS code should be formatted as usuall 1`] = `
"const variable1 = 1; // No semicolon
const stringVar = \\"text\\"; // Wrong quotes
Expand Down
11 changes: 11 additions & 0 deletions tests/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,14 @@ test("since ", () => {

expect(result).toMatchSnapshot();
});

test("Incorrect comment", () => {
const result = subject(`
/***
* Some comment
*/
export class Dummy {}
`);

expect(result).toMatchSnapshot();
});

0 comments on commit 1ac43d1

Please sign in to comment.