eslint-plugin-jsdoc 46.6.0 → 46.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.
|
@@ -42,6 +42,7 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
42
42
|
}) => {
|
|
43
43
|
const {
|
|
44
44
|
contexts,
|
|
45
|
+
enableFixer = false,
|
|
45
46
|
forceRequireReturn = false,
|
|
46
47
|
forceReturnsWithAsync = false
|
|
47
48
|
} = context.options[0] || {};
|
|
@@ -91,7 +92,9 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
91
92
|
return iteratingFunction && utils.hasValueOrExecutorHasNonEmptyResolveValue(forceReturnsWithAsync);
|
|
92
93
|
};
|
|
93
94
|
if (shouldReport()) {
|
|
94
|
-
|
|
95
|
+
utils.reportJSDoc(`Missing JSDoc @${tagName} declaration.`, null, enableFixer ? () => {
|
|
96
|
+
utils.addTag(tagName);
|
|
97
|
+
} : null);
|
|
95
98
|
}
|
|
96
99
|
}, {
|
|
97
100
|
contextDefaults: true,
|
|
@@ -100,6 +103,7 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
100
103
|
description: 'Requires that returns are documented.',
|
|
101
104
|
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-returns.md#repos-sticky-header'
|
|
102
105
|
},
|
|
106
|
+
fixable: 'code',
|
|
103
107
|
schema: [{
|
|
104
108
|
additionalProperties: false,
|
|
105
109
|
properties: {
|
|
@@ -133,6 +137,9 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
133
137
|
},
|
|
134
138
|
type: 'array'
|
|
135
139
|
},
|
|
140
|
+
enableFixer: {
|
|
141
|
+
type: 'boolean'
|
|
142
|
+
},
|
|
136
143
|
exemptedBy: {
|
|
137
144
|
items: {
|
|
138
145
|
type: 'string'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requireReturns.js","names":["_iterateJsdoc","_interopRequireDefault","require","obj","__esModule","default","canSkip","utils","hasATag","avoidDocs","_default","iterateJsdoc","info","comment","report","context","contexts","forceRequireReturn","forceReturnsWithAsync","options","forceRequireReturnContext","foundContext","findContext","tagName","getPreferredTagName","tags","getTags","length","iteratingFunction","isIteratingFunction","tag","missingReturnTag","shouldReport","isVirtualFunction","isAsync","hasTag","hasValueOrExecutorHasNonEmptyResolveValue","contextDefaults","meta","docs","description","url","schema","additionalProperties","properties","checkConstructors","type","checkGetters","items","anyOf","exemptedBy","exports","module"],"sources":["../../src/rules/requireReturns.js"],"sourcesContent":["import 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 info: {\n comment,\n },\n report,\n utils,\n context,\n}) => {\n const {\n contexts,\n forceRequireReturn = false,\n forceReturnsWithAsync = 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 ((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
|
|
1
|
+
{"version":3,"file":"requireReturns.js","names":["_iterateJsdoc","_interopRequireDefault","require","obj","__esModule","default","canSkip","utils","hasATag","avoidDocs","_default","iterateJsdoc","info","comment","report","context","contexts","enableFixer","forceRequireReturn","forceReturnsWithAsync","options","forceRequireReturnContext","foundContext","findContext","tagName","getPreferredTagName","tags","getTags","length","iteratingFunction","isIteratingFunction","tag","missingReturnTag","shouldReport","isVirtualFunction","isAsync","hasTag","hasValueOrExecutorHasNonEmptyResolveValue","reportJSDoc","addTag","contextDefaults","meta","docs","description","url","fixable","schema","additionalProperties","properties","checkConstructors","type","checkGetters","items","anyOf","exemptedBy","exports","module"],"sources":["../../src/rules/requireReturns.js"],"sourcesContent":["import 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 info: {\n comment,\n },\n report,\n utils,\n context,\n}) => {\n const {\n contexts,\n enableFixer = false,\n forceRequireReturn = false,\n forceReturnsWithAsync = 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 ((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.',\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 type: 'boolean',\n },\n checkGetters: {\n default: true,\n type: 'boolean',\n },\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 forceRequireReturn: {\n type: 'boolean',\n },\n },\n type: 'object',\n },\n ],\n },\n type: 'array',\n },\n enableFixer: {\n type: 'boolean',\n },\n exemptedBy: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n forceRequireReturn: {\n default: false,\n type: 'boolean',\n },\n forceReturnsWithAsync: {\n default: false,\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,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;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,GAEa,IAAAC,qBAAY,EAAC,CAAC;EAC3BC,IAAI,EAAE;IACJC;E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