UNPKG

1.32 kBJavaScriptView Raw
1var DEFAULT_TAGS = ['todo', 'fixme'];
2
3function getRegex(customTags) {
4 var tags = DEFAULT_TAGS;
5 if (customTags && customTags.length) {
6 tags = tags.concat(customTags);
7 }
8
9 return (
10 // Optional space.
11 '\\s*' +
12 // Optional `@`.
13 '@?' +
14 // One of the keywords such as `TODO` and `FIXME`.
15 '(' + tags.join('|') + ')' +
16 // Optional space.
17 '\\s*' +
18 // Optional leading reference in parens.
19 '(?:\\(([^)]*)\\))?' +
20 // Optional space.
21 '\\s*' +
22 // Optional colon `:`.
23 ':?' +
24 // Optional space.
25 '\\s*' +
26 // Comment text.
27 '(.*?)' +
28 // Optional trailing reference after a space and a slash, followed by an optional space.
29 '(?:\\s+/([^\\s]+)\\s*)?'
30 );
31}
32
33function prepareComment(match, line, file) {
34 // match = [<entire_match>, required <kind>, <reference>, <text>, <reference>]
35 if (!match || !match[1]) {
36 return null;
37 }
38 var ref = match[2] || match[4] || '';
39 var text = match[3] || '';
40 return {
41 file: file || 'unknown file',
42 kind: match[1].toUpperCase(),
43 line: line,
44 text: text.trim(),
45 ref: ref.trim()
46 };
47}
48
49exports.getRegex = getRegex;
50exports.prepareComment = prepareComment;