{"version":3,"sources":["../../src/rules/requireYields.js"],"names":["canSkip","utils","hasATag","avoidDocs","checkTagName","report","tagName","preferredTagName","getPreferredTagName","tags","getTags","length","tag","missingTag","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","default"],"mappings":";;;;;;;AAAA;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,OAAO,GAAIC,KAAD,IAAW;AACzB,SAAOA,KAAK,CAACC,OAAN,CAAc,CACnB;AACA;AACA;AACA;AACA;AACA,YANmB,EAOnB,SAPmB,EASnB;AACA;AACA,SAXmB,EAYnB,aAZmB,EAcnB;AACA;AACA,QAhBmB,EAkBnB;AACA,aAnBmB,CAAd,KAqBLD,KAAK,CAACE,SAAN,EArBF;AAsBD,CAvBD;;AAyBA,MAAMC,YAAY,GAAG,CAACH,KAAD,EAAQI,MAAR,EAAgBC,OAAhB,KAA4B;AAC/C,QAAMC,gBAAgB,GAAGN,KAAK,CAACO,mBAAN,CAA0B;AAACF,IAAAA;AAAD,GAA1B,CAAzB;;AACA,MAAI,CAACC,gBAAL,EAAuB;AACrB,WAAO,EAAP;AACD;;AAED,QAAME,IAAI,GAAGR,KAAK,CAACS,OAAN,CAAcH,gBAAd,CAAb;;AAEA,MAAIE,IAAI,CAACE,MAAL,GAAc,CAAlB,EAAqB;AACnBN,IAAAA,MAAM,CAAE,wBAAuBE,gBAAiB,eAA1C,CAAN;AACD,GAV8C,CAY/C;;;AACA,QAAM,CAACK,GAAD,IAAQH,IAAd;AACA,QAAMI,UAAU,GAAG,OAAOD,GAAP,KAAe,WAAf,IAA8BA,GAAG,KAAK,IAAzD;AAEA,SAAO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I,EAAE;AApBE,SADA;AAuBVE,QAAAA,UAAU,EAAE;AACVJ,UAAAA,KAAK,EAAE;AACLE,YAAAA,IAAI,EAAE;AADD,WADG;AAIVA,UAAAA,IAAI,EAAE;AAJI,SAvBF;AA6BV3B,QAAAA,gBAAgB,EAAE;AAChB8B,UAAAA,OAAO,EAAE,KADO;AAEhBH,UAAAA,IAAI,EAAE;AAFU,SA7BR;AAiCV1B,QAAAA,kBAAkB,EAAE;AAClB6B,UAAAA,OAAO,EAAE,KADS;AAElBH,UAAAA,IAAI,EAAE;AAFY,SAjCV;AAqCV7B,QAAAA,IAAI,EAAE;AACJgC,UAAAA,OAAO,EAAE,KADL;AAEJH,UAAAA,IAAI,EAAE;AAFF,SArCI;AAyCV5B,QAAAA,oBAAoB,EAAE;AACpB+B,UAAAA,OAAO,EAAE,KADW;AAEpBH,UAAAA,IAAI,EAAE;AAFc,SAzCZ;AA6CVzB,QAAAA,gBAAgB,EAAE;AAChB4B,UAAAA,OAAO,EAAE,IADO;AAEhBH,UAAAA,IAAI,EAAE;AAFU;AA7CR,OAFd;AAoDEA,MAAAA,IAAI,EAAE;AApDR,KADM,CALJ;AA6DJA,IAAAA,IAAI,EAAE;AA7DF;AAFL,CA9EY,C","sourcesContent":["import iterateJsdoc from '../iterateJsdoc';\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 *\n * @param {*} utils\n * a reference to the utils which are used to probe if a tag is present or not.\n * @returns {boolean}\n * 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\nconst checkTagName = (utils, report, tagName) => {\n const preferredTagName = utils.getPreferredTagName({tagName});\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 [tag] = tags;\n const missingTag = typeof tag === 'undefined' || tag === null;\n\n return [preferredTagName, missingTag];\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 [preferredYieldTagName, missingYieldTag] = 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 [preferredNextTagName, missingNextTag] = 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#eslint-plugin-jsdoc-rules-require-yields',\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"],"file":"requireYields.js"}