Skip to content

Commit 9dd2bce

Browse files
authored
Fix/files pattern bug (#185)
* feat: replicate bug in a test * fix: error when reading comments if there is a regexp inside
1 parent ffd228b commit 9dd2bce

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

consumers/utils/getComments.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const COMMENTS_PATTERN = /((\/\*+[\s\S]*?\*\/)|(\/\*+.*\*\/)|^\/\/.*?[\r\n])[\r\n]*/gm;
1+
const COMMENTS_PATTERN = /((\/\*\*+[\s\S]*?\*\/)|(\/\*+.*\*\/)|^\/\/.*?[\r\n])[\r\n]*/gm;
22
const BREAK_LINE = /\n/g;
33

44
const getComments = text => {

test/consumers/getOnlyComments/index.test.js

+20
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ describe('get only comments consumer method', () => {
7474
expect(result).toEqual(expected);
7575
});
7676

77+
it('should return only the JSdoc comment when we add a regex in the file pattern', () => {
78+
const input = [`
79+
const pattern = './*.js';
80+
/**
81+
* @param {[type]}
82+
* @param {[type]}
83+
* @return {[type]}
84+
*/
85+
86+
`];
87+
const expected = [`/**
88+
* @param {[type]}
89+
* @param {[type]}
90+
* @return {[type]}
91+
*/`];
92+
const result = getOnlyComments(input);
93+
expect(result).toHaveLength(1);
94+
expect(result).toEqual(expected);
95+
});
96+
7797
it('should return multiline and JSdoc comment', () => {
7898
const input = [`
7999
/* this is a comment */

0 commit comments

Comments
 (0)