eslint-plugin-jsdoc 44.2.2 → 44.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alignTransform.js +86 -4
- package/dist/alignTransform.js.map +1 -1
- package/dist/exportParser.js +134 -4
- package/dist/exportParser.js.map +1 -1
- package/dist/getDefaultTagStructureForMode.js +71 -62
- package/dist/getDefaultTagStructureForMode.js.map +1 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/iterateJsdoc.js +1081 -111
- package/dist/iterateJsdoc.js.map +1 -1
- package/dist/jsdocUtils.js +381 -132
- package/dist/jsdocUtils.js.map +1 -1
- package/dist/rules/checkAlignment.js +6 -0
- package/dist/rules/checkAlignment.js.map +1 -1
- package/dist/rules/checkExamples.js +70 -6
- package/dist/rules/checkExamples.js.map +1 -1
- package/dist/rules/checkIndentation.js +11 -1
- package/dist/rules/checkIndentation.js.map +1 -1
- package/dist/rules/checkLineAlignment.js +69 -5
- package/dist/rules/checkLineAlignment.js.map +1 -1
- package/dist/rules/checkParamNames.js +12 -7
- package/dist/rules/checkParamNames.js.map +1 -1
- package/dist/rules/checkPropertyNames.js +13 -7
- package/dist/rules/checkPropertyNames.js.map +1 -1
- package/dist/rules/checkTagNames.js +45 -5
- package/dist/rules/checkTagNames.js.map +1 -1
- package/dist/rules/checkTypes.js +97 -36
- package/dist/rules/checkTypes.js.map +1 -1
- package/dist/rules/checkValues.js +6 -6
- package/dist/rules/checkValues.js.map +1 -1
- package/dist/rules/emptyTags.js +8 -1
- package/dist/rules/emptyTags.js.map +1 -1
- package/dist/rules/informativeDocs.js +26 -7
- package/dist/rules/informativeDocs.js.map +1 -1
- package/dist/rules/matchDescription.js +19 -2
- package/dist/rules/matchDescription.js.map +1 -1
- package/dist/rules/matchName.js +2 -2
- package/dist/rules/matchName.js.map +1 -1
- package/dist/rules/multilineBlocks.js +12 -1
- package/dist/rules/multilineBlocks.js.map +1 -1
- package/dist/rules/noBadBlocks.js +4 -6
- package/dist/rules/noBadBlocks.js.map +1 -1
- package/dist/rules/noBlankBlockDescriptions.js +2 -0
- package/dist/rules/noBlankBlockDescriptions.js.map +1 -1
- package/dist/rules/noMissingSyntax.js +58 -15
- package/dist/rules/noMissingSyntax.js.map +1 -1
- package/dist/rules/noMultiAsterisks.js +1 -6
- package/dist/rules/noMultiAsterisks.js.map +1 -1
- package/dist/rules/noRestrictedSyntax.js +17 -4
- package/dist/rules/noRestrictedSyntax.js.map +1 -1
- package/dist/rules/noTypes.js +3 -0
- package/dist/rules/noTypes.js.map +1 -1
- package/dist/rules/noUndefinedTypes.js +61 -20
- package/dist/rules/noUndefinedTypes.js.map +1 -1
- package/dist/rules/requireAsteriskPrefix.js +20 -0
- package/dist/rules/requireAsteriskPrefix.js.map +1 -1
- package/dist/rules/requireDescription.js +6 -2
- package/dist/rules/requireDescription.js.map +1 -1
- package/dist/rules/requireDescriptionCompleteSentence.js +73 -10
- package/dist/rules/requireDescriptionCompleteSentence.js.map +1 -1
- package/dist/rules/requireFileOverview.js +9 -4
- package/dist/rules/requireFileOverview.js.map +1 -1
- package/dist/rules/requireHyphenBeforeParamDescription.js +23 -6
- package/dist/rules/requireHyphenBeforeParamDescription.js.map +1 -1
- package/dist/rules/requireJsdoc.js +148 -30
- package/dist/rules/requireJsdoc.js.map +1 -1
- package/dist/rules/requireParam.js +46 -2
- package/dist/rules/requireParam.js.map +1 -1
- package/dist/rules/requireProperty.js +1 -1
- package/dist/rules/requireProperty.js.map +1 -1
- package/dist/rules/requireReturns.js +2 -2
- package/dist/rules/requireReturns.js.map +1 -1
- package/dist/rules/requireReturnsCheck.js +9 -2
- package/dist/rules/requireReturnsCheck.js.map +1 -1
- package/dist/rules/requireThrows.js +2 -2
- package/dist/rules/requireThrows.js.map +1 -1
- package/dist/rules/requireYields.js +9 -2
- package/dist/rules/requireYields.js.map +1 -1
- package/dist/rules/requireYieldsCheck.js +19 -5
- package/dist/rules/requireYieldsCheck.js.map +1 -1
- package/dist/rules/sortTags.js +67 -9
- package/dist/rules/sortTags.js.map +1 -1
- package/dist/rules/tagLines.js +22 -3
- package/dist/rules/tagLines.js.map +1 -1
- package/dist/rules/textEscaping.js +16 -2
- package/dist/rules/textEscaping.js.map +1 -1
- package/dist/rules/validTypes.js +25 -8
- package/dist/rules/validTypes.js.map +1 -1
- package/dist/tagNames.js +27 -0
- package/dist/tagNames.js.map +1 -1
- package/dist/utils/hasReturnValue.js +87 -42
- package/dist/utils/hasReturnValue.js.map +1 -1
- package/docs/rules/check-tag-names.md +15 -0
- package/docs/rules/no-missing-syntax.md +6 -0
- package/docs/rules/no-undefined-types.md +18 -0
- package/docs/rules/require-description-complete-sentence.md +525 -289
- package/docs/rules/require-description.md +289 -525
- package/docs/rules/require-file-overview.md +7 -0
- package/docs/rules/require-jsdoc.md +1 -1
- package/docs/rules/require-param-description.md +116 -1694
- package/docs/rules/require-param-name.md +58 -133
- package/docs/rules/require-param-type.md +119 -55
- package/docs/rules/require-param.md +1700 -111
- package/docs/rules/require-property-description.md +39 -79
- package/docs/rules/require-property-name.md +21 -30
- package/docs/rules/require-property-type.md +21 -21
- package/docs/rules/require-property.md +82 -33
- package/docs/rules/require-returns-check.md +636 -747
- package/docs/rules/require-returns-description.md +61 -933
- package/docs/rules/require-returns-type.md +42 -79
- package/docs/rules/require-returns.md +1081 -61
- package/docs/rules/require-yields-check.md +238 -517
- package/docs/rules/require-yields.md +517 -238
- package/docs/rules/valid-types.md +1 -1
- package/docs/settings.md +1 -1
- package/package.json +13 -5
- package/tsconfig.json +5 -2
package/dist/jsdocUtils.js
CHANGED
|
@@ -10,24 +10,90 @@ var _getDefaultTagStructureForMode = _interopRequireDefault(require("./getDefaul
|
|
|
10
10
|
var _tagNames = require("./tagNames");
|
|
11
11
|
var _hasReturnValue = require("./utils/hasReturnValue");
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
/* eslint-disable jsdoc/no-undefined-types */
|
|
14
|
-
|
|
15
13
|
/**
|
|
16
|
-
* @typedef {
|
|
14
|
+
* @typedef {number} Integer
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {import('./utils/hasReturnValue.js').ESTreeOrTypeScriptNode} ESTreeOrTypeScriptNode
|
|
17
18
|
*/
|
|
18
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {"jsdoc"|"typescript"|"closure"|"permissive"} ParserMode
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* @type {import('./getDefaultTagStructureForMode.js').TagStructure}
|
|
25
|
+
*/
|
|
19
26
|
let tagStructure;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {ParserMode} mode
|
|
30
|
+
* @returns {void}
|
|
31
|
+
*/
|
|
20
32
|
const setTagStructure = mode => {
|
|
21
33
|
tagStructure = (0, _getDefaultTagStructureForMode.default)(mode);
|
|
22
34
|
};
|
|
23
35
|
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
/**
|
|
37
|
+
* @typedef {{
|
|
38
|
+
* hasPropertyRest: boolean,
|
|
39
|
+
* hasRestElement: boolean,
|
|
40
|
+
* names: string[],
|
|
41
|
+
* rests: boolean[],
|
|
42
|
+
* }} FlattendRootInfo
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @typedef {undefined|string|{
|
|
47
|
+
* isRestProperty: boolean|undefined,
|
|
48
|
+
* name: string,
|
|
49
|
+
* restElement: true
|
|
50
|
+
* }|[undefined|string, FlattendRootInfo & {
|
|
51
|
+
* annotationParamName?: string
|
|
52
|
+
* }|{
|
|
53
|
+
* name: Integer,
|
|
54
|
+
* restElement: boolean
|
|
55
|
+
* }[]]} ParamNameInfo
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @typedef {undefined|string|{
|
|
60
|
+
* isRestProperty: boolean,
|
|
61
|
+
* restElement: boolean,
|
|
62
|
+
* name: string
|
|
63
|
+
* }|[string, {
|
|
64
|
+
* hasPropertyRest: boolean,
|
|
65
|
+
* hasRestElement: boolean,
|
|
66
|
+
* names: string[],
|
|
67
|
+
* rests: boolean[],
|
|
68
|
+
* }]|[string, string[]]} ParamInfo
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Given a nested array of property names, reduce them to a single array,
|
|
73
|
+
* appending the name of the root element along the way if present.
|
|
74
|
+
*
|
|
75
|
+
* @callback FlattenRoots
|
|
76
|
+
* @param {ParamInfo[]} params
|
|
77
|
+
* @param {string} [root]
|
|
78
|
+
* @returns {FlattendRootInfo}
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/** @type {FlattenRoots} */
|
|
26
82
|
const flattenRoots = (params, root = '') => {
|
|
27
83
|
let hasRestElement = false;
|
|
28
84
|
let hasPropertyRest = false;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @type {boolean[]}
|
|
88
|
+
*/
|
|
29
89
|
const rests = [];
|
|
30
|
-
const names = params.reduce(
|
|
90
|
+
const names = params.reduce(
|
|
91
|
+
/**
|
|
92
|
+
* @param {string[]} acc
|
|
93
|
+
* @param {ParamInfo} cur
|
|
94
|
+
* @returns {string[]}
|
|
95
|
+
*/
|
|
96
|
+
(acc, cur) => {
|
|
31
97
|
if (Array.isArray(cur)) {
|
|
32
98
|
let nms;
|
|
33
99
|
if (Array.isArray(cur[1])) {
|
|
@@ -78,46 +144,68 @@ const flattenRoots = (params, root = '') => {
|
|
|
78
144
|
};
|
|
79
145
|
|
|
80
146
|
/**
|
|
81
|
-
* @param {
|
|
82
|
-
*
|
|
147
|
+
* @param {import('@typescript-eslint/types').TSESTree.TSIndexSignature|
|
|
148
|
+
* import('@typescript-eslint/types').TSESTree.TSConstructSignatureDeclaration|
|
|
149
|
+
* import('@typescript-eslint/types').TSESTree.TSCallSignatureDeclaration|
|
|
150
|
+
* import('@typescript-eslint/types').TSESTree.TSPropertySignature} propSignature
|
|
151
|
+
* @returns {undefined|string|[string, string[]]}
|
|
83
152
|
*/
|
|
84
153
|
const getPropertiesFromPropertySignature = propSignature => {
|
|
85
154
|
if (propSignature.type === 'TSIndexSignature' || propSignature.type === 'TSConstructSignatureDeclaration' || propSignature.type === 'TSCallSignatureDeclaration') {
|
|
86
155
|
return undefined;
|
|
87
156
|
}
|
|
88
157
|
if (propSignature.typeAnnotation && propSignature.typeAnnotation.typeAnnotation.type === 'TSTypeLiteral') {
|
|
89
|
-
return [propSignature.key.name, propSignature.typeAnnotation.typeAnnotation.members.map(member => {
|
|
90
|
-
return
|
|
158
|
+
return [/** @type {import('@typescript-eslint/types').TSESTree.Identifier} */propSignature.key.name, propSignature.typeAnnotation.typeAnnotation.members.map(member => {
|
|
159
|
+
return (/** @type {string} */
|
|
160
|
+
getPropertiesFromPropertySignature( /** @type {import('@typescript-eslint/types').TSESTree.TSPropertySignature} */
|
|
161
|
+
member)
|
|
162
|
+
);
|
|
91
163
|
})];
|
|
92
164
|
}
|
|
93
|
-
return propSignature.key.name
|
|
165
|
+
return (/** @type {import('@typescript-eslint/types').TSESTree.Identifier} */propSignature.key.name
|
|
166
|
+
);
|
|
94
167
|
};
|
|
95
168
|
|
|
96
169
|
/**
|
|
97
|
-
* @param {
|
|
98
|
-
* @param {boolean} checkDefaultObjects
|
|
99
|
-
* @
|
|
170
|
+
* @param {ESTreeOrTypeScriptNode|null} functionNode
|
|
171
|
+
* @param {boolean} [checkDefaultObjects]
|
|
172
|
+
* @throws {Error}
|
|
173
|
+
* @returns {ParamNameInfo[]}
|
|
100
174
|
*/
|
|
101
175
|
const getFunctionParameterNames = (functionNode, checkDefaultObjects) => {
|
|
102
176
|
var _functionNode$value;
|
|
103
|
-
|
|
177
|
+
/* eslint-disable complexity -- Temporary */
|
|
178
|
+
/**
|
|
179
|
+
* @param {import('estree').Identifier|import('estree').AssignmentPattern|
|
|
180
|
+
* import('estree').ObjectPattern|import('estree').Property|
|
|
181
|
+
* import('estree').RestElement|import('estree').ArrayPattern|
|
|
182
|
+
* import('@typescript-eslint/types').TSESTree.TSParameterProperty|
|
|
183
|
+
* import('@typescript-eslint/types').TSESTree.Property|
|
|
184
|
+
* import('@typescript-eslint/types').TSESTree.RestElement
|
|
185
|
+
* } param
|
|
186
|
+
* @param {boolean} [isProperty]
|
|
187
|
+
* @returns {ParamNameInfo}
|
|
188
|
+
*/
|
|
104
189
|
const getParamName = (param, isProperty) => {
|
|
105
|
-
var _param$
|
|
190
|
+
var _param$left2;
|
|
191
|
+
/* eslint-enable complexity -- Temporary */
|
|
106
192
|
const hasLeftTypeAnnotation = 'left' in param && 'typeAnnotation' in param.left;
|
|
107
193
|
if ('typeAnnotation' in param || hasLeftTypeAnnotation) {
|
|
108
194
|
var _typeAnnotation$typeA;
|
|
109
|
-
const typeAnnotation = hasLeftTypeAnnotation ? param.left.typeAnnotation :
|
|
195
|
+
const typeAnnotation = hasLeftTypeAnnotation ? /** @type {import('@typescript-eslint/types').TSESTree.Identifier} */param.left.typeAnnotation : /** @type {import('@typescript-eslint/types').TSESTree.Identifier|import('@typescript-eslint/types').TSESTree.ObjectPattern} */
|
|
196
|
+
param.typeAnnotation;
|
|
110
197
|
if ((typeAnnotation === null || typeAnnotation === void 0 ? void 0 : (_typeAnnotation$typeA = typeAnnotation.typeAnnotation) === null || _typeAnnotation$typeA === void 0 ? void 0 : _typeAnnotation$typeA.type) === 'TSTypeLiteral') {
|
|
111
198
|
const propertyNames = typeAnnotation.typeAnnotation.members.map(member => {
|
|
112
|
-
return getPropertiesFromPropertySignature(
|
|
199
|
+
return getPropertiesFromPropertySignature( /** @type {import('@typescript-eslint/types').TSESTree.TSPropertySignature} */
|
|
200
|
+
member);
|
|
113
201
|
});
|
|
114
202
|
const flattened = {
|
|
115
203
|
...flattenRoots(propertyNames),
|
|
116
|
-
annotationParamName: param.name
|
|
204
|
+
annotationParamName: 'name' in param ? param.name : undefined
|
|
117
205
|
};
|
|
118
206
|
const hasLeftName = 'left' in param && 'name' in param.left;
|
|
119
207
|
if ('name' in param || hasLeftName) {
|
|
120
|
-
return [hasLeftName ? param.left.name : param.name, flattened];
|
|
208
|
+
return [hasLeftName ? /** @type {import('@typescript-eslint/types').TSESTree.Identifier} */param.left.name : /** @type {import('@typescript-eslint/types').TSESTree.Identifier} */param.name, flattened];
|
|
121
209
|
}
|
|
122
210
|
return [undefined, flattened];
|
|
123
211
|
}
|
|
@@ -128,9 +216,9 @@ const getFunctionParameterNames = (functionNode, checkDefaultObjects) => {
|
|
|
128
216
|
if ('left' in param && 'name' in param.left) {
|
|
129
217
|
return param.left.name;
|
|
130
218
|
}
|
|
131
|
-
if (param.type === 'ObjectPattern' ||
|
|
132
|
-
var _param$
|
|
133
|
-
const properties = param.properties || ((_param$
|
|
219
|
+
if (param.type === 'ObjectPattern' || 'left' in param && param.left.type === 'ObjectPattern') {
|
|
220
|
+
var _param$left;
|
|
221
|
+
const properties = /** @type {import('@typescript-eslint/types').TSESTree.ObjectPattern} */param.properties || ( /** @type {import('estree').ObjectPattern} */(_param$left = /** @type {import('@typescript-eslint/types').TSESTree.AssignmentPattern} */param.left) === null || _param$left === void 0 ? void 0 : _param$left.properties);
|
|
134
222
|
const roots = properties.map(prop => {
|
|
135
223
|
return getParamName(prop, true);
|
|
136
224
|
});
|
|
@@ -140,14 +228,14 @@ const getFunctionParameterNames = (functionNode, checkDefaultObjects) => {
|
|
|
140
228
|
// eslint-disable-next-line default-case
|
|
141
229
|
switch (param.value.type) {
|
|
142
230
|
case 'ArrayPattern':
|
|
143
|
-
return [param.key.name, param.value.elements.map((prop, idx) => {
|
|
231
|
+
return [param.key.name, /** @type {import('estree').ArrayPattern} */param.value.elements.map((prop, idx) => {
|
|
144
232
|
return {
|
|
145
233
|
name: idx,
|
|
146
|
-
restElement: prop.type === 'RestElement'
|
|
234
|
+
restElement: (prop === null || prop === void 0 ? void 0 : prop.type) === 'RestElement'
|
|
147
235
|
};
|
|
148
236
|
})];
|
|
149
237
|
case 'ObjectPattern':
|
|
150
|
-
return [param.key.name, param.value.properties.map(prop => {
|
|
238
|
+
return [param.key.name, /** @type {import('estree').ObjectPattern} */param.value.properties.map(prop => {
|
|
151
239
|
return getParamName(prop, isProperty);
|
|
152
240
|
})];
|
|
153
241
|
case 'AssignmentPattern':
|
|
@@ -157,20 +245,20 @@ const getFunctionParameterNames = (functionNode, checkDefaultObjects) => {
|
|
|
157
245
|
case 'Identifier':
|
|
158
246
|
// Default parameter
|
|
159
247
|
if (checkDefaultObjects && param.value.right.type === 'ObjectExpression') {
|
|
160
|
-
return [param.key.name, param.value.right.properties.map(prop => {
|
|
248
|
+
return [param.key.name, /** @type {import('estree').AssignmentPattern} */param.value.right.properties.map(prop => {
|
|
161
249
|
return getParamName(prop, isProperty);
|
|
162
250
|
})];
|
|
163
251
|
}
|
|
164
252
|
break;
|
|
165
253
|
case 'ObjectPattern':
|
|
166
|
-
return [param.key.name, param.value.left.properties.map(prop => {
|
|
254
|
+
return [param.key.name, /** @type {import('estree').ObjectPattern} */param.value.left.properties.map(prop => {
|
|
167
255
|
return getParamName(prop, isProperty);
|
|
168
256
|
})];
|
|
169
257
|
case 'ArrayPattern':
|
|
170
|
-
return [param.key.name, param.value.left.elements.map((prop, idx) => {
|
|
258
|
+
return [param.key.name, /** @type {import('estree').ArrayPattern} */param.value.left.elements.map((prop, idx) => {
|
|
171
259
|
return {
|
|
172
260
|
name: idx,
|
|
173
|
-
restElement: prop.type === 'RestElement'
|
|
261
|
+
restElement: (prop === null || prop === void 0 ? void 0 : prop.type) === 'RestElement'
|
|
174
262
|
};
|
|
175
263
|
})];
|
|
176
264
|
}
|
|
@@ -195,9 +283,9 @@ const getFunctionParameterNames = (functionNode, checkDefaultObjects) => {
|
|
|
195
283
|
return undefined;
|
|
196
284
|
}
|
|
197
285
|
}
|
|
198
|
-
if (param.type === 'ArrayPattern' || ((_param$
|
|
199
|
-
var _param$
|
|
200
|
-
const elements = param.elements || ((_param$
|
|
286
|
+
if (param.type === 'ArrayPattern' || ((_param$left2 = param.left) === null || _param$left2 === void 0 ? void 0 : _param$left2.type) === 'ArrayPattern') {
|
|
287
|
+
var _param$left3;
|
|
288
|
+
const elements = /** @type {import('estree').ArrayPattern} */param.elements || ( /** @type {import('estree').ArrayPattern} */(_param$left3 = param.left) === null || _param$left3 === void 0 ? void 0 : _param$left3.elements);
|
|
201
289
|
const roots = elements.map((prop, idx) => {
|
|
202
290
|
return {
|
|
203
291
|
name: `"${idx}"`,
|
|
@@ -227,7 +315,7 @@ const getFunctionParameterNames = (functionNode, checkDefaultObjects) => {
|
|
|
227
315
|
};
|
|
228
316
|
|
|
229
317
|
/**
|
|
230
|
-
* @param {
|
|
318
|
+
* @param {ESTreeOrTypeScriptNode} functionNode
|
|
231
319
|
* @returns {Integer}
|
|
232
320
|
*/
|
|
233
321
|
const hasParams = functionNode => {
|
|
@@ -239,9 +327,13 @@ const hasParams = functionNode => {
|
|
|
239
327
|
* Gets all names of the target type, including those that refer to a path, e.g.
|
|
240
328
|
* "@param foo; @param foo.bar".
|
|
241
329
|
*
|
|
242
|
-
* @param {
|
|
330
|
+
* @param {import('comment-parser').Block} jsdoc
|
|
243
331
|
* @param {string} targetTagName
|
|
244
|
-
* @returns {
|
|
332
|
+
* @returns {{
|
|
333
|
+
* idx: Integer,
|
|
334
|
+
* name: string,
|
|
335
|
+
* type: string
|
|
336
|
+
* }[]}
|
|
245
337
|
*/
|
|
246
338
|
const getJsdocTagsDeep = (jsdoc, targetTagName) => {
|
|
247
339
|
const ret = [];
|
|
@@ -264,8 +356,9 @@ const getJsdocTagsDeep = (jsdoc, targetTagName) => {
|
|
|
264
356
|
const modeWarnSettings = (0, _WarnSettings.default)();
|
|
265
357
|
|
|
266
358
|
/**
|
|
267
|
-
* @param {
|
|
268
|
-
* @param context
|
|
359
|
+
* @param {ParserMode|undefined} mode
|
|
360
|
+
* @param {import('eslint').Rule.RuleContext} context
|
|
361
|
+
* @returns {import('./tagNames.js').AliasedTags}
|
|
269
362
|
*/
|
|
270
363
|
const getTagNamesForMode = (mode, context) => {
|
|
271
364
|
switch (mode) {
|
|
@@ -296,11 +389,14 @@ const getTagNamesForMode = (mode, context) => {
|
|
|
296
389
|
};
|
|
297
390
|
|
|
298
391
|
/**
|
|
299
|
-
* @param context
|
|
300
|
-
* @param {ParserMode} mode
|
|
392
|
+
* @param {import('eslint').Rule.RuleContext} context
|
|
393
|
+
* @param {ParserMode|undefined} mode
|
|
301
394
|
* @param {string} name
|
|
302
|
-
* @param {
|
|
303
|
-
* @returns {string|
|
|
395
|
+
* @param {TagNamePreference} tagPreference
|
|
396
|
+
* @returns {string|false|{
|
|
397
|
+
* message: string;
|
|
398
|
+
* replacement?: string|undefined;
|
|
399
|
+
* }}
|
|
304
400
|
*/
|
|
305
401
|
const getPreferredTagName = (context, mode, name, tagPreference = {}) => {
|
|
306
402
|
var _Object$entries$find;
|
|
@@ -319,7 +415,7 @@ const getPreferredTagName = (context, mode, name, tagPreference = {}) => {
|
|
|
319
415
|
const tagPreferenceFixed = Object.fromEntries(Object.entries(tagPreference).map(([key, value]) => {
|
|
320
416
|
return [key.replace(/^tag /u, ''), value];
|
|
321
417
|
}));
|
|
322
|
-
if (Object.
|
|
418
|
+
if (Object.hasOwn(tagPreferenceFixed, name)) {
|
|
323
419
|
return tagPreferenceFixed[name];
|
|
324
420
|
}
|
|
325
421
|
const tagNames = getTagNamesForMode(mode, context);
|
|
@@ -333,10 +429,10 @@ const getPreferredTagName = (context, mode, name, tagPreference = {}) => {
|
|
|
333
429
|
};
|
|
334
430
|
|
|
335
431
|
/**
|
|
336
|
-
* @param context
|
|
337
|
-
* @param {ParserMode} mode
|
|
432
|
+
* @param {import('eslint').Rule.RuleContext} context
|
|
433
|
+
* @param {ParserMode|undefined} mode
|
|
338
434
|
* @param {string} name
|
|
339
|
-
* @param {
|
|
435
|
+
* @param {string[]} definedTags
|
|
340
436
|
* @returns {boolean}
|
|
341
437
|
*/
|
|
342
438
|
const isValidTag = (context, mode, name, definedTags) => {
|
|
@@ -348,7 +444,9 @@ const isValidTag = (context, mode, name, definedTags) => {
|
|
|
348
444
|
};
|
|
349
445
|
|
|
350
446
|
/**
|
|
351
|
-
* @param {
|
|
447
|
+
* @param {import('comment-parser').Block & {
|
|
448
|
+
* inlineTags: import('@es-joy/jsdoccomment').InlineTag[]
|
|
449
|
+
* }} jsdoc
|
|
352
450
|
* @param {string} targetTagName
|
|
353
451
|
* @returns {boolean}
|
|
354
452
|
*/
|
|
@@ -362,18 +460,69 @@ const hasTag = (jsdoc, targetTagName) => {
|
|
|
362
460
|
/**
|
|
363
461
|
* Get all tags, inline tags and inline tags in tags
|
|
364
462
|
*
|
|
365
|
-
* @param {
|
|
366
|
-
* @
|
|
463
|
+
* @param {import('comment-parser').Block & {
|
|
464
|
+
* inlineTags: import('@es-joy/jsdoccomment').JsdocInlineTagNoType[]
|
|
465
|
+
* }} jsdoc
|
|
466
|
+
* @returns {(import('comment-parser').Spec|
|
|
467
|
+
* import('@es-joy/jsdoccomment').JsdocInlineTagNoType)[]}
|
|
367
468
|
*/
|
|
368
|
-
const getAllTags =
|
|
369
|
-
return
|
|
370
|
-
|
|
371
|
-
|
|
469
|
+
const getAllTags = jsdoc => {
|
|
470
|
+
return [...jsdoc.tags, ...jsdoc.inlineTags.map(inlineTag => {
|
|
471
|
+
// Tags don't have source or line numbers, so add before returning
|
|
472
|
+
let line = -1;
|
|
473
|
+
for (const {
|
|
474
|
+
tokens: {
|
|
475
|
+
description
|
|
476
|
+
}
|
|
477
|
+
} of jsdoc.source) {
|
|
478
|
+
line++;
|
|
479
|
+
if (description && description.includes(`{@${inlineTag.tag}`)) {
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
inlineTag.line = line;
|
|
484
|
+
return inlineTag;
|
|
485
|
+
}), ...jsdoc.tags.flatMap(tag => {
|
|
486
|
+
let tagBegins = -1;
|
|
487
|
+
for (const {
|
|
488
|
+
tokens: {
|
|
489
|
+
tag: tg
|
|
490
|
+
}
|
|
491
|
+
} of jsdoc.source) {
|
|
492
|
+
tagBegins++;
|
|
493
|
+
if (tg) {
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
for (const inlineTag of tag.inlineTags) {
|
|
498
|
+
let line;
|
|
499
|
+
for (const {
|
|
500
|
+
number,
|
|
501
|
+
tokens: {
|
|
502
|
+
description
|
|
503
|
+
}
|
|
504
|
+
} of tag.source) {
|
|
505
|
+
if (description && description.includes(`{@${inlineTag.tag}`)) {
|
|
506
|
+
line = number;
|
|
507
|
+
break;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
inlineTag.line = tagBegins + line - 1;
|
|
511
|
+
}
|
|
512
|
+
return (
|
|
513
|
+
/**
|
|
514
|
+
* @type {import('comment-parser').Spec & {
|
|
515
|
+
* inlineTags: import('@es-joy/jsdoccomment').JsdocInlineTagNoType[]
|
|
516
|
+
* }}
|
|
517
|
+
*/
|
|
518
|
+
tag.inlineTags
|
|
519
|
+
);
|
|
520
|
+
})];
|
|
372
521
|
};
|
|
373
522
|
|
|
374
523
|
/**
|
|
375
|
-
* @param {
|
|
376
|
-
* @param {
|
|
524
|
+
* @param {import('comment-parser').Block} jsdoc
|
|
525
|
+
* @param {string[]} targetTagNames
|
|
377
526
|
* @returns {boolean}
|
|
378
527
|
*/
|
|
379
528
|
const hasATag = (jsdoc, targetTagNames) => {
|
|
@@ -385,9 +534,9 @@ const hasATag = (jsdoc, targetTagNames) => {
|
|
|
385
534
|
/**
|
|
386
535
|
* Checks if the JSDoc comment has an undefined type.
|
|
387
536
|
*
|
|
388
|
-
* @param {
|
|
537
|
+
* @param {import('comment-parser').Spec|null|undefined} tag
|
|
389
538
|
* the tag which should be checked.
|
|
390
|
-
* @param {
|
|
539
|
+
* @param {ParserMode} mode
|
|
391
540
|
* @returns {boolean}
|
|
392
541
|
* true in case a defined type is undeclared; otherwise false.
|
|
393
542
|
*/
|
|
@@ -423,20 +572,22 @@ const mayBeUndefinedTypeTag = (tag, mode) => {
|
|
|
423
572
|
};
|
|
424
573
|
|
|
425
574
|
/**
|
|
426
|
-
* @param map
|
|
427
|
-
* @param tag
|
|
428
|
-
* @returns {Map}
|
|
575
|
+
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} map
|
|
576
|
+
* @param {string} tag
|
|
577
|
+
* @returns {Map<string, string|string[]|boolean|undefined>}
|
|
429
578
|
*/
|
|
430
579
|
const ensureMap = (map, tag) => {
|
|
431
580
|
if (!map.has(tag)) {
|
|
432
581
|
map.set(tag, new Map());
|
|
433
582
|
}
|
|
434
|
-
return map.get(tag)
|
|
583
|
+
return (/** @type {Map<string, string | boolean>} */map.get(tag)
|
|
584
|
+
);
|
|
435
585
|
};
|
|
436
586
|
|
|
437
587
|
/**
|
|
438
|
-
* @param structuredTags
|
|
439
|
-
* @param tagMap
|
|
588
|
+
* @param {import('./iterateJsdoc.js').StructuredTags} structuredTags
|
|
589
|
+
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
590
|
+
* @returns {void}
|
|
440
591
|
*/
|
|
441
592
|
const overrideTagStructure = (structuredTags, tagMap = tagStructure) => {
|
|
442
593
|
for (const [tag, {
|
|
@@ -469,9 +620,9 @@ const overrideTagStructure = (structuredTags, tagMap = tagStructure) => {
|
|
|
469
620
|
};
|
|
470
621
|
|
|
471
622
|
/**
|
|
472
|
-
* @param mode
|
|
473
|
-
* @param structuredTags
|
|
474
|
-
* @returns {
|
|
623
|
+
* @param {ParserMode} mode
|
|
624
|
+
* @param {import('./iterateJsdoc.js').StructuredTags} structuredTags
|
|
625
|
+
* @returns {import('./getDefaultTagStructureForMode.js').TagStructure}
|
|
475
626
|
*/
|
|
476
627
|
const getTagStructureForMode = (mode, structuredTags) => {
|
|
477
628
|
const tagStruct = (0, _getDefaultTagStructureForMode.default)(mode);
|
|
@@ -484,8 +635,8 @@ const getTagStructureForMode = (mode, structuredTags) => {
|
|
|
484
635
|
};
|
|
485
636
|
|
|
486
637
|
/**
|
|
487
|
-
* @param tag
|
|
488
|
-
* @param {
|
|
638
|
+
* @param {string} tag
|
|
639
|
+
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
489
640
|
* @returns {boolean}
|
|
490
641
|
*/
|
|
491
642
|
const isNamepathDefiningTag = (tag, tagMap = tagStructure) => {
|
|
@@ -494,8 +645,8 @@ const isNamepathDefiningTag = (tag, tagMap = tagStructure) => {
|
|
|
494
645
|
};
|
|
495
646
|
|
|
496
647
|
/**
|
|
497
|
-
* @param tag
|
|
498
|
-
* @param {
|
|
648
|
+
* @param {string} tag
|
|
649
|
+
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
499
650
|
* @returns {boolean}
|
|
500
651
|
*/
|
|
501
652
|
const isNamepathReferencingTag = (tag, tagMap = tagStructure) => {
|
|
@@ -504,8 +655,8 @@ const isNamepathReferencingTag = (tag, tagMap = tagStructure) => {
|
|
|
504
655
|
};
|
|
505
656
|
|
|
506
657
|
/**
|
|
507
|
-
* @param tag
|
|
508
|
-
* @param {
|
|
658
|
+
* @param {string} tag
|
|
659
|
+
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
509
660
|
* @returns {boolean}
|
|
510
661
|
*/
|
|
511
662
|
const isNamepathOrUrlReferencingTag = (tag, tagMap = tagStructure) => {
|
|
@@ -514,19 +665,20 @@ const isNamepathOrUrlReferencingTag = (tag, tagMap = tagStructure) => {
|
|
|
514
665
|
};
|
|
515
666
|
|
|
516
667
|
/**
|
|
517
|
-
* @param tag
|
|
518
|
-
* @param {
|
|
519
|
-
* @returns {boolean}
|
|
668
|
+
* @param {string} tag
|
|
669
|
+
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
670
|
+
* @returns {boolean|undefined}
|
|
520
671
|
*/
|
|
521
672
|
const tagMustHaveTypePosition = (tag, tagMap = tagStructure) => {
|
|
522
673
|
const tagStruct = ensureMap(tagMap, tag);
|
|
523
|
-
return tagStruct.get('typeRequired')
|
|
674
|
+
return (/** @type {boolean|undefined} */tagStruct.get('typeRequired')
|
|
675
|
+
);
|
|
524
676
|
};
|
|
525
677
|
|
|
526
678
|
/**
|
|
527
|
-
* @param tag
|
|
528
|
-
* @param {
|
|
529
|
-
* @returns {boolean}
|
|
679
|
+
* @param {string} tag
|
|
680
|
+
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
681
|
+
* @returns {boolean|string}
|
|
530
682
|
*/
|
|
531
683
|
const tagMightHaveTypePosition = (tag, tagMap = tagStructure) => {
|
|
532
684
|
if (tagMustHaveTypePosition(tag, tagMap)) {
|
|
@@ -539,8 +691,8 @@ const tagMightHaveTypePosition = (tag, tagMap = tagStructure) => {
|
|
|
539
691
|
const namepathTypes = new Set(['namepath-defining', 'namepath-referencing']);
|
|
540
692
|
|
|
541
693
|
/**
|
|
542
|
-
* @param tag
|
|
543
|
-
* @param {
|
|
694
|
+
* @param {string} tag
|
|
695
|
+
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
544
696
|
* @returns {boolean}
|
|
545
697
|
*/
|
|
546
698
|
const tagMightHaveNamePosition = (tag, tagMap = tagStructure) => {
|
|
@@ -550,8 +702,8 @@ const tagMightHaveNamePosition = (tag, tagMap = tagStructure) => {
|
|
|
550
702
|
};
|
|
551
703
|
|
|
552
704
|
/**
|
|
553
|
-
* @param tag
|
|
554
|
-
* @param {
|
|
705
|
+
* @param {string} tag
|
|
706
|
+
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
555
707
|
* @returns {boolean}
|
|
556
708
|
*/
|
|
557
709
|
const tagMightHaveNamepath = (tag, tagMap = tagStructure) => {
|
|
@@ -560,38 +712,40 @@ const tagMightHaveNamepath = (tag, tagMap = tagStructure) => {
|
|
|
560
712
|
};
|
|
561
713
|
|
|
562
714
|
/**
|
|
563
|
-
* @param tag
|
|
564
|
-
* @param {
|
|
565
|
-
* @returns {boolean}
|
|
715
|
+
* @param {string} tag
|
|
716
|
+
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
717
|
+
* @returns {boolean|undefined}
|
|
566
718
|
*/
|
|
567
719
|
const tagMustHaveNamePosition = (tag, tagMap = tagStructure) => {
|
|
568
720
|
const tagStruct = ensureMap(tagMap, tag);
|
|
569
|
-
return tagStruct.get('nameRequired')
|
|
721
|
+
return (/** @type {boolean|undefined} */tagStruct.get('nameRequired')
|
|
722
|
+
);
|
|
570
723
|
};
|
|
571
724
|
|
|
572
725
|
/**
|
|
573
|
-
* @param tag
|
|
574
|
-
* @param {
|
|
726
|
+
* @param {string} tag
|
|
727
|
+
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
575
728
|
* @returns {boolean}
|
|
576
729
|
*/
|
|
577
730
|
const tagMightHaveEitherTypeOrNamePosition = (tag, tagMap) => {
|
|
578
|
-
return tagMightHaveTypePosition(tag, tagMap) || tagMightHaveNamepath(tag, tagMap);
|
|
731
|
+
return Boolean(tagMightHaveTypePosition(tag, tagMap)) || tagMightHaveNamepath(tag, tagMap);
|
|
579
732
|
};
|
|
580
733
|
|
|
581
734
|
/**
|
|
582
|
-
* @param tag
|
|
583
|
-
* @param {
|
|
584
|
-
* @returns {boolean}
|
|
735
|
+
* @param {string} tag
|
|
736
|
+
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
737
|
+
* @returns {boolean|undefined}
|
|
585
738
|
*/
|
|
586
739
|
const tagMustHaveEitherTypeOrNamePosition = (tag, tagMap) => {
|
|
587
740
|
const tagStruct = ensureMap(tagMap, tag);
|
|
588
|
-
return tagStruct.get('typeOrNameRequired')
|
|
741
|
+
return (/** @type {boolean} */tagStruct.get('typeOrNameRequired')
|
|
742
|
+
);
|
|
589
743
|
};
|
|
590
744
|
|
|
591
745
|
/**
|
|
592
|
-
* @param tag
|
|
593
|
-
* @param {
|
|
594
|
-
* @returns {boolean}
|
|
746
|
+
* @param {import('comment-parser').Spec} tag
|
|
747
|
+
* @param {import('./getDefaultTagStructureForMode.js').TagStructure} tagMap
|
|
748
|
+
* @returns {boolean|undefined}
|
|
595
749
|
*/
|
|
596
750
|
const tagMissingRequiredTypeOrNamepath = (tag, tagMap = tagStructure) => {
|
|
597
751
|
const mustHaveTypePosition = tagMustHaveTypePosition(tag.tag, tagMap);
|
|
@@ -603,8 +757,14 @@ const tagMissingRequiredTypeOrNamepath = (tag, tagMap = tagStructure) => {
|
|
|
603
757
|
return mustHaveEither && !hasEither && !mustHaveTypePosition;
|
|
604
758
|
};
|
|
605
759
|
|
|
606
|
-
|
|
760
|
+
/* eslint-disable complexity -- Temporary */
|
|
761
|
+
/**
|
|
762
|
+
* @param {ESTreeOrTypeScriptNode} node
|
|
763
|
+
* @param {boolean} [checkYieldReturnValue]
|
|
764
|
+
* @returns {boolean}
|
|
765
|
+
*/
|
|
607
766
|
const hasNonFunctionYield = (node, checkYieldReturnValue) => {
|
|
767
|
+
/* eslint-enable complexity -- Temporary */
|
|
608
768
|
if (!node) {
|
|
609
769
|
return false;
|
|
610
770
|
}
|
|
@@ -616,6 +776,7 @@ const hasNonFunctionYield = (node, checkYieldReturnValue) => {
|
|
|
616
776
|
});
|
|
617
777
|
}
|
|
618
778
|
|
|
779
|
+
// @ts-expect-error In Babel?
|
|
619
780
|
// istanbul ignore next -- In Babel?
|
|
620
781
|
case 'OptionalCallExpression':
|
|
621
782
|
case 'CallExpression':
|
|
@@ -693,13 +854,16 @@ const hasNonFunctionYield = (node, checkYieldReturnValue) => {
|
|
|
693
854
|
// istanbul ignore next -- In Babel?
|
|
694
855
|
case 'PropertyDefinition':
|
|
695
856
|
/* eslint-disable no-fallthrough */
|
|
857
|
+
// @ts-expect-error In Babel?
|
|
696
858
|
// istanbul ignore next -- In Babel?
|
|
697
859
|
case 'ObjectProperty':
|
|
860
|
+
// @ts-expect-error In Babel?
|
|
698
861
|
// istanbul ignore next -- In Babel?
|
|
699
862
|
case 'ClassProperty':
|
|
700
863
|
case 'Property':
|
|
701
864
|
/* eslint-enable no-fallthrough */
|
|
702
865
|
return node.computed && hasNonFunctionYield(node.key, checkYieldReturnValue) || hasNonFunctionYield(node.value, checkYieldReturnValue);
|
|
866
|
+
// @ts-expect-error In Babel?
|
|
703
867
|
// istanbul ignore next -- In Babel?
|
|
704
868
|
case 'ObjectMethod':
|
|
705
869
|
// istanbul ignore next -- In Babel?
|
|
@@ -712,12 +876,14 @@ const hasNonFunctionYield = (node, checkYieldReturnValue) => {
|
|
|
712
876
|
case 'TaggedTemplateExpression':
|
|
713
877
|
return hasNonFunctionYield(node.quasi, checkYieldReturnValue);
|
|
714
878
|
|
|
879
|
+
// @ts-expect-error In Babel?
|
|
715
880
|
// ?.
|
|
716
881
|
// istanbul ignore next -- In Babel?
|
|
717
882
|
case 'OptionalMemberExpression':
|
|
718
883
|
case 'MemberExpression':
|
|
719
884
|
return hasNonFunctionYield(node.object, checkYieldReturnValue) || hasNonFunctionYield(node.property, checkYieldReturnValue);
|
|
720
885
|
|
|
886
|
+
// @ts-expect-error In Babel?
|
|
721
887
|
// istanbul ignore next -- In Babel?
|
|
722
888
|
case 'Import':
|
|
723
889
|
case 'ImportExpression':
|
|
@@ -754,7 +920,8 @@ const hasNonFunctionYield = (node, checkYieldReturnValue) => {
|
|
|
754
920
|
/**
|
|
755
921
|
* Checks if a node has a return statement. Void return does not count.
|
|
756
922
|
*
|
|
757
|
-
* @param {
|
|
923
|
+
* @param {ESTreeOrTypeScriptNode} node
|
|
924
|
+
* @param {boolean} [checkYieldReturnValue]
|
|
758
925
|
* @returns {boolean}
|
|
759
926
|
*/
|
|
760
927
|
const hasYieldValue = (node, checkYieldReturnValue) => {
|
|
@@ -764,8 +931,8 @@ const hasYieldValue = (node, checkYieldReturnValue) => {
|
|
|
764
931
|
/**
|
|
765
932
|
* Checks if a node has a throws statement.
|
|
766
933
|
*
|
|
767
|
-
* @param {
|
|
768
|
-
* @param {boolean} innerFunction
|
|
934
|
+
* @param {ESTreeOrTypeScriptNode|null|undefined} node
|
|
935
|
+
* @param {boolean} [innerFunction]
|
|
769
936
|
* @returns {boolean}
|
|
770
937
|
*/
|
|
771
938
|
// eslint-disable-next-line complexity
|
|
@@ -843,8 +1010,8 @@ const isInlineTag = (tag) => {
|
|
|
843
1010
|
*
|
|
844
1011
|
* @see {https://github.com/google/closure-compiler/wiki/Generic-Types}
|
|
845
1012
|
* @see {https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#template}
|
|
846
|
-
* @param {
|
|
847
|
-
* @returns {
|
|
1013
|
+
* @param {import('comment-parser').Spec} tag
|
|
1014
|
+
* @returns {string[]}
|
|
848
1015
|
*/
|
|
849
1016
|
const parseClosureTemplateTag = tag => {
|
|
850
1017
|
return tag.name.split(',').map(type => {
|
|
@@ -861,9 +1028,11 @@ const parseClosureTemplateTag = tag => {
|
|
|
861
1028
|
* contexts designated by the rule. Returns an array of
|
|
862
1029
|
* ESTree AST types, indicating allowable contexts.
|
|
863
1030
|
*
|
|
864
|
-
* @param {
|
|
865
|
-
* @param {DefaultContexts} defaultContexts
|
|
866
|
-
* @param
|
|
1031
|
+
* @param {import('eslint').Rule.RuleContext} context
|
|
1032
|
+
* @param {DefaultContexts|undefined} defaultContexts
|
|
1033
|
+
* @param {{
|
|
1034
|
+
* contexts?: import('./iterateJsdoc.js').Context[]
|
|
1035
|
+
* }} settings
|
|
867
1036
|
* @returns {string[]}
|
|
868
1037
|
*/
|
|
869
1038
|
const enforcedContexts = (context, defaultContexts, settings) => {
|
|
@@ -873,11 +1042,13 @@ const enforcedContexts = (context, defaultContexts, settings) => {
|
|
|
873
1042
|
};
|
|
874
1043
|
|
|
875
1044
|
/**
|
|
876
|
-
* @param {
|
|
877
|
-
* @param {
|
|
878
|
-
* @param {Function} handler
|
|
1045
|
+
* @param {import('./iterateJsdoc.js').Context[]} contexts
|
|
1046
|
+
* @param {import('./iterateJsdoc.js').CheckJsdoc} checkJsdoc
|
|
1047
|
+
* @param {Function} [handler]
|
|
1048
|
+
* @returns {import('eslint').Rule.RuleListener}
|
|
879
1049
|
*/
|
|
880
1050
|
const getContextObject = (contexts, checkJsdoc, handler) => {
|
|
1051
|
+
/** @type {import('eslint').Rule.RuleListener} */
|
|
881
1052
|
const properties = {};
|
|
882
1053
|
for (const [idx, prop] of contexts.entries()) {
|
|
883
1054
|
let property;
|
|
@@ -913,18 +1084,36 @@ const getContextObject = (contexts, checkJsdoc, handler) => {
|
|
|
913
1084
|
}
|
|
914
1085
|
return properties;
|
|
915
1086
|
};
|
|
916
|
-
const filterTags = (tags, filter) => {
|
|
917
|
-
return tags.filter(tag => {
|
|
918
|
-
return filter(tag);
|
|
919
|
-
});
|
|
920
|
-
};
|
|
921
1087
|
const tagsWithNamesAndDescriptions = new Set(['param', 'arg', 'argument', 'property', 'prop', 'template',
|
|
922
1088
|
// These two are parsed by our custom parser as though having a `name`
|
|
923
1089
|
'returns', 'return']);
|
|
1090
|
+
|
|
1091
|
+
/* eslint-disable jsdoc/valid-types -- Old version */
|
|
1092
|
+
/**
|
|
1093
|
+
* @typedef {{
|
|
1094
|
+
* [key: string]: false|
|
|
1095
|
+
* {message: string, replacement?: string}
|
|
1096
|
+
* }} TagNamePreference
|
|
1097
|
+
*/
|
|
1098
|
+
/* eslint-enable jsdoc/valid-types -- Old version */
|
|
1099
|
+
|
|
1100
|
+
/**
|
|
1101
|
+
* @param {import('eslint').Rule.RuleContext} context
|
|
1102
|
+
* @param {ParserMode|undefined} mode
|
|
1103
|
+
* @param {import('comment-parser').Spec[]} tags
|
|
1104
|
+
* @param {TagNamePreference} tagPreference
|
|
1105
|
+
* @returns {{
|
|
1106
|
+
* tagsWithNames: import('comment-parser').Spec[],
|
|
1107
|
+
* tagsWithoutNames: import('comment-parser').Spec[]
|
|
1108
|
+
* }}
|
|
1109
|
+
*/
|
|
924
1110
|
const getTagsByType = (context, mode, tags, tagPreference) => {
|
|
925
1111
|
const descName = getPreferredTagName(context, mode, 'description', tagPreference);
|
|
1112
|
+
/**
|
|
1113
|
+
* @type {import('comment-parser').Spec[]}
|
|
1114
|
+
*/
|
|
926
1115
|
const tagsWithoutNames = [];
|
|
927
|
-
const tagsWithNames =
|
|
1116
|
+
const tagsWithNames = tags.filter(tag => {
|
|
928
1117
|
const {
|
|
929
1118
|
tag: tagName
|
|
930
1119
|
} = tag;
|
|
@@ -939,42 +1128,100 @@ const getTagsByType = (context, mode, tags, tagPreference) => {
|
|
|
939
1128
|
tagsWithoutNames
|
|
940
1129
|
};
|
|
941
1130
|
};
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* @param {import('eslint').SourceCode|{
|
|
1134
|
+
* text: string
|
|
1135
|
+
* }} sourceCode
|
|
1136
|
+
* @returns {string}
|
|
1137
|
+
*/
|
|
942
1138
|
const getIndent = sourceCode => {
|
|
943
1139
|
var _sourceCode$text$matc;
|
|
944
1140
|
return (((_sourceCode$text$matc = sourceCode.text.match(/^\n*([ \t]+)/u)) === null || _sourceCode$text$matc === void 0 ? void 0 : _sourceCode$text$matc[1]) ?? '') + ' ';
|
|
945
1141
|
};
|
|
1142
|
+
|
|
1143
|
+
/**
|
|
1144
|
+
* @param {import('eslint').Rule.Node|null} node
|
|
1145
|
+
* @returns {boolean}
|
|
1146
|
+
*/
|
|
946
1147
|
const isConstructor = node => {
|
|
947
1148
|
var _node$parent;
|
|
948
|
-
return (node === null || node === void 0 ? void 0 : node.type) === 'MethodDefinition' && node.kind === 'constructor' || (node === null || node === void 0 ? void 0 : (_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.kind) === 'constructor';
|
|
1149
|
+
return (node === null || node === void 0 ? void 0 : node.type) === 'MethodDefinition' && node.kind === 'constructor' || /** @type {import('@typescript-eslint/types').TSESTree.MethodDefinition} */(node === null || node === void 0 ? void 0 : (_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.kind) === 'constructor';
|
|
949
1150
|
};
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* @param {import('eslint').Rule.Node|null} node
|
|
1154
|
+
* @returns {boolean}
|
|
1155
|
+
*/
|
|
950
1156
|
const isGetter = node => {
|
|
951
1157
|
var _node$parent2;
|
|
952
|
-
return node
|
|
1158
|
+
return node !== null &&
|
|
1159
|
+
/**
|
|
1160
|
+
* @type {import('@typescript-eslint/types').TSESTree.MethodDefinition|
|
|
1161
|
+
* import('@typescript-eslint/types').TSESTree.Property}
|
|
1162
|
+
*/
|
|
1163
|
+
((_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.kind) === 'get';
|
|
953
1164
|
};
|
|
1165
|
+
|
|
1166
|
+
/**
|
|
1167
|
+
* @param {import('eslint').Rule.Node|null} node
|
|
1168
|
+
* @returns {boolean}
|
|
1169
|
+
*/
|
|
954
1170
|
const isSetter = node => {
|
|
955
1171
|
var _node$parent3;
|
|
956
|
-
return node
|
|
1172
|
+
return node !== null &&
|
|
1173
|
+
/**
|
|
1174
|
+
* @type {import('@typescript-eslint/types').TSESTree.MethodDefinition|
|
|
1175
|
+
* import('@typescript-eslint/types').TSESTree.Property}
|
|
1176
|
+
*/
|
|
1177
|
+
((_node$parent3 = node.parent) === null || _node$parent3 === void 0 ? void 0 : _node$parent3.kind) === 'set';
|
|
957
1178
|
};
|
|
1179
|
+
|
|
1180
|
+
/**
|
|
1181
|
+
* @param {import('eslint').Rule.Node} node
|
|
1182
|
+
* @returns {boolean}
|
|
1183
|
+
*/
|
|
958
1184
|
const hasAccessorPair = node => {
|
|
959
1185
|
const {
|
|
960
1186
|
type,
|
|
961
1187
|
kind: sourceKind,
|
|
962
|
-
key
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1188
|
+
key
|
|
1189
|
+
} =
|
|
1190
|
+
/**
|
|
1191
|
+
* @type {import('@typescript-eslint/types').TSESTree.MethodDefinition|
|
|
1192
|
+
* import('@typescript-eslint/types').TSESTree.Property}
|
|
1193
|
+
*/
|
|
1194
|
+
node;
|
|
1195
|
+
const sourceName = /** @type {import('@typescript-eslint/types').TSESTree.Identifier} */key.name;
|
|
966
1196
|
const oppositeKind = sourceKind === 'get' ? 'set' : 'get';
|
|
967
|
-
const
|
|
968
|
-
return
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
}
|
|
973
|
-
|
|
1197
|
+
const sibling = type === 'MethodDefinition' ? /** @type {import('@typescript-eslint/types').TSESTree.ClassBody} */node.parent.body : /** @type {import('@typescript-eslint/types').TSESTree.ObjectExpression} */node.parent.properties;
|
|
1198
|
+
return sibling.some(child => {
|
|
1199
|
+
const {
|
|
1200
|
+
kind,
|
|
1201
|
+
key: ky
|
|
1202
|
+
} =
|
|
1203
|
+
/**
|
|
1204
|
+
* @type {import('@typescript-eslint/types').TSESTree.MethodDefinition|
|
|
1205
|
+
* import('@typescript-eslint/types').TSESTree.Property}
|
|
1206
|
+
*/
|
|
1207
|
+
child;
|
|
1208
|
+
const name = /** @type {import('@typescript-eslint/types').TSESTree.Identifier} */ky.name;
|
|
974
1209
|
return kind === oppositeKind && name === sourceName;
|
|
975
1210
|
});
|
|
976
1211
|
};
|
|
1212
|
+
|
|
1213
|
+
/**
|
|
1214
|
+
* @param {import('comment-parser').Block} jsdoc
|
|
1215
|
+
* @param {import('eslint').Rule.Node|null} node
|
|
1216
|
+
* @param {import('eslint').Rule.RuleContext} context
|
|
1217
|
+
* @param {import('json-schema').JSONSchema4} schema
|
|
1218
|
+
* @returns {boolean}
|
|
1219
|
+
*/
|
|
977
1220
|
const exemptSpeciaMethods = (jsdoc, node, context, schema) => {
|
|
1221
|
+
/**
|
|
1222
|
+
* @param {"checkGetters"|"checkSetters"|"checkConstructors"} prop
|
|
1223
|
+
* @returns {boolean|"no-setter"|"no-getter"}
|
|
1224
|
+
*/
|
|
978
1225
|
const hasSchemaOption = prop => {
|
|
979
1226
|
var _context$options$2;
|
|
980
1227
|
const schemaProperties = schema[0].properties;
|
|
@@ -982,7 +1229,7 @@ const exemptSpeciaMethods = (jsdoc, node, context, schema) => {
|
|
|
982
1229
|
};
|
|
983
1230
|
const checkGetters = hasSchemaOption('checkGetters');
|
|
984
1231
|
const checkSetters = hasSchemaOption('checkSetters');
|
|
985
|
-
return !hasSchemaOption('checkConstructors') && (isConstructor(node) || hasATag(jsdoc, ['class', 'constructor'])) || isGetter(node) && (!checkGetters || checkGetters === 'no-setter' && hasAccessorPair(node.parent)) || isSetter(node) && (!checkSetters || checkSetters === 'no-getter' && hasAccessorPair(node.parent));
|
|
1232
|
+
return !hasSchemaOption('checkConstructors') && (isConstructor(node) || hasATag(jsdoc, ['class', 'constructor'])) || isGetter(node) && (!checkGetters || checkGetters === 'no-setter' && hasAccessorPair( /** @type {import('./iterateJsdoc.js').Node} */node.parent)) || isSetter(node) && (!checkSetters || checkSetters === 'no-getter' && hasAccessorPair( /** @type {import('./iterateJsdoc.js').Node} */node.parent));
|
|
986
1233
|
};
|
|
987
1234
|
|
|
988
1235
|
/**
|
|
@@ -1009,17 +1256,20 @@ const comparePaths = name => {
|
|
|
1009
1256
|
};
|
|
1010
1257
|
|
|
1011
1258
|
/**
|
|
1259
|
+
* @callback PathDoesNotBeginWith
|
|
1012
1260
|
* @param {string} name
|
|
1013
1261
|
* @param {string} otherPathName
|
|
1014
1262
|
* @returns {boolean}
|
|
1015
1263
|
*/
|
|
1264
|
+
|
|
1265
|
+
/** @type {PathDoesNotBeginWith} */
|
|
1016
1266
|
const pathDoesNotBeginWith = (name, otherPathName) => {
|
|
1017
1267
|
return !name.startsWith(otherPathName) && !dropPathSegmentQuotes(name).startsWith(dropPathSegmentQuotes(otherPathName));
|
|
1018
1268
|
};
|
|
1019
1269
|
|
|
1020
1270
|
/**
|
|
1021
1271
|
* @param {string} regexString
|
|
1022
|
-
* @param {string} requiredFlags
|
|
1272
|
+
* @param {string} [requiredFlags]
|
|
1023
1273
|
* @returns {RegExp}
|
|
1024
1274
|
*/
|
|
1025
1275
|
const getRegexFromString = (regexString, requiredFlags) => {
|
|
@@ -1041,7 +1291,6 @@ var _default = {
|
|
|
1041
1291
|
dropPathSegmentQuotes,
|
|
1042
1292
|
enforcedContexts,
|
|
1043
1293
|
exemptSpeciaMethods,
|
|
1044
|
-
filterTags,
|
|
1045
1294
|
flattenRoots,
|
|
1046
1295
|
getAllTags,
|
|
1047
1296
|
getContextObject,
|