Skip to content

Commit

Permalink
Fix/files pattern bug (#185)
Browse files Browse the repository at this point in the history
* feat: replicate bug in a test

* fix: error when reading comments if there is a regexp inside
  • Loading branch information
kevinccbsg authored Sep 6, 2021
1 parent ffd228b commit 9dd2bce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion consumers/utils/getComments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const COMMENTS_PATTERN = /((\/\*+[\s\S]*?\*\/)|(\/\*+.*\*\/)|^\/\/.*?[\r\n])[\r\n]*/gm;
const COMMENTS_PATTERN = /((\/\*\*+[\s\S]*?\*\/)|(\/\*+.*\*\/)|^\/\/.*?[\r\n])[\r\n]*/gm;
const BREAK_LINE = /\n/g;

const getComments = text => {
Expand Down
20 changes: 20 additions & 0 deletions test/consumers/getOnlyComments/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ describe('get only comments consumer method', () => {
expect(result).toEqual(expected);
});

it('should return only the JSdoc comment when we add a regex in the file pattern', () => {
const input = [`
const pattern = './*.js';
/**
* @param {[type]}
* @param {[type]}
* @return {[type]}
*/
`];
const expected = [`/**
* @param {[type]}
* @param {[type]}
* @return {[type]}
*/`];
const result = getOnlyComments(input);
expect(result).toHaveLength(1);
expect(result).toEqual(expected);
});

it('should return multiline and JSdoc comment', () => {
const input = [`
/* this is a comment */
Expand Down

0 comments on commit 9dd2bce

Please sign in to comment.