eslint-plugin-jsdoc 39.3.6 → 39.3.13

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.
Files changed (124) hide show
  1. package/README.md +281 -52
  2. package/dist/WarnSettings.js +0 -5
  3. package/dist/WarnSettings.js.map +1 -1
  4. package/dist/alignTransform.js +69 -61
  5. package/dist/alignTransform.js.map +1 -1
  6. package/dist/bin/generateRule.js +7 -26
  7. package/dist/bin/generateRule.js.map +1 -1
  8. package/dist/defaultTagOrder.js +30 -14
  9. package/dist/defaultTagOrder.js.map +1 -1
  10. package/dist/exportParser.js +34 -143
  11. package/dist/exportParser.js.map +1 -1
  12. package/dist/generateRule.js +7 -26
  13. package/dist/generateRule.js.map +1 -1
  14. package/dist/getDefaultTagStructureForMode.js +189 -93
  15. package/dist/getDefaultTagStructureForMode.js.map +1 -1
  16. package/dist/index.js +0 -51
  17. package/dist/index.js.map +1 -1
  18. package/dist/iterateJsdoc.js +43 -206
  19. package/dist/iterateJsdoc.js.map +1 -1
  20. package/dist/jsdocUtils.js +71 -220
  21. package/dist/jsdocUtils.js.map +1 -1
  22. package/dist/rules/checkAccess.js +0 -8
  23. package/dist/rules/checkAccess.js.map +1 -1
  24. package/dist/rules/checkAlignment.js +0 -8
  25. package/dist/rules/checkAlignment.js.map +1 -1
  26. package/dist/rules/checkExamples.js +25 -63
  27. package/dist/rules/checkExamples.js.map +1 -1
  28. package/dist/rules/checkIndentation.js +0 -7
  29. package/dist/rules/checkIndentation.js.map +1 -1
  30. package/dist/rules/checkLineAlignment.js +9 -30
  31. package/dist/rules/checkLineAlignment.js.map +1 -1
  32. package/dist/rules/checkParamNames.js +11 -47
  33. package/dist/rules/checkParamNames.js.map +1 -1
  34. package/dist/rules/checkPropertyNames.js +1 -18
  35. package/dist/rules/checkPropertyNames.js.map +1 -1
  36. package/dist/rules/checkSyntax.js +2 -5
  37. package/dist/rules/checkSyntax.js.map +1 -1
  38. package/dist/rules/checkTagNames.js +0 -18
  39. package/dist/rules/checkTagNames.js.map +1 -1
  40. package/dist/rules/checkTypes.js +17 -46
  41. package/dist/rules/checkTypes.js.map +1 -1
  42. package/dist/rules/checkValues.js +0 -18
  43. package/dist/rules/checkValues.js.map +1 -1
  44. package/dist/rules/emptyTags.js +6 -11
  45. package/dist/rules/emptyTags.js.map +1 -1
  46. package/dist/rules/implementsOnClasses.js +0 -6
  47. package/dist/rules/implementsOnClasses.js.map +1 -1
  48. package/dist/rules/matchDescription.js +0 -20
  49. package/dist/rules/matchDescription.js.map +1 -1
  50. package/dist/rules/matchName.js +2 -17
  51. package/dist/rules/matchName.js.map +1 -1
  52. package/dist/rules/multilineBlocks.js +10 -34
  53. package/dist/rules/multilineBlocks.js.map +1 -1
  54. package/dist/rules/newlineAfterDescription.js +0 -8
  55. package/dist/rules/newlineAfterDescription.js.map +1 -1
  56. package/dist/rules/noBadBlocks.js +2 -16
  57. package/dist/rules/noBadBlocks.js.map +1 -1
  58. package/dist/rules/noDefaults.js +0 -7
  59. package/dist/rules/noDefaults.js.map +1 -1
  60. package/dist/rules/noMissingSyntax.js +2 -16
  61. package/dist/rules/noMissingSyntax.js.map +1 -1
  62. package/dist/rules/noMultiAsterisks.js +2 -16
  63. package/dist/rules/noMultiAsterisks.js.map +1 -1
  64. package/dist/rules/noRestrictedSyntax.js +3 -9
  65. package/dist/rules/noRestrictedSyntax.js.map +1 -1
  66. package/dist/rules/noTypes.js +0 -7
  67. package/dist/rules/noTypes.js.map +1 -1
  68. package/dist/rules/noUndefinedTypes.js +13 -34
  69. package/dist/rules/noUndefinedTypes.js.map +1 -1
  70. package/dist/rules/requireAsteriskPrefix.js +2 -26
  71. package/dist/rules/requireAsteriskPrefix.js.map +1 -1
  72. package/dist/rules/requireDescription.js +0 -17
  73. package/dist/rules/requireDescription.js.map +1 -1
  74. package/dist/rules/requireDescriptionCompleteSentence.js +13 -34
  75. package/dist/rules/requireDescriptionCompleteSentence.js.map +1 -1
  76. package/dist/rules/requireExample.js +0 -9
  77. package/dist/rules/requireExample.js.map +1 -1
  78. package/dist/rules/requireFileOverview.js +0 -16
  79. package/dist/rules/requireFileOverview.js.map +1 -1
  80. package/dist/rules/requireHyphenBeforeParamDescription.js +2 -16
  81. package/dist/rules/requireHyphenBeforeParamDescription.js.map +1 -1
  82. package/dist/rules/requireJsdoc.js +13 -58
  83. package/dist/rules/requireJsdoc.js.map +1 -1
  84. package/dist/rules/requireParam.js +6 -53
  85. package/dist/rules/requireParam.js.map +1 -1
  86. package/dist/rules/requireParamDescription.js +0 -4
  87. package/dist/rules/requireParamDescription.js.map +1 -1
  88. package/dist/rules/requireParamName.js +0 -4
  89. package/dist/rules/requireParamName.js.map +1 -1
  90. package/dist/rules/requireParamType.js +0 -4
  91. package/dist/rules/requireParamType.js.map +1 -1
  92. package/dist/rules/requireProperty.js +0 -9
  93. package/dist/rules/requireProperty.js.map +1 -1
  94. package/dist/rules/requirePropertyDescription.js +0 -4
  95. package/dist/rules/requirePropertyDescription.js.map +1 -1
  96. package/dist/rules/requirePropertyName.js +0 -4
  97. package/dist/rules/requirePropertyName.js.map +1 -1
  98. package/dist/rules/requirePropertyType.js +0 -4
  99. package/dist/rules/requirePropertyType.js.map +1 -1
  100. package/dist/rules/requireReturns.js +13 -23
  101. package/dist/rules/requireReturns.js.map +1 -1
  102. package/dist/rules/requireReturnsCheck.js +12 -20
  103. package/dist/rules/requireReturnsCheck.js.map +1 -1
  104. package/dist/rules/requireReturnsDescription.js +0 -6
  105. package/dist/rules/requireReturnsDescription.js.map +1 -1
  106. package/dist/rules/requireReturnsType.js +0 -4
  107. package/dist/rules/requireReturnsType.js.map +1 -1
  108. package/dist/rules/requireThrows.js +6 -15
  109. package/dist/rules/requireThrows.js.map +1 -1
  110. package/dist/rules/requireYields.js +13 -29
  111. package/dist/rules/requireYields.js.map +1 -1
  112. package/dist/rules/requireYieldsCheck.js +8 -29
  113. package/dist/rules/requireYieldsCheck.js.map +1 -1
  114. package/dist/rules/sortTags.js +17 -30
  115. package/dist/rules/sortTags.js.map +1 -1
  116. package/dist/rules/tagLines.js +0 -26
  117. package/dist/rules/tagLines.js.map +1 -1
  118. package/dist/rules/validTypes.js +22 -53
  119. package/dist/rules/validTypes.js.map +1 -1
  120. package/dist/tagNames.js +7 -4
  121. package/dist/tagNames.js.map +1 -1
  122. package/dist/utils/hasReturnValue.js +22 -66
  123. package/dist/utils/hasReturnValue.js.map +1 -1
  124. package/package.json +16 -16
@@ -11,19 +11,16 @@ Object.defineProperty(exports, "parseComment", {
11
11
  return _jsdoccomment.parseComment;
12
12
  }
13
13
  });
14
-
15
14
  var _jsdoccomment = require("@es-joy/jsdoccomment");
16
-
17
15
  var _commentParser = require("comment-parser");
18
-
19
16
  var _jsdocUtils = _interopRequireDefault(require("./jsdocUtils"));
20
-
21
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
-
23
18
  const {
24
19
  rewireSpecs,
25
20
  seedTokens
26
- } = _commentParser.util; // todo: Change these `any` types once importing types properly.
21
+ } = _commentParser.util;
22
+
23
+ // todo: Change these `any` types once importing types properly.
27
24
 
28
25
  /**
29
26
  * Should use ESLint rule's typing.
@@ -52,13 +49,11 @@ const {
52
49
  */
53
50
 
54
51
  const globalState = new Map();
55
-
56
52
  const getBasicUtils = (context, {
57
53
  tagNamePreference,
58
54
  mode
59
55
  }) => {
60
56
  const utils = {};
61
-
62
57
  utils.reportSettings = message => {
63
58
  context.report({
64
59
  loc: {
@@ -70,33 +65,25 @@ const getBasicUtils = (context, {
70
65
  message
71
66
  });
72
67
  };
73
-
74
68
  utils.parseClosureTemplateTag = tag => {
75
69
  return _jsdocUtils.default.parseClosureTemplateTag(tag);
76
70
  };
77
-
78
71
  utils.pathDoesNotBeginWith = _jsdocUtils.default.pathDoesNotBeginWith;
79
-
80
72
  utils.getPreferredTagNameObject = ({
81
73
  tagName
82
74
  }) => {
83
75
  const ret = _jsdocUtils.default.getPreferredTagName(context, mode, tagName, tagNamePreference);
84
-
85
76
  const isObject = ret && typeof ret === 'object';
86
-
87
77
  if (ret === false || isObject && !ret.replacement) {
88
78
  return {
89
79
  blocked: true,
90
80
  tagName
91
81
  };
92
82
  }
93
-
94
83
  return ret;
95
84
  };
96
-
97
85
  return utils;
98
86
  };
99
-
100
87
  const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAll, ruleConfig, indent) => {
101
88
  const ancestors = context.getAncestors();
102
89
  const sourceCode = context.getSourceCode();
@@ -111,19 +98,15 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
111
98
  minLines,
112
99
  mode
113
100
  } = settings;
114
-
115
101
  utils.isIteratingFunction = () => {
116
102
  return !iteratingAll || ['MethodDefinition', 'ArrowFunctionExpression', 'FunctionDeclaration', 'FunctionExpression'].includes(node && node.type);
117
103
  };
118
-
119
104
  utils.isVirtualFunction = () => {
120
105
  return iteratingAll && utils.hasATag(['callback', 'function', 'func', 'method']);
121
106
  };
122
-
123
107
  utils.stringify = (tagBlock, specRewire) => {
124
108
  return (0, _commentParser.stringify)(specRewire ? rewireSpecs(tagBlock) : tagBlock);
125
109
  };
126
-
127
110
  utils.reportJSDoc = (msg, tag, handler, specRewire, data) => {
128
111
  report(msg, handler ? fixer => {
129
112
  handler();
@@ -131,11 +114,9 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
131
114
  return fixer.replaceText(jsdocNode, replacement);
132
115
  } : null, tag, data);
133
116
  };
134
-
135
117
  utils.getRegexFromString = (str, requiredFlags) => {
136
118
  return _jsdocUtils.default.getRegexFromString(str, requiredFlags);
137
119
  };
138
-
139
120
  utils.getTagDescription = tg => {
140
121
  const descriptions = [];
141
122
  tg.source.some(({
@@ -150,23 +131,21 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
150
131
  description
151
132
  }
152
133
  }) => {
153
- const desc = (tag && postTag || !tag && !name && !type && postDelimiter || '' // Remove space
154
- ).slice(1) + (description || '') + (lineEnd || '');
134
+ const desc = (tag && postTag || !tag && !name && !type && postDelimiter || ''
155
135
 
136
+ // Remove space
137
+ ).slice(1) + (description || '') + (lineEnd || '');
156
138
  if (end) {
157
139
  if (desc) {
158
140
  descriptions.push(desc);
159
141
  }
160
-
161
142
  return true;
162
143
  }
163
-
164
144
  descriptions.push(desc);
165
145
  return false;
166
146
  });
167
147
  return descriptions.join('\n');
168
148
  };
169
-
170
149
  utils.getDescription = () => {
171
150
  const descriptions = [];
172
151
  let lastDescriptionLine = 0;
@@ -181,11 +160,9 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
181
160
  lastDescriptionLine = idx - 1;
182
161
  return true;
183
162
  }
184
-
185
163
  if (idx || description) {
186
164
  descriptions.push(description || (descriptions.length ? '' : '\n'));
187
165
  }
188
-
189
166
  return false;
190
167
  });
191
168
  return {
@@ -193,15 +170,14 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
193
170
  lastDescriptionLine
194
171
  };
195
172
  };
196
-
197
173
  utils.changeTag = (tag, ...tokens) => {
198
174
  for (const [idx, src] of tag.source.entries()) {
199
- src.tokens = { ...src.tokens,
175
+ src.tokens = {
176
+ ...src.tokens,
200
177
  ...tokens[idx]
201
178
  };
202
179
  }
203
180
  };
204
-
205
181
  utils.setTag = (tag, tokens) => {
206
182
  tag.source = [{
207
183
  // Or tag.source[0].number?
@@ -215,11 +191,9 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
215
191
  })
216
192
  }];
217
193
  };
218
-
219
194
  utils.removeTag = idx => {
220
195
  return utils.removeTagItem(idx);
221
196
  };
222
-
223
197
  utils.removeTagItem = (tagIndex, tagSourceOffset = 0) => {
224
198
  const {
225
199
  source: tagSource
@@ -236,8 +210,8 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
236
210
  }
237
211
  }) => {
238
212
  return number === srcNumber && !end;
239
- }); // istanbul ignore else
240
-
213
+ });
214
+ // istanbul ignore else
241
215
  if (sourceIndex > -1) {
242
216
  let spliceCount = 1;
243
217
  tagSource.slice(tagIdx + 1).some(({
@@ -250,30 +224,28 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
250
224
  spliceCount++;
251
225
  return false;
252
226
  }
253
-
254
227
  return true;
255
228
  });
256
229
  jsdoc.source.splice(sourceIndex + tagSourceOffset, spliceCount - tagSourceOffset);
257
230
  tagSource.splice(tagIdx + tagSourceOffset, spliceCount - tagSourceOffset);
258
231
  lastIndex = sourceIndex;
259
232
  return true;
260
- } // istanbul ignore next
261
-
233
+ }
262
234
 
235
+ // istanbul ignore next
263
236
  return false;
264
237
  });
265
-
266
238
  for (const [idx, src] of jsdoc.source.slice(lastIndex).entries()) {
267
239
  src.number = firstNumber + lastIndex + idx;
268
- } // Todo: Once rewiring of tags may be fixed in comment-parser to reflect missing tags,
240
+ }
241
+
242
+ // Todo: Once rewiring of tags may be fixed in comment-parser to reflect missing tags,
269
243
  // this step should be added here (so that, e.g., if accessing `jsdoc.tags`,
270
244
  // such as to add a new tag, the correct information will be available)
271
-
272
245
  };
273
246
 
274
247
  utils.addTag = (targetTagName, number = ((() => {
275
248
  var _jsdoc$tags, _jsdoc$tags$source$;
276
-
277
249
  return (_jsdoc$tags = jsdoc.tags[jsdoc.tags.length - 1]) === null || _jsdoc$tags === void 0 ? void 0 : (_jsdoc$tags$source$ = _jsdoc$tags.source[0]) === null || _jsdoc$tags$source$ === void 0 ? void 0 : _jsdoc$tags$source$.number;
278
250
  })() ?? jsdoc.source.findIndex(({
279
251
  tokens: {
@@ -293,15 +265,12 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
293
265
  ...tokens
294
266
  })
295
267
  });
296
-
297
268
  for (const src of jsdoc.source.slice(number + 1)) {
298
269
  src.number++;
299
270
  }
300
271
  };
301
-
302
272
  utils.getFirstLine = () => {
303
273
  let firstLine;
304
-
305
274
  for (const {
306
275
  number,
307
276
  tokens: {
@@ -313,33 +282,27 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
313
282
  break;
314
283
  }
315
284
  }
316
-
317
285
  return firstLine;
318
286
  };
319
-
320
287
  utils.seedTokens = seedTokens;
321
-
322
288
  utils.emptyTokens = tokens => {
323
289
  for (const prop of ['start', 'postDelimiter', 'tag', 'type', 'postType', 'postTag', 'name', 'postName', 'description', 'end', 'lineEnd']) {
324
290
  tokens[prop] = '';
325
291
  }
326
292
  };
327
-
328
293
  utils.addLine = (sourceIndex, tokens) => {
329
294
  var _jsdoc$source;
330
-
331
295
  const number = (((_jsdoc$source = jsdoc.source[sourceIndex - 1]) === null || _jsdoc$source === void 0 ? void 0 : _jsdoc$source.number) || 0) + 1;
332
296
  jsdoc.source.splice(sourceIndex, 0, {
333
297
  number,
334
298
  source: '',
335
299
  tokens: seedTokens(tokens)
336
300
  });
337
-
338
301
  for (const src of jsdoc.source.slice(number + 1)) {
339
302
  src.number++;
340
- } // If necessary, we can rewire the tags (misnamed method)
303
+ }
304
+ // If necessary, we can rewire the tags (misnamed method)
341
305
  // rewireSource(jsdoc);
342
-
343
306
  };
344
307
 
345
308
  utils.addLines = (tagIndex, tagSourceOffset, numLines) => {
@@ -361,13 +324,11 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
361
324
  })
362
325
  };
363
326
  };
364
-
365
327
  const makeLines = () => {
366
328
  return Array.from({
367
329
  length: numLines
368
330
  }, makeLine);
369
331
  };
370
-
371
332
  const sourceIndex = jsdoc.source.findIndex(({
372
333
  number: srcNumber,
373
334
  tokens: {
@@ -375,25 +336,24 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
375
336
  }
376
337
  }) => {
377
338
  return number === srcNumber && !end;
378
- }); // istanbul ignore else
379
-
339
+ });
340
+ // istanbul ignore else
380
341
  if (sourceIndex > -1) {
381
342
  const lines = makeLines();
382
- jsdoc.source.splice(sourceIndex + tagSourceOffset, 0, ...lines); // tagSource.splice(tagIdx + 1, 0, ...makeLines());
343
+ jsdoc.source.splice(sourceIndex + tagSourceOffset, 0, ...lines);
383
344
 
345
+ // tagSource.splice(tagIdx + 1, 0, ...makeLines());
384
346
  lastIndex = sourceIndex;
385
347
  return true;
386
- } // istanbul ignore next
387
-
348
+ }
388
349
 
350
+ // istanbul ignore next
389
351
  return false;
390
352
  });
391
-
392
353
  for (const [idx, src] of jsdoc.source.slice(lastIndex).entries()) {
393
354
  src.number = firstNumber + lastIndex + idx;
394
355
  }
395
356
  };
396
-
397
357
  utils.makeMultiline = () => {
398
358
  const {
399
359
  source: [{
@@ -414,20 +374,19 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
414
374
  postTag,
415
375
  postType
416
376
  }
417
- } = jsdoc.source[0]; // Strip trailing leftovers from single line ending
377
+ } = jsdoc.source[0];
418
378
 
379
+ // Strip trailing leftovers from single line ending
419
380
  if (!description) {
420
381
  if (postName) {
421
382
  postName = '';
422
383
  } else if (postType) {
423
- postType = ''; // eslint-disable-next-line no-inline-comments
424
- } else
425
- /* istanbul ignore else -- `comment-parser` prevents empty blocks currently per https://github.com/syavorsky/comment-parser/issues/128 */
426
- if (postTag) {
384
+ postType = '';
385
+ // eslint-disable-next-line no-inline-comments
386
+ } else /* istanbul ignore else -- `comment-parser` prevents empty blocks currently per https://github.com/syavorsky/comment-parser/issues/128 */if (postTag) {
427
387
  postTag = '';
428
388
  }
429
389
  }
430
-
431
390
  utils.emptyTokens(tokens);
432
391
  utils.addLine(1, {
433
392
  delimiter: '*',
@@ -449,39 +408,30 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
449
408
  start: indent + ' '
450
409
  });
451
410
  };
452
-
453
411
  utils.flattenRoots = params => {
454
412
  return _jsdocUtils.default.flattenRoots(params);
455
413
  };
456
-
457
414
  utils.getFunctionParameterNames = useDefaultObjectProperties => {
458
415
  return _jsdocUtils.default.getFunctionParameterNames(node, useDefaultObjectProperties);
459
416
  };
460
-
461
417
  utils.hasParams = () => {
462
418
  return _jsdocUtils.default.hasParams(node);
463
419
  };
464
-
465
420
  utils.isGenerator = () => {
466
421
  return node && (node.generator || node.type === 'MethodDefinition' && node.value.generator || ['ExportNamedDeclaration', 'ExportDefaultDeclaration'].includes(node.type) && node.declaration.generator);
467
422
  };
468
-
469
423
  utils.isConstructor = () => {
470
424
  return _jsdocUtils.default.isConstructor(node);
471
425
  };
472
-
473
426
  utils.getJsdocTagsDeep = tagName => {
474
427
  const name = utils.getPreferredTagName({
475
428
  tagName
476
429
  });
477
-
478
430
  if (!name) {
479
431
  return false;
480
432
  }
481
-
482
433
  return _jsdocUtils.default.getJsdocTagsDeep(jsdoc, name);
483
434
  };
484
-
485
435
  utils.getPreferredTagName = ({
486
436
  tagName,
487
437
  skipReportingBlockedTag = false,
@@ -489,9 +439,7 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
489
439
  defaultMessage = `Unexpected tag \`@${tagName}\``
490
440
  }) => {
491
441
  const ret = _jsdocUtils.default.getPreferredTagName(context, mode, tagName, tagNamePreference);
492
-
493
442
  const isObject = ret && typeof ret === 'object';
494
-
495
443
  if (utils.hasTag(tagName) && (ret === false || isObject && !ret.replacement)) {
496
444
  if (skipReportingBlockedTag) {
497
445
  return {
@@ -499,67 +447,50 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
499
447
  tagName
500
448
  };
501
449
  }
502
-
503
450
  const message = isObject && ret.message || defaultMessage;
504
451
  report(message, null, utils.getTags(tagName)[0]);
505
452
  return false;
506
453
  }
507
-
508
454
  return isObject && !allowObjectReturn ? ret.replacement : ret;
509
455
  };
510
-
511
456
  utils.isValidTag = (name, definedTags) => {
512
457
  return _jsdocUtils.default.isValidTag(context, mode, name, definedTags);
513
458
  };
514
-
515
459
  utils.hasATag = names => {
516
460
  return _jsdocUtils.default.hasATag(jsdoc, names);
517
461
  };
518
-
519
462
  utils.hasTag = name => {
520
463
  return _jsdocUtils.default.hasTag(jsdoc, name);
521
464
  };
522
-
523
465
  utils.comparePaths = name => {
524
466
  return _jsdocUtils.default.comparePaths(name);
525
467
  };
526
-
527
468
  utils.dropPathSegmentQuotes = name => {
528
469
  return _jsdocUtils.default.dropPathSegmentQuotes(name);
529
470
  };
530
-
531
471
  utils.avoidDocs = () => {
532
472
  var _context$options$;
533
-
534
473
  if (ignoreReplacesDocs !== false && (utils.hasTag('ignore') || utils.classHasTag('ignore')) || overrideReplacesDocs !== false && (utils.hasTag('override') || utils.classHasTag('override')) || implementsReplacesDocs !== false && (utils.hasTag('implements') || utils.classHasTag('implements')) || augmentsExtendsReplacesDocs && (utils.hasATag(['augments', 'extends']) || utils.classHasTag('augments') || utils.classHasTag('extends'))) {
535
474
  return true;
536
475
  }
537
-
538
476
  if (_jsdocUtils.default.exemptSpeciaMethods(jsdoc, node, context, ruleConfig.meta.schema)) {
539
477
  return true;
540
478
  }
541
-
542
479
  const exemptedBy = ((_context$options$ = context.options[0]) === null || _context$options$ === void 0 ? void 0 : _context$options$.exemptedBy) ?? ['inheritDoc', ...(mode === 'closure' ? [] : ['inheritdoc'])];
543
-
544
480
  if (exemptedBy.length && utils.getPresentTags(exemptedBy).length) {
545
481
  return true;
546
482
  }
547
-
548
483
  return false;
549
484
  };
550
-
551
485
  for (const method of ['tagMightHaveNamePosition', 'tagMightHaveTypePosition']) {
552
486
  utils[method] = (tagName, otherModeMaps) => {
553
487
  const result = _jsdocUtils.default[method](tagName);
554
-
555
488
  if (result) {
556
489
  return true;
557
490
  }
558
-
559
491
  if (!otherModeMaps) {
560
492
  return false;
561
493
  }
562
-
563
494
  const otherResult = otherModeMaps.some(otherModeMap => {
564
495
  return _jsdocUtils.default[method](tagName, otherModeMap);
565
496
  });
@@ -568,15 +499,14 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
568
499
  } : false;
569
500
  };
570
501
  }
571
-
572
502
  for (const method of ['tagMustHaveNamePosition', 'tagMustHaveTypePosition', 'tagMissingRequiredTypeOrNamepath']) {
573
503
  utils[method] = (tagName, otherModeMaps) => {
574
504
  const result = _jsdocUtils.default[method](tagName);
575
-
576
505
  if (!result) {
577
506
  return false;
578
- } // if (!otherModeMaps) { return true; }
507
+ }
579
508
 
509
+ // if (!otherModeMaps) { return true; }
580
510
 
581
511
  const otherResult = otherModeMaps.every(otherModeMap => {
582
512
  return _jsdocUtils.default[method](tagName, otherModeMap);
@@ -586,129 +516,101 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
586
516
  };
587
517
  };
588
518
  }
589
-
590
519
  for (const method of ['isNamepathDefiningTag', 'tagMightHaveNamepath']) {
591
520
  utils[method] = tagName => {
592
521
  return _jsdocUtils.default[method](tagName);
593
522
  };
594
523
  }
595
-
596
524
  utils.getTagStructureForMode = mde => {
597
525
  return _jsdocUtils.default.getTagStructureForMode(mde, settings.structuredTags);
598
526
  };
599
-
600
527
  utils.hasDefinedTypeTag = tag => {
601
528
  return _jsdocUtils.default.hasDefinedTypeTag(tag);
602
529
  };
603
-
604
530
  utils.hasValueOrExecutorHasNonEmptyResolveValue = anyPromiseAsReturn => {
605
531
  return _jsdocUtils.default.hasValueOrExecutorHasNonEmptyResolveValue(node, anyPromiseAsReturn);
606
532
  };
607
-
608
533
  utils.hasYieldValue = () => {
609
534
  if (['ExportNamedDeclaration', 'ExportDefaultDeclaration'].includes(node.type)) {
610
535
  return _jsdocUtils.default.hasYieldValue(node.declaration);
611
536
  }
612
-
613
537
  return _jsdocUtils.default.hasYieldValue(node);
614
538
  };
615
-
616
539
  utils.hasYieldReturnValue = () => {
617
540
  return _jsdocUtils.default.hasYieldValue(node, true);
618
541
  };
619
-
620
542
  utils.hasThrowValue = () => {
621
543
  return _jsdocUtils.default.hasThrowValue(node);
622
544
  };
623
-
624
545
  utils.isAsync = () => {
625
546
  return node.async;
626
547
  };
627
-
628
548
  utils.getTags = tagName => {
629
549
  return utils.filterTags(item => {
630
550
  return item.tag === tagName;
631
551
  });
632
552
  };
633
-
634
553
  utils.getPresentTags = tagList => {
635
554
  return utils.filterTags(tag => {
636
555
  return tagList.includes(tag.tag);
637
556
  });
638
557
  };
639
-
640
558
  utils.filterTags = filter => {
641
559
  return _jsdocUtils.default.filterTags(jsdoc.tags, filter);
642
560
  };
643
-
644
561
  utils.getTagsByType = tags => {
645
562
  return _jsdocUtils.default.getTagsByType(context, mode, tags, tagNamePreference);
646
563
  };
647
-
648
564
  utils.hasOptionTag = tagName => {
649
565
  const {
650
566
  tags
651
567
  } = context.options[0] ?? {};
652
568
  return Boolean(tags && tags.includes(tagName));
653
569
  };
654
-
655
570
  utils.getClassNode = () => {
656
571
  return [...ancestors, node].reverse().find(parent => {
657
572
  return parent && ['ClassDeclaration', 'ClassExpression'].includes(parent.type);
658
573
  }) || null;
659
574
  };
660
-
661
575
  utils.getClassJsdoc = () => {
662
576
  const classNode = utils.getClassNode();
663
-
664
577
  if (!classNode) {
665
578
  return null;
666
579
  }
667
-
668
580
  const classJsdocNode = (0, _jsdoccomment.getJSDocComment)(sourceCode, classNode, {
669
581
  maxLines,
670
582
  minLines
671
583
  });
672
-
673
584
  if (classJsdocNode) {
674
585
  return (0, _jsdoccomment.parseComment)(classJsdocNode, '');
675
586
  }
676
-
677
587
  return null;
678
588
  };
679
-
680
589
  utils.classHasTag = tagName => {
681
590
  const classJsdoc = utils.getClassJsdoc();
682
591
  return Boolean(classJsdoc) && _jsdocUtils.default.hasTag(classJsdoc, tagName);
683
592
  };
684
-
685
593
  utils.forEachPreferredTag = (tagName, arrayHandler, skipReportingBlockedTag = false) => {
686
594
  const targetTagName = utils.getPreferredTagName({
687
595
  skipReportingBlockedTag,
688
596
  tagName
689
597
  });
690
-
691
598
  if (!targetTagName || skipReportingBlockedTag && targetTagName && typeof targetTagName === 'object') {
692
599
  return;
693
600
  }
694
-
695
601
  const matchingJsdocTags = jsdoc.tags.filter(({
696
602
  tag
697
603
  }) => {
698
604
  return tag === targetTagName;
699
605
  });
700
-
701
606
  for (const matchingJsdocTag of matchingJsdocTags) {
702
607
  arrayHandler(matchingJsdocTag, targetTagName);
703
608
  }
704
609
  };
705
-
706
610
  return utils;
707
611
  };
708
-
709
612
  const getSettings = context => {
710
613
  var _context$settings$jsd, _context$settings$jsd2, _context$settings$jsd3, _context$settings$jsd4, _context$settings$jsd5, _context$settings$jsd6, _context$settings$jsd7, _context$settings$jsd8, _context$settings$jsd9, _context$settings$jsd10, _context$settings$jsd11, _context$settings$jsd12;
711
-
712
614
  /* eslint-disable canonical/sort-keys */
713
615
  const settings = {
714
616
  // All rules
@@ -734,7 +636,6 @@ const getSettings = context => {
734
636
  /* eslint-enable canonical/sort-keys */
735
637
 
736
638
  _jsdocUtils.default.setTagStructure(settings.mode);
737
-
738
639
  try {
739
640
  _jsdocUtils.default.overrideTagStructure(settings.structuredTags);
740
641
  } catch (error) {
@@ -749,28 +650,23 @@ const getSettings = context => {
749
650
  });
750
651
  return false;
751
652
  }
752
-
753
653
  return settings;
754
654
  };
655
+
755
656
  /**
756
657
  * Create the report function
757
658
  *
758
659
  * @param {object} context
759
660
  * @param {object} commentNode
760
661
  */
761
-
762
-
763
662
  exports.getSettings = getSettings;
764
-
765
663
  const makeReport = (context, commentNode) => {
766
664
  const report = (message, fix = null, jsdocLoc = null, data = null) => {
767
665
  let loc;
768
-
769
666
  if (jsdocLoc) {
770
667
  if (!('line' in jsdocLoc)) {
771
668
  jsdocLoc.line = jsdocLoc.source[0].number;
772
669
  }
773
-
774
670
  const lineNumber = commentNode.loc.start.line + jsdocLoc.line;
775
671
  loc = {
776
672
  end: {
@@ -781,16 +677,16 @@ const makeReport = (context, commentNode) => {
781
677
  column: 0,
782
678
  line: lineNumber
783
679
  }
784
- }; // Todo: Remove ignore once `check-examples` can be restored for ESLint 8+
785
- // istanbul ignore if
680
+ };
786
681
 
682
+ // Todo: Remove ignore once `check-examples` can be restored for ESLint 8+
683
+ // istanbul ignore if
787
684
  if (jsdocLoc.column) {
788
685
  const colNumber = commentNode.loc.start.column + jsdocLoc.column;
789
686
  loc.end.column = colNumber;
790
687
  loc.start.column = colNumber;
791
688
  }
792
689
  }
793
-
794
690
  context.report({
795
691
  data,
796
692
  fix,
@@ -799,11 +695,10 @@ const makeReport = (context, commentNode) => {
799
695
  node: commentNode
800
696
  });
801
697
  };
802
-
803
698
  return report;
804
699
  };
805
- /* eslint-disable jsdoc/no-undefined-types -- canonical still using an older version where not defined */
806
700
 
701
+ /* eslint-disable jsdoc/no-undefined-types -- canonical still using an older version where not defined */
807
702
  /**
808
703
  * @typedef {ReturnType<typeof getUtils>} Utils
809
704
  * @typedef {ReturnType<typeof getSettings>} Settings
@@ -821,18 +716,14 @@ const makeReport = (context, commentNode) => {
821
716
  * }
822
717
  * ) => any } JsdocVisitor
823
718
  */
824
-
825
719
  /* eslint-enable jsdoc/no-undefined-types -- canonical still using an older version where not defined */
826
720
 
827
-
828
721
  const iterate = (info, indent, jsdoc, ruleConfig, context, lines, jsdocNode, node, settings, sourceCode, iterator, state, iteratingAll) => {
829
722
  const report = makeReport(context, jsdocNode);
830
723
  const utils = getUtils(node, jsdoc, jsdocNode, settings, report, context, iteratingAll, ruleConfig, indent);
831
-
832
724
  if (!ruleConfig.checkInternal && settings.ignoreInternal && utils.hasTag('internal')) {
833
725
  return;
834
726
  }
835
-
836
727
  if (!ruleConfig.checkPrivate && settings.ignorePrivate && (utils.hasTag('private') || jsdoc.tags.filter(({
837
728
  tag
838
729
  }) => {
@@ -844,7 +735,6 @@ const iterate = (info, indent, jsdoc, ruleConfig, context, lines, jsdocNode, nod
844
735
  }))) {
845
736
  return;
846
737
  }
847
-
848
738
  iterator({
849
739
  context,
850
740
  globalState,
@@ -861,13 +751,13 @@ const iterate = (info, indent, jsdoc, ruleConfig, context, lines, jsdocNode, nod
861
751
  utils
862
752
  });
863
753
  };
864
-
865
754
  const getIndentAndJSDoc = function (lines, jsdocNode) {
866
755
  const sourceLine = lines[jsdocNode.loc.start.line - 1];
867
756
  const indnt = sourceLine.charAt(0).repeat(jsdocNode.loc.start.column);
868
757
  const jsdc = (0, _jsdoccomment.parseComment)(jsdocNode, '');
869
758
  return [indnt, jsdc];
870
759
  };
760
+
871
761
  /**
872
762
  *
873
763
  * @typedef {{node: Node, state: StateObject}} NonCommentArgs
@@ -904,27 +794,21 @@ const getIndentAndJSDoc = function (lines, jsdocNode) {
904
794
  * iteration for each matching comment context. Otherwise, will iterate
905
795
  * once if there is a single matching comment context.
906
796
  */
907
-
908
-
909
797
  const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContexts) => {
910
798
  const trackedJsdocs = new Set();
911
799
  let handler;
912
800
  let settings;
913
-
914
801
  const callIterator = (context, node, jsdocNodes, state, lastCall) => {
915
802
  const sourceCode = context.getSourceCode();
916
803
  const {
917
804
  lines
918
805
  } = sourceCode;
919
806
  const utils = getBasicUtils(context, settings);
920
-
921
807
  for (const jsdocNode of jsdocNodes) {
922
808
  if (!/^\/\*\*\s/u.test(sourceCode.getText(jsdocNode))) {
923
809
  continue;
924
810
  }
925
-
926
811
  const [indent, jsdoc] = getIndentAndJSDoc(lines, jsdocNode);
927
-
928
812
  if (additiveCommentContexts) {
929
813
  for (const [idx, {
930
814
  comment
@@ -932,20 +816,17 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext
932
816
  if (comment && handler(comment, jsdoc) === false) {
933
817
  continue;
934
818
  }
935
-
936
819
  iterate({
937
820
  comment,
938
821
  lastIndex: idx,
939
822
  selector: node === null || node === void 0 ? void 0 : node.type
940
823
  }, indent, jsdoc, ruleConfig, context, lines, jsdocNode, node, settings, sourceCode, iterator, state, true);
941
824
  }
942
-
943
825
  continue;
944
826
  }
945
-
946
827
  let lastComment;
947
- let lastIndex; // eslint-disable-next-line no-loop-func
948
-
828
+ let lastIndex;
829
+ // eslint-disable-next-line no-loop-func
949
830
  if (contexts && contexts.every(({
950
831
  comment
951
832
  }, idx) => {
@@ -955,7 +836,6 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext
955
836
  })) {
956
837
  continue;
957
838
  }
958
-
959
839
  iterate(lastComment ? {
960
840
  comment: lastComment,
961
841
  lastIndex,
@@ -965,7 +845,6 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext
965
845
  selector: node === null || node === void 0 ? void 0 : node.type
966
846
  }, indent, jsdoc, ruleConfig, context, lines, jsdocNode, node, settings, sourceCode, iterator, state, true);
967
847
  }
968
-
969
848
  if (lastCall && ruleConfig.exit) {
970
849
  ruleConfig.exit({
971
850
  context,
@@ -974,35 +853,27 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext
974
853
  });
975
854
  }
976
855
  };
977
-
978
856
  return {
979
857
  create(context) {
980
858
  const sourceCode = context.getSourceCode();
981
859
  settings = getSettings(context);
982
-
983
860
  if (!settings) {
984
861
  return {};
985
862
  }
986
-
987
863
  if (contexts) {
988
864
  handler = (0, _jsdoccomment.commentHandler)(settings);
989
865
  }
990
-
991
866
  const state = {};
992
867
  return {
993
868
  '*:not(Program)'(node) {
994
869
  const reducedNode = (0, _jsdoccomment.getReducedASTNode)(node, sourceCode);
995
-
996
870
  if (node !== reducedNode) {
997
871
  return;
998
872
  }
999
-
1000
873
  const commentNode = (0, _jsdoccomment.getJSDocComment)(sourceCode, node, settings);
1001
-
1002
874
  if (trackedJsdocs.has(commentNode)) {
1003
875
  return;
1004
876
  }
1005
-
1006
877
  if (!commentNode) {
1007
878
  if (ruleConfig.nonComment) {
1008
879
  ruleConfig.nonComment({
@@ -1010,14 +881,11 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext
1010
881
  state
1011
882
  });
1012
883
  }
1013
-
1014
884
  return;
1015
885
  }
1016
-
1017
886
  trackedJsdocs.add(commentNode);
1018
887
  callIterator(context, node, [commentNode], state);
1019
888
  },
1020
-
1021
889
  'Program:exit'() {
1022
890
  const allComments = sourceCode.getAllComments();
1023
891
  const untrackedJSdoc = allComments.filter(node => {
@@ -1025,13 +893,12 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext
1025
893
  });
1026
894
  callIterator(context, null, untrackedJSdoc, state, true);
1027
895
  }
1028
-
1029
896
  };
1030
897
  },
1031
-
1032
898
  meta: ruleConfig.meta
1033
899
  };
1034
900
  };
901
+
1035
902
  /**
1036
903
  * Create an eslint rule that iterates over all JSDocs, regardless of whether
1037
904
  * they are attached to a function-like node.
@@ -1039,18 +906,14 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext
1039
906
  * @param {JsdocVisitor} iterator
1040
907
  * @param {RuleConfig} ruleConfig
1041
908
  */
1042
-
1043
-
1044
909
  const checkFile = (iterator, ruleConfig) => {
1045
910
  return {
1046
911
  create(context) {
1047
912
  const sourceCode = context.getSourceCode();
1048
913
  const settings = getSettings(context);
1049
-
1050
914
  if (!settings) {
1051
915
  return {};
1052
916
  }
1053
-
1054
917
  return {
1055
918
  'Program:exit'() {
1056
919
  const allComments = sourceCode.getAllComments();
@@ -1068,39 +931,30 @@ const checkFile = (iterator, ruleConfig) => {
1068
931
  utils
1069
932
  });
1070
933
  }
1071
-
1072
934
  };
1073
935
  },
1074
-
1075
936
  meta: ruleConfig.meta
1076
937
  };
1077
938
  };
1078
-
1079
939
  /**
1080
940
  * @param {JsdocVisitor} iterator
1081
941
  * @param {RuleConfig} ruleConfig
1082
942
  */
1083
943
  function iterateJsdoc(iterator, ruleConfig) {
1084
944
  var _ruleConfig$meta;
1085
-
1086
945
  const metaType = ruleConfig === null || ruleConfig === void 0 ? void 0 : (_ruleConfig$meta = ruleConfig.meta) === null || _ruleConfig$meta === void 0 ? void 0 : _ruleConfig$meta.type;
1087
-
1088
946
  if (!metaType || !['problem', 'suggestion', 'layout'].includes(metaType)) {
1089
947
  throw new TypeError('Rule must include `meta.type` option (with value "problem", "suggestion", or "layout")');
1090
948
  }
1091
-
1092
949
  if (typeof iterator !== 'function') {
1093
950
  throw new TypeError('The iterator argument must be a function.');
1094
951
  }
1095
-
1096
952
  if (ruleConfig.checkFile) {
1097
953
  return checkFile(iterator, ruleConfig);
1098
954
  }
1099
-
1100
955
  if (ruleConfig.iterateAllJsdocs) {
1101
956
  return iterateAllJsdocs(iterator, ruleConfig);
1102
957
  }
1103
-
1104
958
  return {
1105
959
  /**
1106
960
  * The entrypoint for the JSDoc rule.
@@ -1113,67 +967,53 @@ function iterateJsdoc(iterator, ruleConfig) {
1113
967
  */
1114
968
  create(context) {
1115
969
  const settings = getSettings(context);
1116
-
1117
970
  if (!settings) {
1118
971
  return {};
1119
972
  }
1120
-
1121
973
  let contexts;
1122
-
1123
974
  if (ruleConfig.contextDefaults || ruleConfig.contextSelected || ruleConfig.matchContext) {
1124
975
  var _context$options$2, _contexts, _contexts2;
1125
-
1126
976
  contexts = ruleConfig.matchContext && (_context$options$2 = context.options[0]) !== null && _context$options$2 !== void 0 && _context$options$2.match ? context.options[0].match : _jsdocUtils.default.enforcedContexts(context, ruleConfig.contextDefaults);
1127
-
1128
977
  if (contexts) {
1129
978
  contexts = contexts.map(obj => {
1130
979
  if (typeof obj === 'object' && !obj.context) {
1131
- return { ...obj,
980
+ return {
981
+ ...obj,
1132
982
  context: 'any'
1133
983
  };
1134
984
  }
1135
-
1136
985
  return obj;
1137
986
  });
1138
987
  }
1139
-
1140
988
  const hasPlainAny = (_contexts = contexts) === null || _contexts === void 0 ? void 0 : _contexts.includes('any');
1141
989
  const hasObjectAny = !hasPlainAny && ((_contexts2 = contexts) === null || _contexts2 === void 0 ? void 0 : _contexts2.find(ctxt => {
1142
990
  return (ctxt === null || ctxt === void 0 ? void 0 : ctxt.context) === 'any';
1143
991
  }));
1144
-
1145
992
  if (hasPlainAny || hasObjectAny) {
1146
993
  return iterateAllJsdocs(iterator, ruleConfig, hasObjectAny ? contexts : null, ruleConfig.matchContext).create(context);
1147
994
  }
1148
995
  }
1149
-
1150
996
  const sourceCode = context.getSourceCode();
1151
997
  const {
1152
998
  lines
1153
999
  } = sourceCode;
1154
1000
  const state = {};
1155
-
1156
1001
  const checkJsdoc = (info, handler, node) => {
1157
1002
  const jsdocNode = (0, _jsdoccomment.getJSDocComment)(sourceCode, node, settings);
1158
-
1159
1003
  if (!jsdocNode) {
1160
1004
  return;
1161
1005
  }
1162
-
1163
1006
  const [indent, jsdoc] = getIndentAndJSDoc(lines, jsdocNode);
1164
-
1165
- if ( // Note, `handler` should already be bound in its first argument
1007
+ if (
1008
+ // Note, `handler` should already be bound in its first argument
1166
1009
  // with these only to be called after the value of
1167
1010
  // `comment`
1168
1011
  handler && handler(jsdoc) === false) {
1169
1012
  return;
1170
1013
  }
1171
-
1172
1014
  iterate(info, indent, jsdoc, ruleConfig, context, lines, jsdocNode, node, settings, sourceCode, iterator, state);
1173
1015
  };
1174
-
1175
1016
  let contextObject = {};
1176
-
1177
1017
  if (contexts && (ruleConfig.contextDefaults || ruleConfig.contextSelected || ruleConfig.matchContext)) {
1178
1018
  contextObject = _jsdocUtils.default.getContextObject(contexts, checkJsdoc, (0, _jsdoccomment.commentHandler)(settings));
1179
1019
  } else {
@@ -1183,7 +1023,6 @@ function iterateJsdoc(iterator, ruleConfig) {
1183
1023
  }, null);
1184
1024
  }
1185
1025
  }
1186
-
1187
1026
  if (ruleConfig.exit) {
1188
1027
  contextObject['Program:exit'] = () => {
1189
1028
  ruleConfig.exit({
@@ -1192,10 +1031,8 @@ function iterateJsdoc(iterator, ruleConfig) {
1192
1031
  });
1193
1032
  };
1194
1033
  }
1195
-
1196
1034
  return contextObject;
1197
1035
  },
1198
-
1199
1036
  meta: ruleConfig.meta
1200
1037
  };
1201
1038
  }