eslint-plugin-jsdoc 50.6.16 → 50.7.0

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 (155) hide show
  1. package/dist/alignTransform.cjs +10 -10
  2. package/dist/alignTransform.cjs.map +1 -1
  3. package/dist/exportParser.cjs +141 -135
  4. package/dist/exportParser.cjs.map +1 -1
  5. package/dist/generateRule.cjs +10 -12
  6. package/dist/generateRule.cjs.map +1 -1
  7. package/dist/getDefaultTagStructureForMode.cjs +73 -73
  8. package/dist/getDefaultTagStructureForMode.cjs.map +1 -1
  9. package/dist/getJsdocProcessorPlugin.cjs +121 -110
  10. package/dist/getJsdocProcessorPlugin.cjs.map +1 -1
  11. package/dist/index.cjs +17 -12
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.ts +4 -3
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/iterateJsdoc.cjs +87 -66
  16. package/dist/iterateJsdoc.cjs.map +1 -1
  17. package/dist/jsdocUtils.cjs +144 -142
  18. package/dist/jsdocUtils.cjs.map +1 -1
  19. package/dist/rules/checkAlignment.cjs +2 -2
  20. package/dist/rules/checkAlignment.cjs.map +1 -1
  21. package/dist/rules/checkExamples.cjs +22 -28
  22. package/dist/rules/checkExamples.cjs.map +1 -1
  23. package/dist/rules/checkIndentation.cjs +2 -2
  24. package/dist/rules/checkIndentation.cjs.map +1 -1
  25. package/dist/rules/checkLineAlignment.cjs +14 -14
  26. package/dist/rules/checkLineAlignment.cjs.map +1 -1
  27. package/dist/rules/checkParamNames.cjs +21 -15
  28. package/dist/rules/checkParamNames.cjs.map +1 -1
  29. package/dist/rules/checkPropertyNames.cjs +2 -2
  30. package/dist/rules/checkPropertyNames.cjs.map +1 -1
  31. package/dist/rules/checkTagNames.cjs +11 -11
  32. package/dist/rules/checkTagNames.cjs.map +1 -1
  33. package/dist/rules/checkTemplateNames.cjs +21 -22
  34. package/dist/rules/checkTemplateNames.cjs.map +1 -1
  35. package/dist/rules/checkTypes.cjs +10 -10
  36. package/dist/rules/checkTypes.cjs.map +1 -1
  37. package/dist/rules/checkValues.cjs +11 -14
  38. package/dist/rules/checkValues.cjs.map +1 -1
  39. package/dist/rules/convertToJsdocComments.cjs +26 -27
  40. package/dist/rules/convertToJsdocComments.cjs.map +1 -1
  41. package/dist/rules/emptyTags.cjs +6 -6
  42. package/dist/rules/emptyTags.cjs.map +1 -1
  43. package/dist/rules/importsAsDependencies.cjs.map +1 -1
  44. package/dist/rules/informativeDocs.cjs +12 -12
  45. package/dist/rules/informativeDocs.cjs.map +1 -1
  46. package/dist/rules/linesBeforeBlock.cjs +12 -12
  47. package/dist/rules/linesBeforeBlock.cjs.map +1 -1
  48. package/dist/rules/matchDescription.cjs +1 -1
  49. package/dist/rules/matchDescription.cjs.map +1 -1
  50. package/dist/rules/matchName.cjs +4 -4
  51. package/dist/rules/matchName.cjs.map +1 -1
  52. package/dist/rules/multilineBlocks.cjs +10 -10
  53. package/dist/rules/multilineBlocks.cjs.map +1 -1
  54. package/dist/rules/noBadBlocks.cjs +3 -3
  55. package/dist/rules/noBadBlocks.cjs.map +1 -1
  56. package/dist/rules/noMultiAsterisks.cjs +6 -6
  57. package/dist/rules/noMultiAsterisks.cjs.map +1 -1
  58. package/dist/rules/noRestrictedSyntax.cjs +2 -2
  59. package/dist/rules/noRestrictedSyntax.cjs.map +1 -1
  60. package/dist/rules/noTypes.cjs.map +1 -1
  61. package/dist/rules/noUndefinedTypes.cjs +17 -20
  62. package/dist/rules/noUndefinedTypes.cjs.map +1 -1
  63. package/dist/rules/requireAsteriskPrefix.cjs +4 -4
  64. package/dist/rules/requireAsteriskPrefix.cjs.map +1 -1
  65. package/dist/rules/requireDescription.cjs +2 -2
  66. package/dist/rules/requireDescription.cjs.map +1 -1
  67. package/dist/rules/requireDescriptionCompleteSentence.cjs +8 -8
  68. package/dist/rules/requireDescriptionCompleteSentence.cjs.map +1 -1
  69. package/dist/rules/requireFileOverview.cjs +6 -6
  70. package/dist/rules/requireFileOverview.cjs.map +1 -1
  71. package/dist/rules/requireHyphenBeforeParamDescription.cjs +1 -4
  72. package/dist/rules/requireHyphenBeforeParamDescription.cjs.map +1 -1
  73. package/dist/rules/requireJsdoc.cjs +19 -19
  74. package/dist/rules/requireJsdoc.cjs.map +1 -1
  75. package/dist/rules/requireParam.cjs +12 -12
  76. package/dist/rules/requireParam.cjs.map +1 -1
  77. package/dist/rules/requireProperty.cjs +1 -1
  78. package/dist/rules/requireProperty.cjs.map +1 -1
  79. package/dist/rules/requireReturns.cjs +3 -3
  80. package/dist/rules/requireReturns.cjs.map +1 -1
  81. package/dist/rules/requireReturnsCheck.cjs +1 -1
  82. package/dist/rules/requireReturnsCheck.cjs.map +1 -1
  83. package/dist/rules/requireReturnsDescription.cjs +1 -1
  84. package/dist/rules/requireReturnsDescription.cjs.map +1 -1
  85. package/dist/rules/requireTemplate.cjs +16 -15
  86. package/dist/rules/requireTemplate.cjs.map +1 -1
  87. package/dist/rules/requireYields.cjs +4 -4
  88. package/dist/rules/requireYields.cjs.map +1 -1
  89. package/dist/rules/requireYieldsCheck.cjs +6 -6
  90. package/dist/rules/requireYieldsCheck.cjs.map +1 -1
  91. package/dist/rules/sortTags.cjs +13 -13
  92. package/dist/rules/sortTags.cjs.map +1 -1
  93. package/dist/rules/tagLines.cjs +11 -11
  94. package/dist/rules/tagLines.cjs.map +1 -1
  95. package/dist/rules/textEscaping.cjs +2 -2
  96. package/dist/rules/textEscaping.cjs.map +1 -1
  97. package/dist/rules/validTypes.cjs +15 -15
  98. package/dist/rules/validTypes.cjs.map +1 -1
  99. package/dist/tagNames.cjs +1 -1
  100. package/dist/tagNames.cjs.map +1 -1
  101. package/dist/utils/hasReturnValue.cjs +176 -176
  102. package/dist/utils/hasReturnValue.cjs.map +1 -1
  103. package/eslint.config.js +36 -32
  104. package/package.json +35 -35
  105. package/pnpm-workspace.yaml +1 -0
  106. package/src/alignTransform.js +15 -15
  107. package/src/exportParser.js +386 -373
  108. package/src/getDefaultTagStructureForMode.js +45 -45
  109. package/src/getJsdocProcessorPlugin.js +175 -128
  110. package/src/index.js +66 -37
  111. package/src/iterateJsdoc.js +61 -28
  112. package/src/jsdocUtils.js +354 -338
  113. package/src/rules/checkAlignment.js +2 -2
  114. package/src/rules/checkExamples.js +16 -20
  115. package/src/rules/checkIndentation.js +2 -2
  116. package/src/rules/checkLineAlignment.js +10 -10
  117. package/src/rules/checkParamNames.js +22 -14
  118. package/src/rules/checkPropertyNames.js +1 -1
  119. package/src/rules/checkTagNames.js +7 -7
  120. package/src/rules/checkTemplateNames.js +52 -38
  121. package/src/rules/checkTypes.js +7 -7
  122. package/src/rules/checkValues.js +16 -17
  123. package/src/rules/convertToJsdocComments.js +47 -37
  124. package/src/rules/emptyTags.js +14 -7
  125. package/src/rules/importsAsDependencies.js +3 -1
  126. package/src/rules/informativeDocs.js +58 -58
  127. package/src/rules/linesBeforeBlock.js +25 -17
  128. package/src/rules/matchDescription.js +1 -1
  129. package/src/rules/matchName.js +2 -2
  130. package/src/rules/multilineBlocks.js +10 -10
  131. package/src/rules/noBadBlocks.js +3 -3
  132. package/src/rules/noMultiAsterisks.js +4 -4
  133. package/src/rules/noRestrictedSyntax.js +1 -1
  134. package/src/rules/noTypes.js +1 -1
  135. package/src/rules/noUndefinedTypes.js +29 -23
  136. package/src/rules/requireAsteriskPrefix.js +3 -3
  137. package/src/rules/requireDescription.js +1 -1
  138. package/src/rules/requireDescriptionCompleteSentence.js +6 -6
  139. package/src/rules/requireFileOverview.js +3 -3
  140. package/src/rules/requireHyphenBeforeParamDescription.js +2 -5
  141. package/src/rules/requireJsdoc.js +14 -14
  142. package/src/rules/requireParam.js +9 -9
  143. package/src/rules/requireProperty.js +1 -1
  144. package/src/rules/requireReturns.js +1 -1
  145. package/src/rules/requireReturnsCheck.js +1 -1
  146. package/src/rules/requireReturnsDescription.js +1 -1
  147. package/src/rules/requireTemplate.js +59 -38
  148. package/src/rules/requireYields.js +3 -3
  149. package/src/rules/requireYieldsCheck.js +1 -1
  150. package/src/rules/sortTags.js +7 -7
  151. package/src/rules/tagLines.js +8 -8
  152. package/src/rules/textEscaping.js +2 -0
  153. package/src/rules/validTypes.js +29 -29
  154. package/src/tagNames.js +2 -2
  155. package/src/utils/hasReturnValue.js +298 -283
package/src/jsdocUtils.js CHANGED
@@ -4,10 +4,6 @@ import {
4
4
  jsdocTags,
5
5
  typeScriptTags,
6
6
  } from './tagNames.js';
7
- import {
8
- hasReturnValue,
9
- hasValueOrExecutorHasNonEmptyResolveValue,
10
- } from './utils/hasReturnValue.js';
11
7
  import WarnSettings from './WarnSettings.js';
12
8
  import {
13
9
  tryParse,
@@ -308,70 +304,12 @@ const getFunctionParameterNames = (
308
304
 
309
305
  if (param.type === 'Property') {
310
306
  switch (param.value.type) {
311
- case 'ArrayPattern': {
312
- return [
313
- /** @type {import('estree').Identifier} */
314
- (param.key).name,
315
- /** @type {import('estree').ArrayPattern} */ (
316
- param.value
317
- ).elements.map((prop, idx) => {
318
- return {
319
- name: idx,
320
- restElement: prop?.type === 'RestElement',
321
- };
322
- }),
323
- ];
324
- }
325
-
326
- case 'ObjectPattern': {
327
- return [
328
- /** @type {import('estree').Identifier} */ (param.key).name,
329
- /** @type {import('estree').ObjectPattern} */ (
330
- param.value
331
- ).properties.map((prop) => {
332
- return /** @type {string|[string, string[]]} */ (getParamName(prop, isProperty));
333
- }),
334
- ];
335
- }
336
-
337
- case 'AssignmentPattern': {
338
- switch (param.value.left.type) {
339
- case 'Identifier':
340
- // Default parameter
341
- if (checkDefaultObjects && param.value.right.type === 'ObjectExpression') {
342
- return [
343
- /** @type {import('estree').Identifier} */ (
344
- param.key
345
- ).name,
346
- /** @type {import('estree').AssignmentPattern} */ (
347
- param.value
348
- ).right.properties.map((prop) => {
349
- return /** @type {string} */ (getParamName(
350
- /** @type {import('estree').Property} */
351
- (prop),
352
- isProperty,
353
- ));
354
- }),
355
- ];
356
- }
357
-
358
- break;
359
- case 'ObjectPattern':
307
+ case 'ArrayPattern': {
360
308
  return [
361
- /** @type {import('estree').Identifier} */
362
- (param.key).name,
363
- /** @type {import('estree').ObjectPattern} */ (
364
- param.value.left
365
- ).properties.map((prop) => {
366
- return getParamName(prop, isProperty);
367
- }),
368
- ];
369
- case 'ArrayPattern':
370
- return [
371
- /** @type {import('estree').Identifier} */
309
+ /** @type {import('estree').Identifier} */
372
310
  (param.key).name,
373
311
  /** @type {import('estree').ArrayPattern} */ (
374
- param.value.left
312
+ param.value
375
313
  ).elements.map((prop, idx) => {
376
314
  return {
377
315
  name: idx,
@@ -380,26 +318,84 @@ const getFunctionParameterNames = (
380
318
  }),
381
319
  ];
382
320
  }
383
- }
321
+
322
+ case 'ObjectPattern': {
323
+ return [
324
+ /** @type {import('estree').Identifier} */ (param.key).name,
325
+ /** @type {import('estree').ObjectPattern} */ (
326
+ param.value
327
+ ).properties.map((prop) => {
328
+ return /** @type {string|[string, string[]]} */ (getParamName(prop, isProperty));
329
+ }),
330
+ ];
331
+ }
332
+
333
+ case 'AssignmentPattern': {
334
+ switch (param.value.left.type) {
335
+ case 'ArrayPattern':
336
+ return [
337
+ /** @type {import('estree').Identifier} */
338
+ (param.key).name,
339
+ /** @type {import('estree').ArrayPattern} */ (
340
+ param.value.left
341
+ ).elements.map((prop, idx) => {
342
+ return {
343
+ name: idx,
344
+ restElement: prop?.type === 'RestElement',
345
+ };
346
+ }),
347
+ ];
348
+ case 'Identifier':
349
+ // Default parameter
350
+ if (checkDefaultObjects && param.value.right.type === 'ObjectExpression') {
351
+ return [
352
+ /** @type {import('estree').Identifier} */ (
353
+ param.key
354
+ ).name,
355
+ /** @type {import('estree').AssignmentPattern} */ (
356
+ param.value
357
+ ).right.properties.map((prop) => {
358
+ return /** @type {string} */ (getParamName(
359
+ /** @type {import('estree').Property} */
360
+ (prop),
361
+ isProperty,
362
+ ));
363
+ }),
364
+ ];
365
+ }
366
+
367
+ break;
368
+ case 'ObjectPattern':
369
+ return [
370
+ /** @type {import('estree').Identifier} */
371
+ (param.key).name,
372
+ /** @type {import('estree').ObjectPattern} */ (
373
+ param.value.left
374
+ ).properties.map((prop) => {
375
+ return getParamName(prop, isProperty);
376
+ }),
377
+ ];
378
+ }
379
+ }
384
380
  }
385
381
 
386
382
  switch (param.key.type) {
387
- case 'Identifier':
388
- return param.key.name;
383
+ case 'Identifier':
384
+ return param.key.name;
389
385
 
390
- // The key of an object could also be a string or number
391
- case 'Literal':
386
+ // The key of an object could also be a string or number
387
+ case 'Literal':
392
388
  /* c8 ignore next 2 -- `raw` may not be present in all parsers */
393
- return /** @type {string} */ (param.key.raw ||
389
+ return /** @type {string} */ (param.key.raw ||
394
390
  param.key.value);
395
391
 
396
- // case 'MemberExpression':
397
- default:
392
+ // case 'MemberExpression':
393
+ default:
398
394
  // Todo: We should really create a structure (and a corresponding
399
395
  // option analogous to `checkRestProperty`) which allows for
400
396
  // (and optionally requires) dynamic properties to have a single
401
397
  // line of documentation
402
- return undefined;
398
+ return undefined;
403
399
  }
404
400
  }
405
401
 
@@ -429,7 +425,7 @@ const getFunctionParameterNames = (
429
425
  }
430
426
 
431
427
  if ([
432
- 'RestElement', 'ExperimentalRestProperty',
428
+ 'ExperimentalRestProperty', 'RestElement',
433
429
  ].includes(param.type)) {
434
430
  return {
435
431
  isRestProperty: isProperty,
@@ -437,9 +433,12 @@ const getFunctionParameterNames = (
437
433
  /** @type {import('@typescript-eslint/types').TSESTree.RestElement} */ (
438
434
  param
439
435
  // @ts-expect-error Ok
440
- ).argument).name ?? param?.argument?.elements?.map(({name}) => {
441
- return name;
442
- }),
436
+ ).argument).name ?? param?.argument?.elements?.map(({
437
+ // @ts-expect-error Ok
438
+ name,
439
+ }) => {
440
+ return name;
441
+ }),
443
442
  restElement: true,
444
443
  };
445
444
  }
@@ -526,32 +525,32 @@ const modeWarnSettings = WarnSettings();
526
525
  */
527
526
  const getTagNamesForMode = (mode, context) => {
528
527
  switch (mode) {
529
- case 'jsdoc':
530
- return jsdocTags;
531
- case 'typescript':
532
- return typeScriptTags;
533
- case 'closure': case 'permissive':
534
- return closureTags;
535
- default:
536
- if (!modeWarnSettings.hasBeenWarned(context, 'mode')) {
537
- context.report({
538
- loc: {
539
- end: {
540
- column: 1,
541
- line: 1,
528
+ case 'closure':
529
+ case 'permissive':
530
+ return closureTags;
531
+ case 'jsdoc':
532
+ return jsdocTags; case 'typescript':
533
+ return typeScriptTags;
534
+ default:
535
+ if (!modeWarnSettings.hasBeenWarned(context, 'mode')) {
536
+ context.report({
537
+ loc: {
538
+ end: {
539
+ column: 1,
540
+ line: 1,
541
+ },
542
+ start: {
543
+ column: 1,
544
+ line: 1,
545
+ },
542
546
  },
543
- start: {
544
- column: 1,
545
- line: 1,
546
- },
547
- },
548
- message: `Unrecognized value \`${mode}\` for \`settings.jsdoc.mode\`.`,
549
- });
550
- modeWarnSettings.markSettingAsWarned(context, 'mode');
551
- }
547
+ message: `Unrecognized value \`${mode}\` for \`settings.jsdoc.mode\`.`,
548
+ });
549
+ modeWarnSettings.markSettingAsWarned(context, 'mode');
550
+ }
552
551
 
553
- // We'll avoid breaking too many other rules
554
- return jsdocTags;
552
+ // We'll avoid breaking too many other rules
553
+ return jsdocTags;
555
554
  }
556
555
  };
557
556
 
@@ -561,44 +560,44 @@ const getTagNamesForMode = (mode, context) => {
561
560
  * @returns {string[]|string}
562
561
  */
563
562
  const getTagDescription = (tg, returnArray) => {
564
- /**
565
- * @type {string[]}
566
- */
567
- const descriptions = [];
568
- tg.source.some(({
569
- tokens: {
570
- end,
571
- lineEnd,
572
- postDelimiter,
573
- tag,
574
- postTag,
575
- name,
576
- type,
577
- description,
578
- },
579
- }) => {
580
- const desc = (
581
- tag && postTag ||
563
+ /**
564
+ * @type {string[]}
565
+ */
566
+ const descriptions = [];
567
+ tg.source.some(({
568
+ tokens: {
569
+ description,
570
+ end,
571
+ lineEnd,
572
+ name,
573
+ postDelimiter,
574
+ postTag,
575
+ tag,
576
+ type,
577
+ },
578
+ }) => {
579
+ const desc = (
580
+ tag && postTag ||
582
581
  !tag && !name && !type && postDelimiter || ''
583
582
 
584
- // Remove space
585
- ).slice(1) +
583
+ // Remove space
584
+ ).slice(1) +
586
585
  (description || '') + (lineEnd || '');
587
586
 
588
- if (end) {
589
- if (desc) {
590
- descriptions.push(desc);
591
- }
592
-
593
- return true;
587
+ if (end) {
588
+ if (desc) {
589
+ descriptions.push(desc);
594
590
  }
595
591
 
596
- descriptions.push(desc);
592
+ return true;
593
+ }
597
594
 
598
- return false;
599
- });
595
+ descriptions.push(desc);
600
596
 
601
- return returnArray ? descriptions : descriptions.join('\n');
597
+ return false;
598
+ });
599
+
600
+ return returnArray ? descriptions : descriptions.join('\n');
602
601
  };
603
602
 
604
603
  /**
@@ -621,10 +620,11 @@ const getPreferredTagNameSimple = (
621
620
  name,
622
621
  mode,
623
622
  tagPreference = {},
623
+ // eslint-disable-next-line unicorn/no-object-as-default-parameter -- Ok
624
624
  context = {
625
625
  report () {
626
626
  // No-op
627
- }
627
+ },
628
628
  },
629
629
  ) => {
630
630
  const prefValues = Object.values(tagPreference);
@@ -748,13 +748,14 @@ const getTags = (jsdoc, tagName) => {
748
748
  * }}
749
749
  */
750
750
  const getPreferredTagName = (jsdoc, {
751
+ allowObjectReturn = false,
752
+ context,
751
753
  tagName,
752
- context, mode,
753
- tagNamePreference,
754
+ defaultMessage = `Unexpected tag \`@${tagName}\``,
755
+ mode,
754
756
  report = () => {},
755
757
  skipReportingBlockedTag = false,
756
- allowObjectReturn = false,
757
- defaultMessage = `Unexpected tag \`@${tagName}\``,
758
+ tagNamePreference,
758
759
  }) => {
759
760
  const ret = getPreferredTagNameSimple(tagName, mode, tagNamePreference, context);
760
761
  const isObject = ret && typeof ret === 'object';
@@ -793,16 +794,21 @@ const getPreferredTagName = (jsdoc, {
793
794
  const forEachPreferredTag = (
794
795
  jsdoc, tagName, arrayHandler,
795
796
  {
796
- context, mode, report,
797
- tagNamePreference,
797
+ context,
798
+ mode,
799
+ report,
798
800
  skipReportingBlockedTag = false,
799
- } = {}
801
+ tagNamePreference,
802
+ } = {},
800
803
  ) => {
801
804
  const targetTagName = /** @type {string|false} */ (
802
805
  getPreferredTagName(jsdoc, {
806
+ context,
807
+ mode,
808
+ report,
803
809
  skipReportingBlockedTag,
804
810
  tagName,
805
- context, mode, report, tagNamePreference
811
+ tagNamePreference,
806
812
  })
807
813
  );
808
814
  if (!targetTagName ||
@@ -985,8 +991,8 @@ const overrideTagStructure = (structuredTags, tagMap = tagStructure) => {
985
991
  tag,
986
992
  {
987
993
  name,
988
- type,
989
994
  required = [],
995
+ type,
990
996
  },
991
997
  ] of Object.entries(structuredTags)) {
992
998
  const tagStruct = ensureMap(tagMap, tag);
@@ -1193,185 +1199,191 @@ const hasNonFunctionYield = (node, checkYieldReturnValue) => {
1193
1199
  }
1194
1200
 
1195
1201
  switch (node.type) {
1196
- case 'BlockStatement': {
1197
- return node.body.some((bodyNode) => {
1198
- return ![
1199
- 'ArrowFunctionExpression',
1200
- 'FunctionDeclaration',
1201
- 'FunctionExpression',
1202
- ].includes(bodyNode.type) && hasNonFunctionYield(
1203
- bodyNode, checkYieldReturnValue,
1204
- );
1205
- });
1206
- }
1202
+ case 'ArrayExpression':
1207
1203
 
1208
- /* c8 ignore next 2 -- In Babel? */
1209
- // @ts-expect-error In Babel?
1210
- case 'OptionalCallExpression':
1211
- case 'CallExpression':
1212
- return node.arguments.some((element) => {
1213
- return hasNonFunctionYield(element, checkYieldReturnValue);
1214
- });
1215
- case 'ChainExpression':
1216
- case 'ExpressionStatement': {
1217
- return hasNonFunctionYield(node.expression, checkYieldReturnValue);
1218
- }
1204
+ case 'ArrayPattern':
1205
+ return node.elements.some((element) => {
1206
+ return hasNonFunctionYield(element, checkYieldReturnValue);
1207
+ });
1208
+ case 'AssignmentExpression':
1209
+ case 'BinaryExpression':
1210
+ case 'LogicalExpression': {
1211
+ return hasNonFunctionYield(node.left, checkYieldReturnValue) ||
1212
+ hasNonFunctionYield(node.right, checkYieldReturnValue);
1213
+ }
1219
1214
 
1220
- case 'LabeledStatement':
1221
- case 'WhileStatement':
1222
- case 'DoWhileStatement':
1223
- case 'ForStatement':
1224
- case 'ForInStatement':
1225
- case 'ForOfStatement':
1226
- case 'WithStatement': {
1227
- return hasNonFunctionYield(node.body, checkYieldReturnValue);
1228
- }
1215
+ case 'AssignmentPattern':
1216
+ return hasNonFunctionYield(node.right, checkYieldReturnValue);
1217
+ case 'BlockStatement': {
1218
+ return node.body.some((bodyNode) => {
1219
+ return ![
1220
+ 'ArrowFunctionExpression',
1221
+ 'FunctionDeclaration',
1222
+ 'FunctionExpression',
1223
+ ].includes(bodyNode.type) && hasNonFunctionYield(
1224
+ bodyNode, checkYieldReturnValue,
1225
+ );
1226
+ });
1227
+ }
1229
1228
 
1230
- case 'ConditionalExpression':
1231
- case 'IfStatement': {
1232
- return hasNonFunctionYield(node.test, checkYieldReturnValue) ||
1233
- hasNonFunctionYield(node.consequent, checkYieldReturnValue) ||
1234
- hasNonFunctionYield(node.alternate, checkYieldReturnValue);
1235
- }
1229
+ /* c8 ignore next 2 -- In Babel? */
1230
+ case 'CallExpression':
1231
+ // @ts-expect-error In Babel?
1232
+ case 'OptionalCallExpression':
1233
+ return node.arguments.some((element) => {
1234
+ return hasNonFunctionYield(element, checkYieldReturnValue);
1235
+ });
1236
+ case 'ChainExpression':
1237
+ case 'ExpressionStatement': {
1238
+ return hasNonFunctionYield(node.expression, checkYieldReturnValue);
1239
+ }
1236
1240
 
1237
- case 'TryStatement': {
1238
- return hasNonFunctionYield(node.block, checkYieldReturnValue) ||
1239
- hasNonFunctionYield(
1240
- node.handler && node.handler.body, checkYieldReturnValue,
1241
- ) ||
1242
- hasNonFunctionYield(
1243
- /** @type {import('@typescript-eslint/types').TSESTree.BlockStatement} */
1244
- (node.finalizer),
1245
- checkYieldReturnValue,
1246
- );
1247
- }
1241
+ /* c8 ignore next 2 -- In Babel? */
1242
+ // @ts-expect-error In Babel?
1243
+ case 'ClassProperty':
1248
1244
 
1249
- case 'SwitchStatement': {
1250
- return node.cases.some(
1251
- (someCase) => {
1252
- return someCase.consequent.some((nde) => {
1253
- return hasNonFunctionYield(nde, checkYieldReturnValue);
1254
- });
1255
- },
1256
- );
1257
- }
1245
+ /* c8 ignore next 2 -- In Babel? */
1246
+ // @ts-expect-error In Babel?
1247
+ case 'ObjectProperty':
1248
+ /* c8 ignore next 2 -- In Babel? */
1249
+ case 'Property':
1258
1250
 
1259
- case 'ArrayPattern':
1260
- case 'ArrayExpression':
1261
- return node.elements.some((element) => {
1262
- return hasNonFunctionYield(element, checkYieldReturnValue);
1263
- });
1264
- case 'AssignmentPattern':
1265
- return hasNonFunctionYield(node.right, checkYieldReturnValue);
1251
+ case 'PropertyDefinition':
1252
+ return node.computed && hasNonFunctionYield(node.key, checkYieldReturnValue) ||
1253
+ hasNonFunctionYield(node.value, checkYieldReturnValue);
1266
1254
 
1267
- case 'VariableDeclaration': {
1268
- return node.declarations.some((nde) => {
1269
- return hasNonFunctionYield(nde, checkYieldReturnValue);
1270
- });
1271
- }
1255
+ case 'ConditionalExpression':
1272
1256
 
1273
- case 'VariableDeclarator': {
1274
- return hasNonFunctionYield(node.id, checkYieldReturnValue) ||
1275
- hasNonFunctionYield(node.init, checkYieldReturnValue);
1276
- }
1257
+ case 'IfStatement': {
1258
+ return hasNonFunctionYield(node.test, checkYieldReturnValue) ||
1259
+ hasNonFunctionYield(node.consequent, checkYieldReturnValue) ||
1260
+ hasNonFunctionYield(node.alternate, checkYieldReturnValue);
1261
+ }
1277
1262
 
1278
- case 'AssignmentExpression':
1279
- case 'BinaryExpression':
1280
- case 'LogicalExpression': {
1281
- return hasNonFunctionYield(node.left, checkYieldReturnValue) ||
1282
- hasNonFunctionYield(node.right, checkYieldReturnValue);
1283
- }
1263
+ case 'DoWhileStatement':
1264
+ case 'ForInStatement':
1284
1265
 
1285
- // Comma
1286
- case 'SequenceExpression':
1287
- case 'TemplateLiteral':
1288
- return node.expressions.some((subExpression) => {
1289
- return hasNonFunctionYield(subExpression, checkYieldReturnValue);
1290
- });
1266
+ case 'ForOfStatement':
1291
1267
 
1292
- case 'ObjectPattern':
1293
- case 'ObjectExpression':
1294
- return node.properties.some((property) => {
1295
- return hasNonFunctionYield(property, checkYieldReturnValue);
1296
- });
1268
+ case 'ForStatement':
1297
1269
 
1298
- /* c8 ignore next -- In Babel? */
1299
- case 'PropertyDefinition':
1300
- /* eslint-disable no-fallthrough */
1301
- /* c8 ignore next 2 -- In Babel? */
1302
- // @ts-expect-error In Babel?
1303
- case 'ObjectProperty':
1304
- /* c8 ignore next 2 -- In Babel? */
1305
- // @ts-expect-error In Babel?
1306
- case 'ClassProperty':
1307
- case 'Property':
1308
- /* eslint-enable no-fallthrough */
1309
- return node.computed && hasNonFunctionYield(node.key, checkYieldReturnValue) ||
1310
- hasNonFunctionYield(node.value, checkYieldReturnValue);
1311
- /* c8 ignore next 2 -- In Babel? */
1312
- // @ts-expect-error In Babel?
1313
- case 'ObjectMethod':
1270
+ case 'LabeledStatement':
1271
+ case 'WhileStatement':
1272
+ case 'WithStatement': {
1273
+ return hasNonFunctionYield(node.body, checkYieldReturnValue);
1274
+ }
1275
+
1276
+ /* c8 ignore next 2 -- In Babel? */
1277
+ // @ts-expect-error In Babel?
1278
+ case 'Import':
1279
+ case 'ImportExpression':
1280
+ return hasNonFunctionYield(node.source, checkYieldReturnValue);
1281
+
1282
+ // ?.
1283
+ /* c8 ignore next 2 -- In Babel? */
1284
+ case 'MemberExpression':
1285
+ // @ts-expect-error In Babel?
1286
+ case 'OptionalMemberExpression':
1287
+ return hasNonFunctionYield(node.object, checkYieldReturnValue) ||
1288
+ hasNonFunctionYield(node.property, checkYieldReturnValue);
1289
+
1290
+ case 'ObjectExpression':
1291
+ /* eslint-disable no-fallthrough */
1292
+ case 'ObjectPattern':
1293
+ /* eslint-enable no-fallthrough */
1294
+ return node.properties.some((property) => {
1295
+ return hasNonFunctionYield(property, checkYieldReturnValue);
1296
+ });
1297
+ /* c8 ignore next 2 -- In Babel? */
1298
+ // @ts-expect-error In Babel?
1299
+ case 'ObjectMethod':
1314
1300
  /* c8 ignore next 6 -- In Babel? */
1315
1301
  // @ts-expect-error In Babel?
1316
- return node.computed && hasNonFunctionYield(node.key, checkYieldReturnValue) ||
1302
+ return node.computed && hasNonFunctionYield(node.key, checkYieldReturnValue) ||
1317
1303
  // @ts-expect-error In Babel?
1318
1304
  node.arguments.some((nde) => {
1319
1305
  return hasNonFunctionYield(nde, checkYieldReturnValue);
1320
1306
  });
1307
+ case 'ReturnStatement': {
1308
+ if (node.argument === null) {
1309
+ return false;
1310
+ }
1321
1311
 
1322
- case 'SpreadElement':
1323
- case 'UnaryExpression':
1324
- return hasNonFunctionYield(node.argument, checkYieldReturnValue);
1312
+ return hasNonFunctionYield(node.argument, checkYieldReturnValue);
1313
+ }
1325
1314
 
1326
- case 'TaggedTemplateExpression':
1327
- return hasNonFunctionYield(node.quasi, checkYieldReturnValue);
1315
+ // Comma
1316
+ case 'SequenceExpression':
1328
1317
 
1329
- // ?.
1330
- /* c8 ignore next 2 -- In Babel? */
1331
- // @ts-expect-error In Babel?
1332
- case 'OptionalMemberExpression':
1333
- case 'MemberExpression':
1334
- return hasNonFunctionYield(node.object, checkYieldReturnValue) ||
1335
- hasNonFunctionYield(node.property, checkYieldReturnValue);
1318
+ case 'TemplateLiteral':
1319
+ return node.expressions.some((subExpression) => {
1320
+ return hasNonFunctionYield(subExpression, checkYieldReturnValue);
1321
+ });
1322
+ case 'SpreadElement':
1336
1323
 
1337
- /* c8 ignore next 2 -- In Babel? */
1338
- // @ts-expect-error In Babel?
1339
- case 'Import':
1340
- case 'ImportExpression':
1341
- return hasNonFunctionYield(node.source, checkYieldReturnValue);
1324
+ case 'UnaryExpression':
1325
+ return hasNonFunctionYield(node.argument, checkYieldReturnValue);
1342
1326
 
1343
- case 'ReturnStatement': {
1344
- if (node.argument === null) {
1345
- return false;
1327
+ case 'SwitchStatement': {
1328
+ return node.cases.some(
1329
+ (someCase) => {
1330
+ return someCase.consequent.some((nde) => {
1331
+ return hasNonFunctionYield(nde, checkYieldReturnValue);
1332
+ });
1333
+ },
1334
+ );
1346
1335
  }
1347
1336
 
1348
- return hasNonFunctionYield(node.argument, checkYieldReturnValue);
1349
- }
1337
+ case 'TaggedTemplateExpression':
1338
+ return hasNonFunctionYield(node.quasi, checkYieldReturnValue);
1339
+
1340
+ case 'TryStatement': {
1341
+ return hasNonFunctionYield(node.block, checkYieldReturnValue) ||
1342
+ hasNonFunctionYield(
1343
+ node.handler && node.handler.body, checkYieldReturnValue,
1344
+ ) ||
1345
+ hasNonFunctionYield(
1346
+ /** @type {import('@typescript-eslint/types').TSESTree.BlockStatement} */
1347
+ (node.finalizer),
1348
+ checkYieldReturnValue,
1349
+ );
1350
+ }
1351
+
1352
+ case 'VariableDeclaration': {
1353
+ return node.declarations.some((nde) => {
1354
+ return hasNonFunctionYield(nde, checkYieldReturnValue);
1355
+ });
1356
+ }
1357
+
1358
+ case 'VariableDeclarator': {
1359
+ return hasNonFunctionYield(node.id, checkYieldReturnValue) ||
1360
+ hasNonFunctionYield(node.init, checkYieldReturnValue);
1361
+ }
1350
1362
 
1351
- case 'YieldExpression': {
1352
- if (checkYieldReturnValue) {
1353
- if (
1363
+ case 'YieldExpression': {
1364
+ if (checkYieldReturnValue) {
1365
+ if (
1354
1366
  /** @type {import('eslint').Rule.Node} */ (
1355
- node
1356
- ).parent.type === 'VariableDeclarator'
1357
- ) {
1358
- return true;
1367
+ node
1368
+ ).parent.type === 'VariableDeclarator'
1369
+ ) {
1370
+ return true;
1371
+ }
1372
+
1373
+ return false;
1359
1374
  }
1360
1375
 
1361
- return false;
1376
+ // void return does not count.
1377
+ if (node.argument === null) {
1378
+ return false;
1379
+ }
1380
+
1381
+ return true;
1362
1382
  }
1363
1383
 
1364
- // void return does not count.
1365
- if (node.argument === null) {
1384
+ default: {
1366
1385
  return false;
1367
1386
  }
1368
-
1369
- return true;
1370
- }
1371
-
1372
- default: {
1373
- return false;
1374
- }
1375
1387
  }
1376
1388
  };
1377
1389
 
@@ -1411,55 +1423,55 @@ const hasThrowValue = (node, innerFunction) => {
1411
1423
  // throws, but we're treating functions atomically rather than trying to
1412
1424
  // follow them
1413
1425
  switch (node.type) {
1414
- case 'FunctionExpression':
1415
- case 'FunctionDeclaration':
1416
- case 'ArrowFunctionExpression': {
1417
- return !innerFunction && !node.async && hasThrowValue(node.body, true);
1418
- }
1426
+ case 'ArrowFunctionExpression':
1427
+ case 'FunctionDeclaration':
1428
+ case 'FunctionExpression': {
1429
+ return !innerFunction && !node.async && hasThrowValue(node.body, true);
1430
+ }
1419
1431
 
1420
- case 'BlockStatement': {
1421
- return node.body.some((bodyNode) => {
1422
- return bodyNode.type !== 'FunctionDeclaration' && hasThrowValue(bodyNode);
1423
- });
1424
- }
1432
+ case 'BlockStatement': {
1433
+ return node.body.some((bodyNode) => {
1434
+ return bodyNode.type !== 'FunctionDeclaration' && hasThrowValue(bodyNode);
1435
+ });
1436
+ }
1425
1437
 
1426
- case 'LabeledStatement':
1427
- case 'WhileStatement':
1428
- case 'DoWhileStatement':
1429
- case 'ForStatement':
1430
- case 'ForInStatement':
1431
- case 'ForOfStatement':
1432
- case 'WithStatement': {
1433
- return hasThrowValue(node.body);
1434
- }
1438
+ case 'DoWhileStatement':
1439
+ case 'ForInStatement':
1440
+ case 'ForOfStatement':
1441
+ case 'ForStatement':
1442
+ case 'LabeledStatement':
1443
+ case 'WhileStatement':
1444
+ case 'WithStatement': {
1445
+ return hasThrowValue(node.body);
1446
+ }
1435
1447
 
1436
- case 'IfStatement': {
1437
- return hasThrowValue(node.consequent) || hasThrowValue(node.alternate);
1438
- }
1448
+ case 'IfStatement': {
1449
+ return hasThrowValue(node.consequent) || hasThrowValue(node.alternate);
1450
+ }
1439
1451
 
1440
- // We only consider it to throw an error if the catch or finally blocks throw an error.
1441
- case 'TryStatement': {
1442
- return hasThrowValue(node.handler && node.handler.body) ||
1443
- hasThrowValue(node.finalizer);
1444
- }
1452
+ case 'SwitchStatement': {
1453
+ return node.cases.some(
1454
+ (someCase) => {
1455
+ return someCase.consequent.some((nde) => {
1456
+ return hasThrowValue(nde);
1457
+ });
1458
+ },
1459
+ );
1460
+ }
1445
1461
 
1446
- case 'SwitchStatement': {
1447
- return node.cases.some(
1448
- (someCase) => {
1449
- return someCase.consequent.some((nde) => {
1450
- return hasThrowValue(nde);
1451
- });
1452
- },
1453
- );
1454
- }
1462
+ case 'ThrowStatement': {
1463
+ return true;
1464
+ }
1455
1465
 
1456
- case 'ThrowStatement': {
1457
- return true;
1458
- }
1466
+ // We only consider it to throw an error if the catch or finally blocks throw an error.
1467
+ case 'TryStatement': {
1468
+ return hasThrowValue(node.handler && node.handler.body) ||
1469
+ hasThrowValue(node.finalizer);
1470
+ }
1459
1471
 
1460
- default: {
1461
- return false;
1462
- }
1472
+ default: {
1473
+ return false;
1474
+ }
1463
1475
  }
1464
1476
  };
1465
1477
 
@@ -1584,11 +1596,11 @@ const getContextObject = (contexts, checkJsdoc, handler) => {
1584
1596
  };
1585
1597
 
1586
1598
  const tagsWithNamesAndDescriptions = new Set([
1587
- 'param', 'arg', 'argument', 'property', 'prop',
1588
- 'template',
1599
+ 'arg', 'argument', 'param', 'prop', 'property',
1600
+ 'return',
1589
1601
 
1590
1602
  // These two are parsed by our custom parser as though having a `name`
1591
- 'returns', 'return',
1603
+ 'returns', 'template',
1592
1604
  ]);
1593
1605
 
1594
1606
  /**
@@ -1685,9 +1697,9 @@ const isSetter = (node) => {
1685
1697
  */
1686
1698
  const hasAccessorPair = (node) => {
1687
1699
  const {
1688
- type,
1689
- kind: sourceKind,
1690
1700
  key,
1701
+ kind: sourceKind,
1702
+ type,
1691
1703
  } =
1692
1704
  /**
1693
1705
  * @type {import('@typescript-eslint/types').TSESTree.MethodDefinition|
@@ -1712,8 +1724,8 @@ const hasAccessorPair = (node) => {
1712
1724
  return (
1713
1725
  sibling.some((child) => {
1714
1726
  const {
1715
- kind,
1716
1727
  key: ky,
1728
+ kind,
1717
1729
  } = /**
1718
1730
  * @type {import('@typescript-eslint/types').TSESTree.MethodDefinition|
1719
1731
  * import('@typescript-eslint/types').TSESTree.Property}
@@ -1853,10 +1865,10 @@ export {
1853
1865
  getTagStructureForMode,
1854
1866
  hasATag,
1855
1867
  hasParams,
1856
- hasReturnValue,
1868
+
1857
1869
  hasTag,
1858
1870
  hasThrowValue,
1859
- hasValueOrExecutorHasNonEmptyResolveValue,
1871
+
1860
1872
  hasYieldValue,
1861
1873
  isConstructor,
1862
1874
  isGetter,
@@ -1878,3 +1890,7 @@ export {
1878
1890
  tagMustHaveNamePosition,
1879
1891
  tagMustHaveTypePosition,
1880
1892
  };
1893
+ export {
1894
+ hasReturnValue,
1895
+ hasValueOrExecutorHasNonEmptyResolveValue,
1896
+ } from './utils/hasReturnValue.js';