{"version":3,"file":"requireReturns.cjs","names":["_exportParser","_interopRequireDefault","require","_iterateJsdoc","e","__esModule","default","canSkip","utils","hasATag","avoidDocs","_default","exports","iterateJsdoc","context","info","comment","node","report","settings","contexts","enableFixer","forceRequireReturn","forceReturnsWithAsync","publicOnly","options","forceRequireReturnContext","foundContext","findContext","tagName","getPreferredTagName","tags","getTags","length","iteratingFunction","isIteratingFunction","tag","missingReturnTag","shouldReport","opt","ancestorsOnly","Boolean","esm","initModuleExports","cjs","initWindow","window","sourceCode","getSourceCode","exported","exportParser","isUncommentedExport","isVirtualFunction","isAsync","hasTag","hasValueOrExecutorHasNonEmptyResolveValue","reportJSDoc","addTag","contextDefaults","meta","docs","description","url","fixable","schema","additionalProperties","properties","checkConstructors","type","checkGetters","items","anyOf","exemptedBy","oneOf","module"],"sources":["../../src/rules/requireReturns.js"],"sourcesContent":["import exportParser from '../exportParser.js';\nimport iterateJsdoc from '../iterateJsdoc.js';\n\n/**\n * We can skip checking for a return value, in case the documentation is inherited\n * or the method is either a constructor or an abstract method.\n *\n * In either of these cases the return value is optional or not defined.\n * @param {import('../iterateJsdoc.js').Utils} 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 return value but does not implement it.\n    'abstract',\n    'virtual',\n\n    // Constructors do not have a return value by definition (https://jsdoc.app/tags-class.html)\n    // So we can bail out here, too.\n    'class',\n    'constructor',\n\n    // Return type is specified by type in @type\n    'type',\n\n    // This seems to imply a class as well\n    'interface',\n  ]) ||\n    utils.avoidDocs();\n};\n\nexport default iterateJsdoc(({\n  context,\n  info: {\n    comment,\n  },\n  node,\n  report,\n  settings,\n  utils,\n}) => {\n  const {\n    contexts,\n    enableFixer = false,\n    forceRequireReturn = false,\n    forceReturnsWithAsync = false,\n    publicOnly = false,\n  } = context.options[0] || {};\n\n  // A preflight check. We do not need to run a deep check\n  // in case the @returns comment is optional or undefined.\n  if (canSkip(utils)) {\n    return;\n  }\n\n  /** @type {boolean|undefined} */\n  let forceRequireReturnContext;\n  if (contexts) {\n    const {\n      foundContext,\n    } = utils.findContext(contexts, comment);\n    if (typeof foundContext === 'object') {\n      forceRequireReturnContext = foundContext.forceRequireReturn;\n    }\n  }\n\n  const tagName = /** @type {string} */ (utils.getPreferredTagName({\n    tagName: 'returns',\n  }));\n  if (!tagName) {\n    return;\n  }\n\n  const tags = utils.getTags(tagName);\n\n  if (tags.length > 1) {\n    report(`Found more than one @${tagName} declaration.`);\n  }\n\n  const iteratingFunction = utils.isIteratingFunction();\n\n  // In case the code returns something, we expect a return value in JSDoc.\n  const [\n    tag,\n  ] = tags;\n  const missingReturnTag = typeof tag === 'undefined' || tag === null;\n\n  const shouldReport = () => {\n    if (!missingReturnTag) {\n      return false;\n    }\n\n    if (publicOnly) {\n      /** @type {import('./requireJsdoc.js').RequireJsdocOpts} */\n      const opt = {\n        ancestorsOnly: Boolean(publicOnly?.ancestorsOnly ?? false),\n        esm: Boolean(publicOnly?.esm ?? true),\n        initModuleExports: Boolean(publicOnly?.cjs ?? true),\n        initWindow: Boolean(publicOnly?.window ?? false),\n      };\n      /* c8 ignore next -- Fallback to deprecated method */\n      const {\n        // @ts-expect-error ESLint < 10\n        sourceCode = context.getSourceCode(),\n      } = context;\n      const exported = exportParser.isUncommentedExport(\n        /** @type {import('eslint').Rule.Node} */ (node), sourceCode, opt, settings,\n      );\n\n      if (!exported) {\n        return false;\n      }\n    }\n\n    if ((forceRequireReturn || forceRequireReturnContext) && (\n      iteratingFunction || utils.isVirtualFunction()\n    )) {\n      return true;\n    }\n\n    const isAsync = !iteratingFunction && utils.hasTag('async') ||\n      iteratingFunction && utils.isAsync();\n\n    if (forceReturnsWithAsync && isAsync) {\n      return true;\n    }\n\n    return iteratingFunction && utils.hasValueOrExecutorHasNonEmptyResolveValue(\n      forceReturnsWithAsync,\n    );\n  };\n\n  if (shouldReport()) {\n    utils.reportJSDoc(`Missing JSDoc @${tagName} declaration.`, null, enableFixer ? () => {\n      utils.addTag(tagName);\n    } : null);\n  }\n}, {\n  contextDefaults: true,\n  meta: {\n    docs: {\n      description: 'Requires that returns are documented with `@returns`.',\n      url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-returns.md#repos-sticky-header',\n    },\n    fixable: 'code',\n    schema: [\n      {\n        additionalProperties: false,\n        properties: {\n          checkConstructors: {\n            default: false,\n            description: `A value indicating whether \\`constructor\\`s should\nbe checked for \\`@returns\\` tags. Defaults to \\`false\\`.`,\n            type: 'boolean',\n          },\n          checkGetters: {\n            default: true,\n            description: `Boolean to determine whether getter methods should\nbe checked for \\`@returns\\` tags. Defaults to \\`true\\`.`,\n            type: 'boolean',\n          },\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 \\`forceRequireReturn\\` option is set or if the\n\\`forceReturnsWithAsync\\` option is set with a present \\`@async\\` tag\n(since we are not checking against the actual \\`return\\` 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                    forceRequireReturn: {\n                      type: 'boolean',\n                    },\n                  },\n                  type: 'object',\n                },\n              ],\n            },\n            type: 'array',\n          },\n          enableFixer: {\n            description: `Whether to enable the fixer to add a blank \\`@returns\\`.\nDefaults to \\`false\\`.`,\n            type: 'boolean',\n          },\n          exemptedBy: {\n            description: `Array of tags (e.g., \\`['type']\\`) whose presence on the\ndocument block avoids the need for a \\`@returns\\`. 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          forceRequireReturn: {\n            default: false,\n            description: `Set to \\`true\\` to always insist on\n\\`@returns\\` documentation regardless of implicit or explicit \\`return\\`'s\nin the function. May be desired to flag that a project is aware of an\n\\`undefined\\`/\\`void\\` return. Defaults to \\`false\\`.`,\n            type: 'boolean',\n          },\n          forceReturnsWithAsync: {\n            default: false,\n            description: `By default \\`async\\` functions that do not explicitly\nreturn a value pass this rule as an \\`async\\` function will always return a\n\\`Promise\\`, even if the \\`Promise\\` resolves to void. You can force all\n\\`async\\` functions (including ones with an explicit \\`Promise\\` but no\ndetected non-\\`undefined\\` \\`resolve\\` value) to require \\`@return\\`\ndocumentation by setting \\`forceReturnsWithAsync\\` to \\`true\\` on the options\nobject. This may be useful for flagging that there has been consideration\nof return type. Defaults to \\`false\\`.`,\n            type: 'boolean',\n          },\n          publicOnly: {\n            description: `This option will insist that missing \\`@returns\\` are only reported for\nfunction bodies / class declarations that are exported from the module.\nMay be a boolean or object. If set to \\`true\\`, the defaults below will be\nused. If unset, \\`@returns\\` reporting will not be limited to exports.\n\nThis object supports the following optional boolean keys (\\`false\\` unless\notherwise noted):\n\n- \\`ancestorsOnly\\` - Optimization to only check node ancestors to check if node is exported\n- \\`esm\\` - ESM exports are checked for \\`@returns\\` JSDoc comments (Defaults to \\`true\\`)\n- \\`cjs\\` - CommonJS exports are checked for \\`@returns\\` JSDoc comments  (Defaults to \\`true\\`)\n- \\`window\\` - Window global exports are checked for \\`@returns\\` JSDoc comments`,\n            oneOf: [\n              {\n                default: false,\n                type: 'boolean',\n              },\n              {\n                additionalProperties: false,\n                default: {},\n                properties: {\n                  ancestorsOnly: {\n                    type: 'boolean',\n                  },\n                  cjs: {\n                    type: 'boolean',\n                  },\n                  esm: {\n                    type: 'boolean',\n                  },\n                  window: {\n                    type: 'boolean',\n                  },\n                },\n                type: 'object',\n              },\n            ],\n          },\n        },\n        type: 'object',\n      },\n    ],\n    type: 'suggestion',\n  },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAF,sBAAA,CAAAC,OAAA;AAA8C,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE9C;AACA;AACA;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,MAAM;EAEN;EACA,WAAW,CACZ,CAAC,IACAD,KAAK,CAACE,SAAS,CAAC,CAAC;AACrB,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAN,OAAA,GAEa,IAAAO,qBAAY,EAAC,CAAC;EAC3BC,OAAO;EACPC,IAAI,EAAE;IACJC;EACF,CAAC;EACDC,IAAI;EACJC,MAAM;EACNC,QAAQ;EACRX;AACF,CAAC,KAAK;EACJ,MAAM;IACJY,QAAQ;IACRC,WAAW,GAAG,KAAK;IACnBC,kBAAkB,GAAG,KAAK;IAC1BC,qBAAqB,GAAG,KAAK;IAC7BC,UAAU,GAAG;EACf,CAAC,GAAGV,OAAO,CAACW,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;;E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