-
-
Notifications
You must be signed in to change notification settings - Fork 153
/
noRestrictedSyntax.js
97 lines (90 loc) · 2.32 KB
/
noRestrictedSyntax.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import esquery from 'esquery';
import iterateJsdoc from '../iterateJsdoc';
export default iterateJsdoc(({
node,
context,
info: {
comment,
},
sourceCode,
report,
}) => {
if (!context.options.length) {
report('Rule `no-restricted-syntax` is missing a `context` option.');
return;
}
const {
contexts,
} = context.options[0];
const foundContext = contexts.find((cntxt) => {
return typeof cntxt === 'string' ?
esquery.matches(node, esquery.parse(cntxt), null, {
visitorKeys: sourceCode.visitorKeys,
}) :
(!cntxt.context || cntxt.context === 'any' || esquery.matches(node, esquery.parse(cntxt.context), null, {
visitorKeys: sourceCode.visitorKeys,
})) &&
comment === cntxt.comment;
});
// We are not on the *particular* matching context/comment, so don't assume
// we need reporting
if (!foundContext) {
return;
}
const contextStr = typeof foundContext === 'object' ?
foundContext.context ?? 'any' :
foundContext;
const message = foundContext?.message ??
'Syntax is restricted: {{context}}' +
(comment ? ' with {{comment}}' : '');
report(message, null, null, {
comment,
context: contextStr,
});
}, {
contextSelected: true,
meta: {
docs: {
description: 'Reports when certain comment structures are present.',
url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-no-restricted-syntax',
},
fixable: 'code',
schema: [
{
additionalProperties: false,
properties: {
contexts: {
items: {
anyOf: [
{
type: 'string',
},
{
additionalProperties: false,
properties: {
comment: {
type: 'string',
},
context: {
type: 'string',
},
message: {
type: 'string',
},
},
type: 'object',
},
],
},
type: 'array',
},
},
required: [
'contexts',
],
type: 'object',
},
],
type: 'suggestion',
},
});