{"version":3,"file":"requireYields.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","canSkip","utils","hasATag","avoidDocs","checkTagName","report","tagName","preferredTagName","getPreferredTagName","tags","getTags","length","tag","missingTag","_default","exports","iterateJsdoc","context","forceRequireNext","forceRequireYields","next","nextWithGeneratorTag","withGeneratorTag","options","iteratingFunction","isIteratingFunction","preferredYieldTagName","missingYieldTag","shouldReportYields","hasTag","isGenerator","hasYieldValue","preferredNextTagName","missingNextTag","shouldReportNext","hasYieldReturnValue","contextDefaults","meta","docs","description","url","schema","additionalProperties","properties","contexts","items","anyOf","type","comment","exemptedBy","module"],"sources":["../../src/rules/requireYields.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\n/**\n * We can skip checking for a yield value, in case the documentation is inherited\n * or the method has a constructor or abstract tag.\n *\n * In either of these cases the yield value is optional or not defined.\n * @param {import('../iterateJsdoc.js').Utils} utils a reference to the utils which are used to probe if a tag is present or not.\n * @returns {boolean} true in case deep checking can be skipped; otherwise false.\n */\nconst canSkip = (utils) => {\n  return utils.hasATag([\n    // inheritdoc implies that all documentation is inherited\n    // see https://jsdoc.app/tags-inheritdoc.html\n    //\n    // Abstract methods are by definition incomplete,\n    // so it is not an error if it declares a yield value but does not implement it.\n    'abstract',\n    'virtual',\n\n    // Constructors do not have a yield value\n    // so we can bail out here, too.\n    'class',\n    'constructor',\n\n    // Yield (and any `next`) type is specified accompanying the targeted\n    //   @type\n    'type',\n\n    // This seems to imply a class as well\n    'interface',\n  ]) ||\n    utils.avoidDocs();\n};\n\n/**\n * @param {import('../iterateJsdoc.js').Utils} utils\n * @param {import('../iterateJsdoc.js').Report} report\n * @param {string} tagName\n * @returns {[preferredTagName?: string, missingTag?: boolean]}\n */\nconst checkTagName = (utils, report, tagName) => {\n  const preferredTagName = /** @type {string} */ (utils.getPreferredTagName({\n    tagName,\n  }));\n  if (!preferredTagName) {\n    return [];\n  }\n\n  const tags = utils.getTags(preferredTagName);\n\n  if (tags.length > 1) {\n    report(`Found more than one @${preferredTagName} declaration.`);\n  }\n\n  // In case the code yields something, we expect a yields value in JSDoc.\n  const [\n    tag,\n  ] = tags;\n  const missingTag = typeof tag === 'undefined' || tag === null;\n\n  return [\n    preferredTagName, missingTag,\n  ];\n};\n\nexport default iterateJsdoc(({\n  context,\n  report,\n  utils,\n}) => {\n  const {\n    forceRequireNext = false,\n    forceRequireYields = false,\n    next = false,\n    nextWithGeneratorTag = false,\n    withGeneratorTag = true,\n  } = context.options[0] || {};\n\n  // A preflight check. We do not need to run a deep check\n  // in case the @yield comment is optional or undefined.\n  if (canSkip(utils)) {\n    return;\n  }\n\n  const iteratingFunction = utils.isIteratingFunction();\n\n  const [\n    preferredYieldTagName,\n    missingYieldTag,\n  ] = checkTagName(\n    utils, report, 'yields',\n  );\n  if (preferredYieldTagName) {\n    const shouldReportYields = () => {\n      if (!missingYieldTag) {\n        return false;\n      }\n\n      if (\n        withGeneratorTag && utils.hasTag('generator') ||\n        forceRequireYields && iteratingFunction && utils.isGenerator()\n      ) {\n        return true;\n      }\n\n      return iteratingFunction && utils.isGenerator() && utils.hasYieldValue();\n    };\n\n    if (shouldReportYields()) {\n      report(`Missing JSDoc @${preferredYieldTagName} declaration.`);\n    }\n  }\n\n  if (next || nextWithGeneratorTag || forceRequireNext) {\n    const [\n      preferredNextTagName,\n      missingNextTag,\n    ] = checkTagName(\n      utils, report, 'next',\n    );\n    if (!preferredNextTagName) {\n      return;\n    }\n\n    const shouldReportNext = () => {\n      if (!missingNextTag) {\n        return false;\n      }\n\n      if (\n        nextWithGeneratorTag && utils.hasTag('generator')) {\n        return true;\n      }\n\n      if (\n        !next && !forceRequireNext ||\n        !iteratingFunction ||\n        !utils.isGenerator()\n      ) {\n        return false;\n      }\n\n      return forceRequireNext || utils.hasYieldReturnValue();\n    };\n\n    if (shouldReportNext()) {\n      report(`Missing JSDoc @${preferredNextTagName} declaration.`);\n    }\n  }\n}, {\n  contextDefaults: true,\n  meta: {\n    docs: {\n      description: 'Requires yields are documented with `@yields` tags.',\n      url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-yields.md#repos-sticky-header',\n    },\n    schema: [\n      {\n        additionalProperties: false,\n        properties: {\n          contexts: {\n            description: `Set this to an array of strings representing the AST context\n(or objects with optional \\`context\\` and \\`comment\\` properties) where you wish\nthe rule to be applied.\n\n\\`context\\` defaults to \\`any\\` and \\`comment\\` defaults to no specific comment context.\n\nOverrides the default contexts (\\`ArrowFunctionExpression\\`, \\`FunctionDeclaration\\`,\n\\`FunctionExpression\\`). Set to \\`\"any\"\\` if you want\nthe rule to apply to any JSDoc block throughout your files (as is necessary\nfor finding function blocks not attached to a function declaration or\nexpression, i.e., \\`@callback\\` or \\`@function\\` (or its aliases \\`@func\\` or\n\\`@method\\`) (including those associated with an \\`@interface\\`). This\nrule will only apply on non-default contexts when there is such a tag\npresent and the \\`forceRequireYields\\` option is set or if the\n\\`withGeneratorTag\\` option is set with a present \\`@generator\\` tag\n(since we are not checking against the actual \\`yield\\` values in these\ncases).`,\n            items: {\n              anyOf: [\n                {\n                  type: 'string',\n                },\n                {\n                  additionalProperties: false,\n                  properties: {\n                    comment: {\n                      type: 'string',\n                    },\n                    context: {\n                      type: 'string',\n                    },\n                  },\n                  type: 'object',\n                },\n              ],\n            },\n            type: 'array',\n          },\n          exemptedBy: {\n            description: `Array of tags (e.g., \\`['type']\\`) whose presence on the\ndocument block avoids the need for a \\`@yields\\`. Defaults to an array\nwith \\`inheritdoc\\`. If you set this array, it will overwrite the default,\nso be sure to add back \\`inheritdoc\\` if you wish its presence to cause\nexemption of the rule.`,\n            items: {\n              type: 'string',\n            },\n            type: 'array',\n          },\n          forceRequireNext: {\n            default: false,\n            description: `Set to \\`true\\` to always insist on\n\\`@next\\` documentation even if there are no \\`yield\\` statements in the\nfunction or none return values. May be desired to flag that a project is\naware of the expected yield return being \\`undefined\\`. Defaults to \\`false\\`.`,\n            type: 'boolean',\n          },\n          forceRequireYields: {\n            default: false,\n            description: `Set to \\`true\\` to always insist on\n\\`@yields\\` documentation for generators even if there are only\nexpressionless \\`yield\\` statements in the function. May be desired to flag\nthat a project is aware of an \\`undefined\\`/\\`void\\` yield. Defaults to\n\\`false\\`.`,\n            type: 'boolean',\n          },\n          next: {\n            default: false,\n            description: `If \\`true\\`, this option will insist that any use of a \\`yield\\` return\nvalue (e.g., \\`const rv = yield;\\` or \\`const rv = yield value;\\`) has a\n(non-standard) \\`@next\\` tag (in addition to any \\`@yields\\` tag) so as to be\nable to document the type expected to be supplied into the iterator\n(the \\`Generator\\` iterator that is returned by the call to the generator\nfunction) to the iterator (e.g., \\`it.next(value)\\`). The tag will not be\nexpected if the generator function body merely has plain \\`yield;\\` or\n\\`yield value;\\` statements without returning the values. Defaults to\n\\`false\\`.`,\n            type: 'boolean',\n          },\n          nextWithGeneratorTag: {\n            default: false,\n            description: `If a \\`@generator\\` tag is present on a block, require\n(non-standard ) \\`@next\\` (see \\`next\\` option). This will require using \\`void\\`\nor \\`undefined\\` in cases where generators do not use the \\`next()\\`-supplied\nincoming \\`yield\\`-returned value. Defaults to \\`false\\`. See \\`contexts\\` to\n\\`any\\` if you want to catch \\`@generator\\` with \\`@callback\\` or such not\nattached to a function.`,\n            type: 'boolean',\n          },\n          withGeneratorTag: {\n            default: true,\n            description: `If a \\`@generator\\` tag is present on a block, require\n\\`@yields\\`/\\`@yield\\`. Defaults to \\`true\\`. See \\`contexts\\` to \\`any\\` if you want\nto catch \\`@generator\\` with \\`@callback\\` or such not attached to a function.`,\n            type: 'boolean',\n          },\n        },\n        type: 'object',\n      },\n    ],\n    type: 'suggestion',\n  },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA8C,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE9C;AACA;AACA;AACA;AACA;AACA;AACA;AAC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