-
-
Notifications
You must be signed in to change notification settings - Fork 153
/
checkPrefix.js
41 lines (35 loc) · 962 Bytes
/
checkPrefix.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import iterateJsdoc from '../iterateJsdoc';
const prefixMatch = /^(\s+)(?:\*( ?))?/u;
const validPrefix = /^\s+\*(?:\/?$| )/u;
export default iterateJsdoc(({
sourceCode,
jsdocNode,
report,
}) => {
const fix = (fixer) => {
const replacement = sourceCode.getText(jsdocNode).split('\n')
.map((line, index) => {
return index && !validPrefix.test(line) ? line.replace(prefixMatch, (_, $1, $2) => {
return `${$1}*${$2 || ' '}`;
}) : line;
})
.join('\n');
return fixer.replaceText(jsdocNode, replacement);
};
sourceCode.getText(jsdocNode).split('\n').some((line, index) => {
const lineNum = parseInt(index, 10);
if (lineNum && !validPrefix.test(line)) {
report('Expected JSDoc block to have the prefix.', fix, {
line: lineNum,
});
return true;
}
return false;
});
}, {
iterateAllJsdocs: true,
meta: {
fixable: 'code',
type: 'layout',
},
});