{"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","next","nextWithGeneratorTag","forceRequireNext","forceRequireYields","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  report,\n  utils,\n  context,\n}) => {\n  const {\n    next = false,\n    nextWithGeneratorTag = false,\n    forceRequireNext = false,\n    forceRequireYields = 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.',\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            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            items: {\n              type: 'string',\n            },\n            type: 'array',\n          },\n          forceRequireNext: {\n            default: false,\n            type: 'boolean',\n          },\n          forceRequireYields: {\n            default: false,\n            type: 'boolean',\n          },\n          next: {\n            default: false,\n            type: 'boolean',\n          },\n          nextWithGeneratorTag: {\n            default: false,\n            type: 'boolean',\n          },\n          withGeneratorTag: {\n            default: true,\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;AACA;AACA,MAAMG,OAAO,GAAIC,KAAK,IAAK;EACzB,OAAOA,KAAK,CAACC,OAAO,CAAC;EACnB;EACA;EACA;EACA;EACA;EACA,UAAU,EACV,SAAS;EAET;EACA;EACA,OAAO,EACP,aAAa;EAEb;EACA;EACA,MAAM;EAEN;EACA,WAAW,CACZ,CAAC,IACAD,KAAK,CAACE,SAAS,CAAC,CAAC;AACrB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAY,GAAGA,CAACH,KAAK,EAAEI,MAAM,EAAEC,OAAO,KAAK;EAC/C,MAAMC,gBAAgB,GAAG,qBAAuBN,KAAK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