/
noBadBlocks.js
72 lines (65 loc) · 1.67 KB
/
noBadBlocks.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import commentParser from 'comment-parser';
import iterateJsdoc from '../iterateJsdoc';
const commentRegexp = /^\/\*(?!\*)/;
export default iterateJsdoc(({
context,
sourceCode,
allComments,
makeReport,
}) => {
const [
{
ignore = [
'ts-check',
'ts-expect-error',
'ts-ignore',
'ts-nocheck',
],
} = {},
] = context.options;
const nonJsdocNodes = allComments.filter((comment) => {
const commentText = sourceCode.getText(comment);
if (!commentRegexp.test(commentText)) {
return false;
}
const [{tags = {}} = {}] = commentParser(`${commentText.slice(0, 2)}*${commentText.slice(2)}`);
return tags.length && !tags.some(({tag}) => {
return ignore.includes(tag);
});
});
if (!nonJsdocNodes.length) {
return;
}
nonJsdocNodes.forEach((node) => {
const report = makeReport(context, node);
const fix = (fixer) => {
const text = sourceCode.getText(node);
return fixer.replaceText(node, text.replace('/*', '/**'));
};
report('Expected JSDoc-like comment to begin with two asterisks.', fix);
});
}, {
checkFile: true,
meta: {
docs: {
description: 'This rule checks for multi-line-style comments which fail to meet the criteria of a jsdoc block.',
url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-no-bad-blocks',
},
fixable: 'code',
schema: [
{
additionalProperties: false,
properties: {
ignore: {
items: {
type: 'string',
},
type: 'array',
},
},
type: 'object',
},
],
type: 'layout',
},
});