Skip to content

Commit

Permalink
fix: remove empty comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinmd committed Jan 2, 2021
1 parent 87a27a6 commit 3b7473e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,13 @@ export const getParser = (parser: any) =>
);
});

comment.value = addStarsToTheBeginningOfTheLines(comment.value.trimEnd());
comment.value = comment.value.trimEnd();
if (comment.value) {
comment.value = addStarsToTheBeginningOfTheLines(comment.value);
}
});

ast.comments = ast.comments.filter(({ value }) => value);

return ast;
};
5 changes: 5 additions & 0 deletions tests/__snapshots__/main.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export class Dummy {}
"
`;

exports[`Incorrect comment 2`] = `
"export class Dummy {}
"
`;

exports[`JS code should be formatted as usuall 1`] = `
"const variable1 = 1; // No semicolon
const stringVar = \\"text\\"; // Wrong quotes
Expand Down
8 changes: 8 additions & 0 deletions tests/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,5 +369,13 @@ test("Incorrect comment", () => {
export class Dummy {}
`);

const result2 = subject(`
/**
*
*/
export class Dummy {}
`);

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

0 comments on commit 3b7473e

Please sign in to comment.