eslint-plugin-jsdoc 61.4.1 → 61.5.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.
- package/dist/rules/checkTemplateNames.cjs +8 -2
- package/dist/rules/checkTemplateNames.cjs.map +1 -1
- package/dist/rules/requireRejects.cjs +1 -1
- package/dist/rules/requireRejects.cjs.map +1 -1
- package/dist/rules/requireTemplate.cjs +10 -4
- package/dist/rules/requireTemplate.cjs.map +1 -1
- package/dist/tagNames.cjs +4 -2
- package/dist/tagNames.cjs.map +1 -1
- package/package.json +1 -1
- package/src/rules/checkTemplateNames.js +9 -2
- package/src/rules/requireRejects.js +1 -1
- package/src/rules/requireTemplate.js +13 -4
- package/src/tagNames.js +5 -2
|
@@ -19,7 +19,13 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
19
19
|
const {
|
|
20
20
|
mode
|
|
21
21
|
} = settings;
|
|
22
|
-
const
|
|
22
|
+
const tgName = /** @type {string} */utils.getPreferredTagName({
|
|
23
|
+
tagName: 'template'
|
|
24
|
+
});
|
|
25
|
+
if (!tgName) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const templateTags = utils.getTags(tgName);
|
|
23
29
|
const usedNames = new Set();
|
|
24
30
|
/**
|
|
25
31
|
* @param {string} potentialType
|
|
@@ -62,7 +68,7 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
62
68
|
const names = utils.parseClosureTemplateTag(tag);
|
|
63
69
|
for (const nme of names) {
|
|
64
70
|
if (!usedNames.has(nme)) {
|
|
65
|
-
report(
|
|
71
|
+
report(`@${tgName} ${nme} not in use`, null, tag);
|
|
66
72
|
}
|
|
67
73
|
}
|
|
68
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkTemplateNames.cjs","names":["_iterateJsdoc","_interopRequireWildcard","require","_jsdocUtils","_jsdoccomment","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_default","exports","iterateJsdoc","jsdoc","node","report","settings","sourceCode","utils","mode","templateTags","getTags","usedNames","Set","checkForUsedTypes","potentialType","parsedType","tryParseType","parseType","traverse","nde","type","value","add","checkParamsAndReturnsTags","jsdc","paramName","getPreferredTagName","tagName","paramTags","paramTag","returnsName","returnsTags","returnsTag","checkTemplateTags","tag","names","parseClosureTemplateTag","nme","checkParameters","aliasDeclaration","checkParamsAndReturns","params","typeParameters","name","body","commentNode","getJSDocComment","innerJsdoc","parseComment","typeName","typeTags","typeTag","handleTypeAliases","declaration","callbackTags","functionTags","length","typedefTags","potentialTypedefType","propertyName","propertyTags","propertyTag","iterateAllJsdocs","meta","docs","description","url","schema","module"],"sources":["../../src/rules/checkTemplateNames.js"],"sourcesContent":["import iterateJsdoc, {\n parseComment,\n} from '../iterateJsdoc.js';\nimport {\n getTags,\n} from '../jsdocUtils.js';\nimport {\n getJSDocComment,\n parse as parseType,\n traverse,\n tryParse as tryParseType,\n} from '@es-joy/jsdoccomment';\n\nexport default iterateJsdoc(({\n jsdoc,\n node,\n report,\n settings,\n sourceCode,\n utils,\n}) => {\n const {\n mode,\n } = settings;\n\n const templateTags = utils.getTags('template');\n\n const usedNames = new Set();\n /**\n * @param {string} potentialType\n */\n const checkForUsedTypes = (potentialType) => {\n let parsedType;\n try {\n parsedType = mode === 'permissive' ?\n tryParseType(/** @type {string} */ (potentialType)) :\n parseType(/** @type {string} */ (potentialType), mode);\n } catch {\n return;\n }\n\n traverse(parsedType, (nde) => {\n const {\n type,\n value,\n } = /** @type {import('jsdoc-type-pratt-parser').NameResult} */ (nde);\n if (type === 'JsdocTypeName') {\n usedNames.add(value);\n }\n });\n };\n\n const checkParamsAndReturnsTags = (jsdc = jsdoc) => {\n const paramName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'param',\n }));\n const paramTags = getTags(jsdc, paramName);\n for (const paramTag of paramTags) {\n checkForUsedTypes(paramTag.type);\n }\n\n const returnsName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'returns',\n }));\n const returnsTags = getTags(jsdc, returnsName);\n for (const returnsTag of returnsTags) {\n checkForUsedTypes(returnsTag.type);\n }\n };\n\n const checkTemplateTags = () => {\n for (const tag of templateTags) {\n const names = utils.parseClosureTemplateTag(tag);\n for (const nme of names) {\n if (!usedNames.has(nme)) {\n report(`@template ${nme} not in use`, null, tag);\n }\n }\n }\n };\n\n /**\n * @param {import('@typescript-eslint/types').TSESTree.FunctionDeclaration|\n * import('@typescript-eslint/types').TSESTree.ClassDeclaration|\n * import('@typescript-eslint/types').TSESTree.TSInterfaceDeclaration|\n * import('@typescript-eslint/types').TSESTree.TSTypeAliasDeclaration} aliasDeclaration\n * @param {boolean} [checkParamsAndReturns]\n */\n const checkParameters = (aliasDeclaration, checkParamsAndReturns) => {\n /* c8 ignore next -- Guard */\n const {\n params,\n } = aliasDeclaration.typeParameters ?? {\n params: [],\n };\n for (const {\n name: {\n name,\n },\n } of params) {\n usedNames.add(name);\n }\n\n if (checkParamsAndReturns) {\n checkParamsAndReturnsTags();\n } else if (aliasDeclaration.type === 'ClassDeclaration') {\n /* c8 ignore next -- TS */\n for (const nde of aliasDeclaration?.body?.body ?? []) {\n // @ts-expect-error Should be ok\n const commentNode = getJSDocComment(sourceCode, nde, settings);\n if (!commentNode) {\n continue;\n }\n\n const innerJsdoc = parseComment(commentNode, '');\n checkParamsAndReturnsTags(innerJsdoc);\n\n const typeName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'type',\n }));\n const typeTags = getTags(innerJsdoc, typeName);\n for (const typeTag of typeTags) {\n checkForUsedTypes(typeTag.type);\n }\n }\n }\n\n checkTemplateTags();\n };\n\n const handleTypeAliases = () => {\n const nde = /** @type {import('@typescript-eslint/types').TSESTree.Node} */ (\n node\n );\n if (!nde) {\n return;\n }\n\n switch (nde.type) {\n case 'ClassDeclaration':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n checkParameters(nde);\n break;\n case 'ExportDefaultDeclaration':\n case 'ExportNamedDeclaration':\n switch (nde.declaration?.type) {\n case 'ClassDeclaration':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n checkParameters(nde.declaration);\n break;\n case 'FunctionDeclaration':\n checkParameters(nde.declaration, true);\n break;\n }\n\n break;\n case 'FunctionDeclaration':\n checkParameters(nde, true);\n break;\n }\n };\n\n const callbackTags = utils.getTags('callback');\n const functionTags = utils.getTags('function');\n if (callbackTags.length || functionTags.length) {\n checkParamsAndReturnsTags();\n checkTemplateTags();\n return;\n }\n\n const typedefTags = utils.getTags('typedef');\n if (!typedefTags.length || typedefTags.length >= 2) {\n handleTypeAliases();\n return;\n }\n\n const potentialTypedefType = typedefTags[0].type;\n checkForUsedTypes(potentialTypedefType);\n\n const propertyName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'property',\n }));\n const propertyTags = utils.getTags(propertyName);\n for (const propertyTag of propertyTags) {\n checkForUsedTypes(propertyTag.type);\n }\n\n checkTemplateTags();\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Checks that any `@template` names are actually used in the connected `@typedef` or type alias.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-template-names.md#repos-sticky-header',\n },\n schema: [],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,WAAA,GAAAD,OAAA;AAGA,IAAAE,aAAA,GAAAF,OAAA;AAK8B,SAAAD,wBAAAI,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAN,uBAAA,YAAAA,CAAAI,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,C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KAAK,CAACG,OAAO,CAACiD,YAAY,CAAC;EAChD,KAAK,MAAME,WAAW,IAAID,YAAY,EAAE;IACtC/C,iBAAiB,CAACgD,WAAW,CAACzC,IAAI,CAAC;EACrC;EAEAa,iBAAiB,CAAC,CAAC;AACrB,CAAC,EAAE;EACD6B,gBAAgB,EAAE,IAAI;EACtBC,IAAI,EAAE;IACJC,IAAI,EAAE;MACJC,WAAW,EAAE,gGAAgG;MAC7GC,GAAG,EAAE;IACP,CAAC;IACDC,MAAM,EAAE,EAAE;IACV/C,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAgD,MAAA,CAAApE,OAAA,GAAAA,OAAA,CAAAV,OAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"checkTemplateNames.cjs","names":["_iterateJsdoc","_interopRequireWildcard","require","_jsdocUtils","_jsdoccomment","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_default","exports","iterateJsdoc","jsdoc","node","report","settings","sourceCode","utils","mode","tgName","getPreferredTagName","tagName","templateTags","getTags","usedNames","Set","checkForUsedTypes","potentialType","parsedType","tryParseType","parseType","traverse","nde","type","value","add","checkParamsAndReturnsTags","jsdc","paramName","paramTags","paramTag","returnsName","returnsTags","returnsTag","checkTemplateTags","tag","names","parseClosureTemplateTag","nme","checkParameters","aliasDeclaration","checkParamsAndReturns","params","typeParameters","name","body","commentNode","getJSDocComment","innerJsdoc","parseComment","typeName","typeTags","typeTag","handleTypeAliases","declaration","callbackTags","functionTags","length","typedefTags","potentialTypedefType","propertyName","propertyTags","propertyTag","iterateAllJsdocs","meta","docs","description","url","schema","module"],"sources":["../../src/rules/checkTemplateNames.js"],"sourcesContent":["import iterateJsdoc, {\n parseComment,\n} from '../iterateJsdoc.js';\nimport {\n getTags,\n} from '../jsdocUtils.js';\nimport {\n getJSDocComment,\n parse as parseType,\n traverse,\n tryParse as tryParseType,\n} from '@es-joy/jsdoccomment';\n\nexport default iterateJsdoc(({\n jsdoc,\n node,\n report,\n settings,\n sourceCode,\n utils,\n}) => {\n const {\n mode,\n } = settings;\n\n const tgName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'template',\n }));\n if (!tgName) {\n return;\n }\n\n const templateTags = utils.getTags(tgName);\n\n const usedNames = new Set();\n /**\n * @param {string} potentialType\n */\n const checkForUsedTypes = (potentialType) => {\n let parsedType;\n try {\n parsedType = mode === 'permissive' ?\n tryParseType(/** @type {string} */ (potentialType)) :\n parseType(/** @type {string} */ (potentialType), mode);\n } catch {\n return;\n }\n\n traverse(parsedType, (nde) => {\n const {\n type,\n value,\n } = /** @type {import('jsdoc-type-pratt-parser').NameResult} */ (nde);\n if (type === 'JsdocTypeName') {\n usedNames.add(value);\n }\n });\n };\n\n const checkParamsAndReturnsTags = (jsdc = jsdoc) => {\n const paramName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'param',\n }));\n const paramTags = getTags(jsdc, paramName);\n for (const paramTag of paramTags) {\n checkForUsedTypes(paramTag.type);\n }\n\n const returnsName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'returns',\n }));\n const returnsTags = getTags(jsdc, returnsName);\n for (const returnsTag of returnsTags) {\n checkForUsedTypes(returnsTag.type);\n }\n };\n\n const checkTemplateTags = () => {\n for (const tag of templateTags) {\n const names = utils.parseClosureTemplateTag(tag);\n for (const nme of names) {\n if (!usedNames.has(nme)) {\n report(`@${tgName} ${nme} not in use`, null, tag);\n }\n }\n }\n };\n\n /**\n * @param {import('@typescript-eslint/types').TSESTree.FunctionDeclaration|\n * import('@typescript-eslint/types').TSESTree.ClassDeclaration|\n * import('@typescript-eslint/types').TSESTree.TSInterfaceDeclaration|\n * import('@typescript-eslint/types').TSESTree.TSTypeAliasDeclaration} aliasDeclaration\n * @param {boolean} [checkParamsAndReturns]\n */\n const checkParameters = (aliasDeclaration, checkParamsAndReturns) => {\n /* c8 ignore next -- Guard */\n const {\n params,\n } = aliasDeclaration.typeParameters ?? {\n params: [],\n };\n for (const {\n name: {\n name,\n },\n } of params) {\n usedNames.add(name);\n }\n\n if (checkParamsAndReturns) {\n checkParamsAndReturnsTags();\n } else if (aliasDeclaration.type === 'ClassDeclaration') {\n /* c8 ignore next -- TS */\n for (const nde of aliasDeclaration?.body?.body ?? []) {\n // @ts-expect-error Should be ok\n const commentNode = getJSDocComment(sourceCode, nde, settings);\n if (!commentNode) {\n continue;\n }\n\n const innerJsdoc = parseComment(commentNode, '');\n checkParamsAndReturnsTags(innerJsdoc);\n\n const typeName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'type',\n }));\n const typeTags = getTags(innerJsdoc, typeName);\n for (const typeTag of typeTags) {\n checkForUsedTypes(typeTag.type);\n }\n }\n }\n\n checkTemplateTags();\n };\n\n const handleTypeAliases = () => {\n const nde = /** @type {import('@typescript-eslint/types').TSESTree.Node} */ (\n node\n );\n if (!nde) {\n return;\n }\n\n switch (nde.type) {\n case 'ClassDeclaration':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n checkParameters(nde);\n break;\n case 'ExportDefaultDeclaration':\n case 'ExportNamedDeclaration':\n switch (nde.declaration?.type) {\n case 'ClassDeclaration':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n checkParameters(nde.declaration);\n break;\n case 'FunctionDeclaration':\n checkParameters(nde.declaration, true);\n break;\n }\n\n break;\n case 'FunctionDeclaration':\n checkParameters(nde, true);\n break;\n }\n };\n\n const callbackTags = utils.getTags('callback');\n const functionTags = utils.getTags('function');\n if (callbackTags.length || functionTags.length) {\n checkParamsAndReturnsTags();\n checkTemplateTags();\n return;\n }\n\n const typedefTags = utils.getTags('typedef');\n if (!typedefTags.length || typedefTags.length >= 2) {\n handleTypeAliases();\n return;\n }\n\n const potentialTypedefType = typedefTags[0].type;\n checkForUsedTypes(potentialTypedefType);\n\n const propertyName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'property',\n }));\n const propertyTags = utils.getTags(propertyName);\n for (const propertyTag of propertyTags) {\n checkForUsedTypes(propertyTag.type);\n }\n\n checkTemplateTags();\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Checks that any `@template` names are actually used in the connected `@typedef` or type alias.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-template-names.md#repos-sticky-header',\n },\n schema: [],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,WAAA,GAAAD,OAAA;AAGA,IAAAE,aAAA,GAAAF,OAAA;AAK8B,SAAAD,wBAAAI,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAN,uBAAA,YAAAA,CAAAI,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CA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}
|
|
@@ -166,7 +166,7 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
166
166
|
return hasRejectValue(/** @type {import('eslint').Rule.Node} */node);
|
|
167
167
|
};
|
|
168
168
|
if (shouldReport()) {
|
|
169
|
-
report('Promise-rejecting function requires `@
|
|
169
|
+
report('Promise-rejecting function requires `@rejects` tag');
|
|
170
170
|
}
|
|
171
171
|
}, {
|
|
172
172
|
contextDefaults: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requireRejects.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","hasRejectValue","node","innerFunction","isAsync","type","innerIsAsync","async","body","some","bodyNode","callee","object","name","property","expression","consequent","alternate","arguments","length","executor","argument","cases","someCase","nde","handler","finalizer","canSkip","utils","hasATag","avoidDocs","_default","exports","iterateJsdoc","report","tagName","getPreferredTagName","tags","getTags","iteratingFunction","isIteratingFunction","tag","missingRejectsTag","shouldReport","contextDefaults","meta","docs","description","url","schema","additionalProperties","properties","contexts","items","anyOf","comment","context","exemptedBy","module"],"sources":["../../src/rules/requireRejects.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\n/**\n * Checks if a node or its children contain Promise rejection patterns\n * @param {import('eslint').Rule.Node} node\n * @param {boolean} [innerFunction]\n * @param {boolean} [isAsync]\n * @returns {boolean}\n */\n// eslint-disable-next-line complexity -- Temporary\nconst hasRejectValue = (node, innerFunction, isAsync) => {\n if (!node) {\n return false;\n }\n\n switch (node.type) {\n case 'ArrowFunctionExpression':\n case 'FunctionDeclaration':\n case 'FunctionExpression': {\n // For inner functions in async contexts, check if they throw\n // (they could be called and cause rejection)\n if (innerFunction) {\n // Check inner functions for throws - if called from async context, throws become rejections\n const innerIsAsync = node.async;\n // Pass isAsync=true if the inner function is async OR if we're already in an async context\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.body), false, innerIsAsync || isAsync);\n }\n\n // This is the top-level function we're checking\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.body), true, node.async);\n }\n\n case 'BlockStatement': {\n return node.body.some((bodyNode) => {\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (bodyNode), innerFunction, isAsync);\n });\n }\n\n case 'CallExpression': {\n // Check for Promise.reject()\n if (node.callee.type === 'MemberExpression' &&\n node.callee.object.type === 'Identifier' &&\n node.callee.object.name === 'Promise' &&\n node.callee.property.type === 'Identifier' &&\n node.callee.property.name === 'reject') {\n return true;\n }\n\n // Check for reject() call (in Promise executor context)\n if (node.callee.type === 'Identifier' && node.callee.name === 'reject') {\n return true;\n }\n\n // Check if this is calling an inner function that might reject\n if (innerFunction && node.callee.type === 'Identifier') {\n // We found a function call inside - check if it could be calling a function that rejects\n // We'll handle this in function body traversal\n return false;\n }\n\n return false;\n }\n\n case 'DoWhileStatement':\n case 'ForInStatement':\n case 'ForOfStatement':\n case 'ForStatement':\n case 'LabeledStatement':\n case 'WhileStatement':\n\n case 'WithStatement': {\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.body), innerFunction, isAsync);\n }\n\n case 'ExpressionStatement': {\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.expression), innerFunction, isAsync);\n }\n\n case 'IfStatement': {\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.consequent), innerFunction, isAsync) || hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.alternate), innerFunction, isAsync);\n }\n\n case 'NewExpression': {\n // Check for new Promise((resolve, reject) => { reject(...) })\n if (node.callee.type === 'Identifier' && node.callee.name === 'Promise' && node.arguments.length > 0) {\n const executor = node.arguments[0];\n if (executor.type === 'ArrowFunctionExpression' || executor.type === 'FunctionExpression') {\n // Check if the executor has reject() calls\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (executor.body), false, false);\n }\n }\n\n return false;\n }\n\n case 'ReturnStatement': {\n if (node.argument) {\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.argument), innerFunction, isAsync);\n }\n\n return false;\n }\n\n case 'SwitchStatement': {\n return node.cases.some(\n (someCase) => {\n return someCase.consequent.some((nde) => {\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (nde), innerFunction, isAsync);\n });\n },\n );\n }\n\n // Throw statements in async functions become rejections\n case 'ThrowStatement': {\n return isAsync === true;\n }\n\n case 'TryStatement': {\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.handler && node.handler.body), innerFunction, isAsync) ||\n hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.finalizer), innerFunction, isAsync);\n }\n\n default: {\n return false;\n }\n }\n};\n\n/**\n * We can skip checking for a rejects value, in case the documentation is inherited\n * or the method is abstract.\n * @param {import('../iterateJsdoc.js').Utils} utils\n * @returns {boolean}\n */\nconst canSkip = (utils) => {\n return utils.hasATag([\n 'abstract',\n 'virtual',\n 'type',\n ]) ||\n utils.avoidDocs();\n};\n\nexport default iterateJsdoc(({\n node,\n report,\n utils,\n}) => {\n if (canSkip(utils)) {\n return;\n }\n\n const tagName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'rejects',\n }));\n if (!tagName) {\n return;\n }\n\n const tags = utils.getTags(tagName);\n const iteratingFunction = utils.isIteratingFunction();\n\n const [\n tag,\n ] = tags;\n const missingRejectsTag = typeof tag === 'undefined' || tag === null;\n\n const shouldReport = () => {\n if (!missingRejectsTag) {\n return false;\n }\n\n // Check if this is an async function or returns a Promise\n const isAsync = utils.isAsync();\n if (!isAsync && !iteratingFunction) {\n return false;\n }\n\n // For async functions, check for throw statements\n // For regular functions, check for Promise.reject or reject calls\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node));\n };\n\n if (shouldReport()) {\n report('Promise-rejecting function requires `@reject` tag');\n }\n}, {\n contextDefaults: true,\n meta: {\n docs: {\n description: 'Requires that Promise rejections are documented with `@rejects` tags.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-rejects.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\\`).`,\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 \\`@rejects\\`. Defaults to an array\nwith \\`abstract\\`, \\`virtual\\`, and \\`type\\`. If you set this array, it will overwrite the default,\nso be sure to add back those tags if you wish their presence to cause\nexemption of the rule.`,\n items: {\n type: 'string',\n },\n type: 'array',\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,cAAc,GAAGA,CAACC,IAAI,EAAEC,aAAa,EAAEC,OAAO,KAAK;EACvD,IAAI,CAACF,IAAI,EAAE;IACT,OAAO,KAAK;EACd;EAEA,QAAQA,IAAI,CAACG,IAAI;IACf,KAAK,yBAAyB;IAC9B,KAAK,qBAAqB;IAC1B,KAAK,oBAAoB;MAAE;QACzB;QACA;QACA,IAAIF,aAAa,EAAE;UACjB;UACA,MAAMG,YAAY,GAAGJ,IAAI,CAACK,KAAK;UAC/B;UACA,OAAON,cAAc,CAAC,yCAA2CC,IAAI,CAACM,IAAI,EAAG,KAAK,EAAEF,YAAY,IAAI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AO,GAAGwB,KAAK,CAACxB,OAAO,CAAC,CAAC;IAC/B,IAAI,CAACA,OAAO,IAAI,CAACmC,iBAAiB,EAAE;MAClC,OAAO,KAAK;IACd;;IAEA;IACA;IACA,OAAOtC,cAAc,CAAC,yCAA2CC,IAAK,CAAC;EACzE,CAAC;EAED,IAAIyC,YAAY,CAAC,CAAC,EAAE;IAClBT,MAAM,CAAC,mDAAmD,CAAC;EAC7D;AACF,CAAC,EAAE;EACDU,eAAe,EAAE,IAAI;EACrBC,IAAI,EAAE;IACJC,IAAI,EAAE;MACJC,WAAW,EAAE,uEAAuE;MACpFC,GAAG,EAAE;IACP,CAAC;IACDC,MAAM,EAAE,CACN;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACVC,QAAQ,EAAE;UACRL,WAAW,EAAE;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,yBAAyB;UACbM,KAAK,EAAE;YACLC,KAAK,EAAE,CACL;cACEjD,IAAI,EAAE;YACR,CAAC,EACD;cACE6C,oBAAoB,EAAE,KAAK;cAC3BC,UAAU,EAAE;gBACVI,OAAO,EAAE;kBACPlD,IAAI,EAAE;gBACR,CAAC;gBACDmD,OAAO,EAAE;kBACPnD,IAAI,EAAE;gBACR;cACF,CAAC;cACDA,IAAI,EAAE;YACR,CAAC;UAEL,CAAC;UACDA,IAAI,EAAE;QACR,CAAC;QACDoD,UAAU,EAAE;UACVV,WAAW,EAAE;AACzB;AACA;AACA;AACA,uBAAuB;UACXM,KAAK,EAAE;YACLhD,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAqD,MAAA,CAAA1B,OAAA,GAAAA,OAAA,CAAAhC,OAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"requireRejects.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","e","__esModule","default","hasRejectValue","node","innerFunction","isAsync","type","innerIsAsync","async","body","some","bodyNode","callee","object","name","property","expression","consequent","alternate","arguments","length","executor","argument","cases","someCase","nde","handler","finalizer","canSkip","utils","hasATag","avoidDocs","_default","exports","iterateJsdoc","report","tagName","getPreferredTagName","tags","getTags","iteratingFunction","isIteratingFunction","tag","missingRejectsTag","shouldReport","contextDefaults","meta","docs","description","url","schema","additionalProperties","properties","contexts","items","anyOf","comment","context","exemptedBy","module"],"sources":["../../src/rules/requireRejects.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\n/**\n * Checks if a node or its children contain Promise rejection patterns\n * @param {import('eslint').Rule.Node} node\n * @param {boolean} [innerFunction]\n * @param {boolean} [isAsync]\n * @returns {boolean}\n */\n// eslint-disable-next-line complexity -- Temporary\nconst hasRejectValue = (node, innerFunction, isAsync) => {\n if (!node) {\n return false;\n }\n\n switch (node.type) {\n case 'ArrowFunctionExpression':\n case 'FunctionDeclaration':\n case 'FunctionExpression': {\n // For inner functions in async contexts, check if they throw\n // (they could be called and cause rejection)\n if (innerFunction) {\n // Check inner functions for throws - if called from async context, throws become rejections\n const innerIsAsync = node.async;\n // Pass isAsync=true if the inner function is async OR if we're already in an async context\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.body), false, innerIsAsync || isAsync);\n }\n\n // This is the top-level function we're checking\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.body), true, node.async);\n }\n\n case 'BlockStatement': {\n return node.body.some((bodyNode) => {\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (bodyNode), innerFunction, isAsync);\n });\n }\n\n case 'CallExpression': {\n // Check for Promise.reject()\n if (node.callee.type === 'MemberExpression' &&\n node.callee.object.type === 'Identifier' &&\n node.callee.object.name === 'Promise' &&\n node.callee.property.type === 'Identifier' &&\n node.callee.property.name === 'reject') {\n return true;\n }\n\n // Check for reject() call (in Promise executor context)\n if (node.callee.type === 'Identifier' && node.callee.name === 'reject') {\n return true;\n }\n\n // Check if this is calling an inner function that might reject\n if (innerFunction && node.callee.type === 'Identifier') {\n // We found a function call inside - check if it could be calling a function that rejects\n // We'll handle this in function body traversal\n return false;\n }\n\n return false;\n }\n\n case 'DoWhileStatement':\n case 'ForInStatement':\n case 'ForOfStatement':\n case 'ForStatement':\n case 'LabeledStatement':\n case 'WhileStatement':\n\n case 'WithStatement': {\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.body), innerFunction, isAsync);\n }\n\n case 'ExpressionStatement': {\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.expression), innerFunction, isAsync);\n }\n\n case 'IfStatement': {\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.consequent), innerFunction, isAsync) || hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.alternate), innerFunction, isAsync);\n }\n\n case 'NewExpression': {\n // Check for new Promise((resolve, reject) => { reject(...) })\n if (node.callee.type === 'Identifier' && node.callee.name === 'Promise' && node.arguments.length > 0) {\n const executor = node.arguments[0];\n if (executor.type === 'ArrowFunctionExpression' || executor.type === 'FunctionExpression') {\n // Check if the executor has reject() calls\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (executor.body), false, false);\n }\n }\n\n return false;\n }\n\n case 'ReturnStatement': {\n if (node.argument) {\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.argument), innerFunction, isAsync);\n }\n\n return false;\n }\n\n case 'SwitchStatement': {\n return node.cases.some(\n (someCase) => {\n return someCase.consequent.some((nde) => {\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (nde), innerFunction, isAsync);\n });\n },\n );\n }\n\n // Throw statements in async functions become rejections\n case 'ThrowStatement': {\n return isAsync === true;\n }\n\n case 'TryStatement': {\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.handler && node.handler.body), innerFunction, isAsync) ||\n hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node.finalizer), innerFunction, isAsync);\n }\n\n default: {\n return false;\n }\n }\n};\n\n/**\n * We can skip checking for a rejects value, in case the documentation is inherited\n * or the method is abstract.\n * @param {import('../iterateJsdoc.js').Utils} utils\n * @returns {boolean}\n */\nconst canSkip = (utils) => {\n return utils.hasATag([\n 'abstract',\n 'virtual',\n 'type',\n ]) ||\n utils.avoidDocs();\n};\n\nexport default iterateJsdoc(({\n node,\n report,\n utils,\n}) => {\n if (canSkip(utils)) {\n return;\n }\n\n const tagName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'rejects',\n }));\n if (!tagName) {\n return;\n }\n\n const tags = utils.getTags(tagName);\n const iteratingFunction = utils.isIteratingFunction();\n\n const [\n tag,\n ] = tags;\n const missingRejectsTag = typeof tag === 'undefined' || tag === null;\n\n const shouldReport = () => {\n if (!missingRejectsTag) {\n return false;\n }\n\n // Check if this is an async function or returns a Promise\n const isAsync = utils.isAsync();\n if (!isAsync && !iteratingFunction) {\n return false;\n }\n\n // For async functions, check for throw statements\n // For regular functions, check for Promise.reject or reject calls\n return hasRejectValue(/** @type {import('eslint').Rule.Node} */ (node));\n };\n\n if (shouldReport()) {\n report('Promise-rejecting function requires `@rejects` tag');\n }\n}, {\n contextDefaults: true,\n meta: {\n docs: {\n description: 'Requires that Promise rejections are documented with `@rejects` tags.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-rejects.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\\`).`,\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 \\`@rejects\\`. Defaults to an array\nwith \\`abstract\\`, \\`virtual\\`, and \\`type\\`. If you set this array, it will overwrite the default,\nso be sure to add back those tags if you wish their presence to cause\nexemption of the rule.`,\n items: {\n type: 'string',\n },\n type: 'array',\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,cAAc,GAAGA,CAACC,IAAI,EAAEC,aAAa,EAAEC,OAAO,KAAK;EACvD,IAAI,CAACF,IAAI,EAAE;IACT,OAAO,KAAK;EACd;EAEA,QAAQA,IAAI,CAACG,IAAI;IACf,KAAK,yBAAyB;IAC9B,KAAK,qBAAqB;IAC1B,KAAK,oBAAoB;MAAE;QACzB;QACA;QACA,IAAIF,aAAa,EAAE;UACjB;UACA,MAAMG,YAAY,GAAGJ,IAAI,CAACK,KAAK;UAC/B;UACA,OAAON,cAAc,CAAC,yCAA2CC,IAAI,CAACM,IAAI,EAAG,KAAK,EAAEF,YAAY,IAAIF,OAAO,CAAC;QAC9G;;QAEA;QACA,OAAOH,cAAc,CAAC,yCAA2CC,IAAI,CAACM,IAAI,EAAG,IAAI,EAAEN,IAAI,CAACK,KAAK,CAAC;MAChG;IAEA,KAAK,gBAAgB;MAAE;QACrB,OAAOL,IAAI,CAACM,IAAI,CAACC,IAAI,CAAEC,QAAQ,IAAK;UAClC,OAAOT,cAAc,CAAC,yCAA2CS,QAAQ,EAAGP,aAAa,EAAEC,OAAO,CAAC;QACrG,CAAC,CAAC;MACJ;IAEA,KAAK,gBAAgB;MAAE;QACrB;QACA,IAAIF,IAAI,CAACS,MAAM,C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AG,EAAE;IACP,CAAC;IACDC,MAAM,EAAE,CACN;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACVC,QAAQ,EAAE;UACRL,WAAW,EAAE;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,yBAAyB;UACbM,KAAK,EAAE;YACLC,KAAK,EAAE,CACL;cACEjD,IAAI,EAAE;YACR,CAAC,EACD;cACE6C,oBAAoB,EAAE,KAAK;cAC3BC,UAAU,EAAE;gBACVI,OAAO,EAAE;kBACPlD,IAAI,EAAE;gBACR,CAAC;gBACDmD,OAAO,EAAE;kBACPnD,IAAI,EAAE;gBACR;cACF,CAAC;cACDA,IAAI,EAAE;YACR,CAAC;UAEL,CAAC;UACDA,IAAI,EAAE;QACR,CAAC;QACDoD,UAAU,EAAE;UACVV,WAAW,EAAE;AACzB;AACA;AACA;AACA,uBAAuB;UACXM,KAAK,EAAE;YACLhD,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAqD,MAAA,CAAA1B,OAAA,GAAAA,OAAA,CAAAhC,OAAA","ignoreList":[]}
|
|
@@ -24,7 +24,13 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
24
24
|
mode
|
|
25
25
|
} = settings;
|
|
26
26
|
const usedNames = new Set();
|
|
27
|
-
const
|
|
27
|
+
const tgName = /** @type {string} */utils.getPreferredTagName({
|
|
28
|
+
tagName: 'template'
|
|
29
|
+
});
|
|
30
|
+
if (!tgName) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const templateTags = utils.getTags(tgName);
|
|
28
34
|
const templateNames = templateTags.flatMap(tag => {
|
|
29
35
|
return utils.parseClosureTemplateTag(tag);
|
|
30
36
|
});
|
|
@@ -32,7 +38,7 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
32
38
|
for (const tag of templateTags) {
|
|
33
39
|
const names = utils.parseClosureTemplateTag(tag);
|
|
34
40
|
if (names.length > 1) {
|
|
35
|
-
report(`Missing separate
|
|
41
|
+
report(`Missing separate @${tgName} for ${names[1]}`, null, tag);
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
}
|
|
@@ -61,7 +67,7 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
61
67
|
}
|
|
62
68
|
for (const usedName of usedNames) {
|
|
63
69
|
if (!templateNames.includes(usedName)) {
|
|
64
|
-
report(`Missing
|
|
70
|
+
report(`Missing @${tgName} ${usedName}`);
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
73
|
};
|
|
@@ -144,7 +150,7 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
|
|
|
144
150
|
// Could check against whitelist/blacklist
|
|
145
151
|
for (const usedName of usedNames) {
|
|
146
152
|
if (!templateNames.includes(usedName)) {
|
|
147
|
-
report(`Missing
|
|
153
|
+
report(`Missing @${tgName} ${usedName}`, null, usedNameToTag.get(usedName));
|
|
148
154
|
}
|
|
149
155
|
}
|
|
150
156
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requireTemplate.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","_jsdoccomment","e","__esModule","default","_default","exports","iterateJsdoc","context","node","report","settings","utils","avoidDocs","requireSeparateTemplates","options","mode","usedNames","Set","templateTags","getTags","templateNames","flatMap","tag","parseClosureTemplateTag","names","length","checkTypeParams","aliasDeclaration","params","typeParameters","name","add","usedName","includes","handleTypes","nde","type","declaration","usedNameToTag","Map","checkForUsedTypes","potentialTag","parsedType","tryParseType","parseType","traverse","value","test","has","set","checkTagsAndTemplates","tagNames","tagName","preferredTagName","getPreferredTagName","matchingTags","matchingTag","get","callbackTags","functionTags","typedefTags","potentialTypedef","iterateAllJsdocs","meta","docs","description","url","schema","additionalProperties","properties","exemptedBy","items","module"],"sources":["../../src/rules/requireTemplate.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\nimport {\n parse as parseType,\n traverse,\n tryParse as tryParseType,\n} from '@es-joy/jsdoccomment';\n\nexport default iterateJsdoc(({\n context,\n node,\n report,\n settings,\n utils,\n}) => {\n if (utils.avoidDocs()) {\n return;\n }\n\n const {\n requireSeparateTemplates = false,\n } = context.options[0] || {};\n\n const {\n mode,\n } = settings;\n\n const usedNames = new Set();\n const templateTags = utils.getTags('template');\n const templateNames = templateTags.flatMap((tag) => {\n return utils.parseClosureTemplateTag(tag);\n });\n\n if (requireSeparateTemplates) {\n for (const tag of templateTags) {\n const names = utils.parseClosureTemplateTag(tag);\n if (names.length > 1) {\n report(`Missing separate @template for ${names[1]}`, null, tag);\n }\n }\n }\n\n /**\n * @param {import('@typescript-eslint/types').TSESTree.FunctionDeclaration|\n * import('@typescript-eslint/types').TSESTree.ClassDeclaration|\n * import('@typescript-eslint/types').TSESTree.TSDeclareFunction|\n * import('@typescript-eslint/types').TSESTree.TSInterfaceDeclaration|\n * import('@typescript-eslint/types').TSESTree.TSTypeAliasDeclaration} aliasDeclaration\n */\n const checkTypeParams = (aliasDeclaration) => {\n const {\n params,\n /* c8 ignore next -- Guard */\n } = aliasDeclaration.typeParameters ?? {\n /* c8 ignore next -- Guard */\n params: [],\n };\n for (const {\n name: {\n name,\n },\n } of params) {\n usedNames.add(name);\n }\n\n for (const usedName of usedNames) {\n if (!templateNames.includes(usedName)) {\n report(`Missing @template ${usedName}`);\n }\n }\n };\n\n const handleTypes = () => {\n const nde = /** @type {import('@typescript-eslint/types').TSESTree.Node} */ (\n node\n );\n if (!nde) {\n return;\n }\n\n switch (nde.type) {\n case 'ClassDeclaration':\n case 'FunctionDeclaration':\n case 'TSDeclareFunction':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n checkTypeParams(nde);\n break;\n case 'ExportDefaultDeclaration':\n switch (nde.declaration?.type) {\n case 'ClassDeclaration':\n case 'FunctionDeclaration':\n case 'TSInterfaceDeclaration':\n checkTypeParams(nde.declaration);\n break;\n }\n\n break;\n case 'ExportNamedDeclaration':\n switch (nde.declaration?.type) {\n case 'ClassDeclaration':\n case 'FunctionDeclaration':\n case 'TSDeclareFunction':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n checkTypeParams(nde.declaration);\n break;\n }\n\n break;\n }\n };\n\n const usedNameToTag = new Map();\n\n /**\n * @param {import('comment-parser').Spec} potentialTag\n */\n const checkForUsedTypes = (potentialTag) => {\n let parsedType;\n try {\n parsedType = mode === 'permissive' ?\n tryParseType(/** @type {string} */ (potentialTag.type)) :\n parseType(/** @type {string} */ (potentialTag.type), mode);\n } catch {\n return;\n }\n\n traverse(parsedType, (nde) => {\n const {\n type,\n value,\n } = /** @type {import('jsdoc-type-pratt-parser').NameResult} */ (nde);\n if (type === 'JsdocTypeName' && (/^[A-Z]$/v).test(value)) {\n usedNames.add(value);\n if (!usedNameToTag.has(value)) {\n usedNameToTag.set(value, potentialTag);\n }\n }\n });\n };\n\n /**\n * @param {string[]} tagNames\n */\n const checkTagsAndTemplates = (tagNames) => {\n for (const tagName of tagNames) {\n const preferredTagName = /** @type {string} */ (utils.getPreferredTagName({\n tagName,\n }));\n const matchingTags = utils.getTags(preferredTagName);\n for (const matchingTag of matchingTags) {\n checkForUsedTypes(matchingTag);\n }\n }\n\n // Could check against whitelist/blacklist\n for (const usedName of usedNames) {\n if (!templateNames.includes(usedName)) {\n report(`Missing @template ${usedName}`, null, usedNameToTag.get(usedName));\n }\n }\n };\n\n const callbackTags = utils.getTags('callback');\n const functionTags = utils.getTags('function');\n if (callbackTags.length || functionTags.length) {\n checkTagsAndTemplates([\n 'param', 'returns',\n ]);\n return;\n }\n\n const typedefTags = utils.getTags('typedef');\n if (!typedefTags.length || typedefTags.length >= 2) {\n handleTypes();\n return;\n }\n\n const potentialTypedef = typedefTags[0];\n checkForUsedTypes(potentialTypedef);\n\n checkTagsAndTemplates([\n 'property',\n ]);\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Requires `@template` tags be present when type parameters are used.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-template.md#repos-sticky-header',\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n exemptedBy: {\n description: `Array of tags (e.g., \\`['type']\\`) whose presence on the document\nblock avoids the need for a \\`@template\\`. Defaults to an array with\n\\`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 requireSeparateTemplates: {\n description: `Requires that each template have its own separate line, i.e., preventing\ntemplates of this format:\n\n\\`\\`\\`js\n/**\n * @template T, U, V\n */\n\\`\\`\\`\n\nDefaults to \\`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;AACA,IAAAC,aAAA,GAAAD,OAAA;AAI8B,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAEf,IAAAG,qBAAY,EAAC,CAAC;EAC3BC,OAAO;EACPC,IAAI;EACJC,MAAM;EACNC,QAAQ;EACRC;AACF,CAAC,KAAK;EACJ,IAAIA,KAAK,CAACC,SAAS,CAAC,CAAC,EAAE;IACrB;EACF;EAEA,MAAM;IACJC,wBAAwB,GAAG;EAC7B,CAAC,GAAGN,OAAO,CAACO,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;EAE5B,MAAM;IACJC;EACF,CAAC,GAAGL,QAAQ;EAEZ,MAAMM,SAAS,GAAG,IAAIC,GAAG,CAAC,CAAC;EAC3B,MAAMC,YAAY,GAAGP,KAAK,CAACQ,OAAO,CAAC,UAAU,CAAC;EAC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C,GAAG,EAAE;IACP,CAAC;IACDC,MAAM,EAAE,CACN;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACVC,UAAU,EAAE;UACVL,WAAW,EAAE;AACzB;AACA;AACA;AACA,uBAAuB;UACXM,KAAK,EAAE;YACLnC,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR,CAAC;QACDvB,wBAAwB,EAAE;UACxBoD,WAAW,EAAE;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uBAAuB;UACX7B,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAoC,MAAA,CAAAnE,OAAA,GAAAA,OAAA,CAAAF,OAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"requireTemplate.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","_jsdoccomment","e","__esModule","default","_default","exports","iterateJsdoc","context","node","report","settings","utils","avoidDocs","requireSeparateTemplates","options","mode","usedNames","Set","tgName","getPreferredTagName","tagName","templateTags","getTags","templateNames","flatMap","tag","parseClosureTemplateTag","names","length","checkTypeParams","aliasDeclaration","params","typeParameters","name","add","usedName","includes","handleTypes","nde","type","declaration","usedNameToTag","Map","checkForUsedTypes","potentialTag","parsedType","tryParseType","parseType","traverse","value","test","has","set","checkTagsAndTemplates","tagNames","preferredTagName","matchingTags","matchingTag","get","callbackTags","functionTags","typedefTags","potentialTypedef","iterateAllJsdocs","meta","docs","description","url","schema","additionalProperties","properties","exemptedBy","items","module"],"sources":["../../src/rules/requireTemplate.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\nimport {\n parse as parseType,\n traverse,\n tryParse as tryParseType,\n} from '@es-joy/jsdoccomment';\n\nexport default iterateJsdoc(({\n context,\n node,\n report,\n settings,\n utils,\n}) => {\n if (utils.avoidDocs()) {\n return;\n }\n\n const {\n requireSeparateTemplates = false,\n } = context.options[0] || {};\n\n const {\n mode,\n } = settings;\n\n const usedNames = new Set();\n\n const tgName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'template',\n }));\n if (!tgName) {\n return;\n }\n\n const templateTags = utils.getTags(tgName);\n\n const templateNames = templateTags.flatMap((tag) => {\n return utils.parseClosureTemplateTag(tag);\n });\n\n if (requireSeparateTemplates) {\n for (const tag of templateTags) {\n const names = utils.parseClosureTemplateTag(tag);\n if (names.length > 1) {\n report(`Missing separate @${tgName} for ${names[1]}`, null, tag);\n }\n }\n }\n\n /**\n * @param {import('@typescript-eslint/types').TSESTree.FunctionDeclaration|\n * import('@typescript-eslint/types').TSESTree.ClassDeclaration|\n * import('@typescript-eslint/types').TSESTree.TSDeclareFunction|\n * import('@typescript-eslint/types').TSESTree.TSInterfaceDeclaration|\n * import('@typescript-eslint/types').TSESTree.TSTypeAliasDeclaration} aliasDeclaration\n */\n const checkTypeParams = (aliasDeclaration) => {\n const {\n params,\n /* c8 ignore next -- Guard */\n } = aliasDeclaration.typeParameters ?? {\n /* c8 ignore next -- Guard */\n params: [],\n };\n for (const {\n name: {\n name,\n },\n } of params) {\n usedNames.add(name);\n }\n\n for (const usedName of usedNames) {\n if (!templateNames.includes(usedName)) {\n report(`Missing @${tgName} ${usedName}`);\n }\n }\n };\n\n const handleTypes = () => {\n const nde = /** @type {import('@typescript-eslint/types').TSESTree.Node} */ (\n node\n );\n if (!nde) {\n return;\n }\n\n switch (nde.type) {\n case 'ClassDeclaration':\n case 'FunctionDeclaration':\n case 'TSDeclareFunction':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n checkTypeParams(nde);\n break;\n case 'ExportDefaultDeclaration':\n switch (nde.declaration?.type) {\n case 'ClassDeclaration':\n case 'FunctionDeclaration':\n case 'TSInterfaceDeclaration':\n checkTypeParams(nde.declaration);\n break;\n }\n\n break;\n case 'ExportNamedDeclaration':\n switch (nde.declaration?.type) {\n case 'ClassDeclaration':\n case 'FunctionDeclaration':\n case 'TSDeclareFunction':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n checkTypeParams(nde.declaration);\n break;\n }\n\n break;\n }\n };\n\n const usedNameToTag = new Map();\n\n /**\n * @param {import('comment-parser').Spec} potentialTag\n */\n const checkForUsedTypes = (potentialTag) => {\n let parsedType;\n try {\n parsedType = mode === 'permissive' ?\n tryParseType(/** @type {string} */ (potentialTag.type)) :\n parseType(/** @type {string} */ (potentialTag.type), mode);\n } catch {\n return;\n }\n\n traverse(parsedType, (nde) => {\n const {\n type,\n value,\n } = /** @type {import('jsdoc-type-pratt-parser').NameResult} */ (nde);\n if (type === 'JsdocTypeName' && (/^[A-Z]$/v).test(value)) {\n usedNames.add(value);\n if (!usedNameToTag.has(value)) {\n usedNameToTag.set(value, potentialTag);\n }\n }\n });\n };\n\n /**\n * @param {string[]} tagNames\n */\n const checkTagsAndTemplates = (tagNames) => {\n for (const tagName of tagNames) {\n const preferredTagName = /** @type {string} */ (utils.getPreferredTagName({\n tagName,\n }));\n const matchingTags = utils.getTags(preferredTagName);\n for (const matchingTag of matchingTags) {\n checkForUsedTypes(matchingTag);\n }\n }\n\n // Could check against whitelist/blacklist\n for (const usedName of usedNames) {\n if (!templateNames.includes(usedName)) {\n report(`Missing @${tgName} ${usedName}`, null, usedNameToTag.get(usedName));\n }\n }\n };\n\n const callbackTags = utils.getTags('callback');\n const functionTags = utils.getTags('function');\n if (callbackTags.length || functionTags.length) {\n checkTagsAndTemplates([\n 'param', 'returns',\n ]);\n return;\n }\n\n const typedefTags = utils.getTags('typedef');\n if (!typedefTags.length || typedefTags.length >= 2) {\n handleTypes();\n return;\n }\n\n const potentialTypedef = typedefTags[0];\n checkForUsedTypes(potentialTypedef);\n\n checkTagsAndTemplates([\n 'property',\n ]);\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Requires `@template` tags be present when type parameters are used.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-template.md#repos-sticky-header',\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n exemptedBy: {\n description: `Array of tags (e.g., \\`['type']\\`) whose presence on the document\nblock avoids the need for a \\`@template\\`. Defaults to an array with\n\\`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 requireSeparateTemplates: {\n description: `Requires that each template have its own separate line, i.e., preventing\ntemplates of this format:\n\n\\`\\`\\`js\n/**\n * @template T, U, V\n */\n\\`\\`\\`\n\nDefaults to \\`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;AACA,IAAAC,aAAA,GAAAD,OAAA;AAI8B,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAEf,IAAAG,qBAAY,EAAC,CAAC;EAC3BC,OAAO;EACPC,IAAI;EACJC,MAAM;EACNC,QAAQ;EACRC;AACF,CAAC,KAAK;EACJ,IAAIA,KAAK,CAACC,SAAS,CAAC,CAAC,EAAE;IACrB;EACF;EAEA,MAAM;IACJC,wBAAwB,GAAG;EAC7B,CAAC,GAAGN,OAAO,CAACO,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;EAE5B,MAAM;IACJC;EACF,CAAC,GAAGL,QAAQ;EAEZ,MAAMM,SAAS,GAAG,IAAIC,GAAG,CAAC,CAAC;EAE3B,MAAMC,MAAM,GAAG,qBAAuBP,KAAK,CAACQ,mBAAmB,CAAC;IAC9DC,OAAO,EAAE;EACX,CAAC,CAAE;EACH,IAAI,CAACF,MAAM,EAAE;IACX;EACF;EAEA,MAAMG,YAAY,GAAGV,KAAK,CAAC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EACtBC,IAAI,EAAE;IACJC,IAAI,EAAE;MACJC,WAAW,EAAE,qEAAqE;MAClFC,GAAG,EAAE;IACP,CAAC;IACDC,MAAM,EAAE,CACN;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACVC,UAAU,EAAE;UACVL,WAAW,EAAE;AACzB;AACA;AACA;AACA,uBAAuB;UACXM,KAAK,EAAE;YACLjC,IAAI,EAAE;UACR,CAAC;UACDA,IAAI,EAAE;QACR,CAAC;QACD1B,wBAAwB,EAAE;UACxBqD,WAAW,EAAE;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uBAAuB;UACX3B,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAkC,MAAA,CAAApE,OAAA,GAAAA,OAAA,CAAAF,OAAA","ignoreList":[]}
|
package/dist/tagNames.cjs
CHANGED
|
@@ -112,8 +112,10 @@ const typeScriptTags = exports.typeScriptTags = {
|
|
|
112
112
|
// https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#satisfies-support-in-jsdoc
|
|
113
113
|
satisfies: [],
|
|
114
114
|
// `@template` is also in TypeScript per:
|
|
115
|
-
// https://www.typescriptlang.org/docs/handbook/
|
|
116
|
-
template: [
|
|
115
|
+
// https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#template
|
|
116
|
+
template: [
|
|
117
|
+
// Alias as per https://typedoc.org/documents/Tags._typeParam.html
|
|
118
|
+
'typeParam']
|
|
117
119
|
};
|
|
118
120
|
|
|
119
121
|
/**
|
package/dist/tagNames.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tagNames.cjs","names":["jsdocTagsUndocumented","modifies","jsdocTags","exports","abstract","access","alias","async","augments","author","borrows","callback","class","classdesc","constant","constructs","copyright","default","deprecated","description","enum","event","example","external","file","fires","function","generator","global","hideconstructor","ignore","implements","inheritdoc","inheritDoc","inner","instance","interface","kind","lends","license","listens","member","memberof","mixes","mixin","module","name","namespace","override","package","param","private","property","protected","public","readonly","requires","returns","see","since","static","summary","this","throws","todo","tutorial","type","typedef","variation","version","yields","typeScriptTags","import","internal","overload","satisfies","template","undocumentedClosureTags","closurePrimitive","customElement","expose","hidden","idGenerator","meaning","mixinClass","mixinFunction","ngInject","owner","typeSummary","wizaction","typeScriptTagsInClosure","closureTags","define","dict","export","externs","final","implicitCast","noalias","nocollapse","nocompile","noinline","nosideeffects","polymer","polymerBehavior","preserve","record","return","struct","suppress","unrestricted"],"sources":["../src/tagNames.js"],"sourcesContent":["/**\n * @typedef {{\n * [key: string]: string[]\n * }} AliasedTags\n */\n\n/**\n * @type {AliasedTags}\n */\nconst jsdocTagsUndocumented = {\n // Undocumented but present; see\n // https://github.com/jsdoc/jsdoc/issues/1283#issuecomment-516816802\n // https://github.com/jsdoc/jsdoc/blob/master/packages/jsdoc/lib/jsdoc/tag/dictionary/definitions.js#L594\n modifies: [],\n};\n\n/**\n * @type {AliasedTags}\n */\nconst jsdocTags = {\n ...jsdocTagsUndocumented,\n abstract: [\n 'virtual',\n ],\n access: [],\n alias: [],\n async: [],\n augments: [\n 'extends',\n ],\n author: [],\n borrows: [],\n callback: [],\n class: [\n 'constructor',\n ],\n classdesc: [],\n constant: [\n 'const',\n ],\n constructs: [],\n copyright: [],\n default: [\n 'defaultvalue',\n ],\n deprecated: [],\n description: [\n 'desc',\n ],\n enum: [],\n event: [],\n example: [],\n exports: [],\n external: [\n 'host',\n ],\n file: [\n 'fileoverview',\n 'overview',\n ],\n fires: [\n 'emits',\n ],\n function: [\n 'func',\n 'method',\n ],\n generator: [],\n global: [],\n hideconstructor: [],\n ignore: [],\n implements: [],\n inheritdoc: [],\n\n // Allowing casing distinct from jsdoc `definitions.js` (required in Closure)\n inheritDoc: [],\n\n inner: [],\n instance: [],\n interface: [],\n kind: [],\n lends: [],\n license: [],\n listens: [],\n member: [\n 'var',\n ],\n memberof: [],\n 'memberof!': [],\n mixes: [],\n mixin: [],\n\n module: [],\n name: [],\n namespace: [],\n override: [],\n package: [],\n param: [\n 'arg',\n 'argument',\n ],\n private: [],\n property: [\n 'prop',\n ],\n protected: [],\n public: [],\n readonly: [],\n requires: [],\n returns: [\n 'return',\n ],\n see: [],\n since: [],\n static: [],\n summary: [],\n\n this: [],\n throws: [\n 'exception',\n ],\n todo: [],\n tutorial: [],\n type: [],\n typedef: [],\n variation: [],\n version: [],\n yields: [\n 'yield',\n ],\n};\n\n/**\n * @type {AliasedTags}\n */\nconst typeScriptTags = {\n ...jsdocTags,\n\n // https://github.com/microsoft/TypeScript/issues/22160\n // https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#the-jsdoc-import-tag\n import: [],\n\n // https://www.typescriptlang.org/tsconfig/#stripInternal\n internal: [],\n\n // https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#overload-support-in-jsdoc\n overload: [],\n\n // https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#satisfies-support-in-jsdoc\n satisfies: [],\n\n // `@template` is also in TypeScript per:\n // https://www.typescriptlang.org/docs/handbook/
|
|
1
|
+
{"version":3,"file":"tagNames.cjs","names":["jsdocTagsUndocumented","modifies","jsdocTags","exports","abstract","access","alias","async","augments","author","borrows","callback","class","classdesc","constant","constructs","copyright","default","deprecated","description","enum","event","example","external","file","fires","function","generator","global","hideconstructor","ignore","implements","inheritdoc","inheritDoc","inner","instance","interface","kind","lends","license","listens","member","memberof","mixes","mixin","module","name","namespace","override","package","param","private","property","protected","public","readonly","requires","returns","see","since","static","summary","this","throws","todo","tutorial","type","typedef","variation","version","yields","typeScriptTags","import","internal","overload","satisfies","template","undocumentedClosureTags","closurePrimitive","customElement","expose","hidden","idGenerator","meaning","mixinClass","mixinFunction","ngInject","owner","typeSummary","wizaction","typeScriptTagsInClosure","closureTags","define","dict","export","externs","final","implicitCast","noalias","nocollapse","nocompile","noinline","nosideeffects","polymer","polymerBehavior","preserve","record","return","struct","suppress","unrestricted"],"sources":["../src/tagNames.js"],"sourcesContent":["/**\n * @typedef {{\n * [key: string]: string[]\n * }} AliasedTags\n */\n\n/**\n * @type {AliasedTags}\n */\nconst jsdocTagsUndocumented = {\n // Undocumented but present; see\n // https://github.com/jsdoc/jsdoc/issues/1283#issuecomment-516816802\n // https://github.com/jsdoc/jsdoc/blob/master/packages/jsdoc/lib/jsdoc/tag/dictionary/definitions.js#L594\n modifies: [],\n};\n\n/**\n * @type {AliasedTags}\n */\nconst jsdocTags = {\n ...jsdocTagsUndocumented,\n abstract: [\n 'virtual',\n ],\n access: [],\n alias: [],\n async: [],\n augments: [\n 'extends',\n ],\n author: [],\n borrows: [],\n callback: [],\n class: [\n 'constructor',\n ],\n classdesc: [],\n constant: [\n 'const',\n ],\n constructs: [],\n copyright: [],\n default: [\n 'defaultvalue',\n ],\n deprecated: [],\n description: [\n 'desc',\n ],\n enum: [],\n event: [],\n example: [],\n exports: [],\n external: [\n 'host',\n ],\n file: [\n 'fileoverview',\n 'overview',\n ],\n fires: [\n 'emits',\n ],\n function: [\n 'func',\n 'method',\n ],\n generator: [],\n global: [],\n hideconstructor: [],\n ignore: [],\n implements: [],\n inheritdoc: [],\n\n // Allowing casing distinct from jsdoc `definitions.js` (required in Closure)\n inheritDoc: [],\n\n inner: [],\n instance: [],\n interface: [],\n kind: [],\n lends: [],\n license: [],\n listens: [],\n member: [\n 'var',\n ],\n memberof: [],\n 'memberof!': [],\n mixes: [],\n mixin: [],\n\n module: [],\n name: [],\n namespace: [],\n override: [],\n package: [],\n param: [\n 'arg',\n 'argument',\n ],\n private: [],\n property: [\n 'prop',\n ],\n protected: [],\n public: [],\n readonly: [],\n requires: [],\n returns: [\n 'return',\n ],\n see: [],\n since: [],\n static: [],\n summary: [],\n\n this: [],\n throws: [\n 'exception',\n ],\n todo: [],\n tutorial: [],\n type: [],\n typedef: [],\n variation: [],\n version: [],\n yields: [\n 'yield',\n ],\n};\n\n/**\n * @type {AliasedTags}\n */\nconst typeScriptTags = {\n ...jsdocTags,\n\n // https://github.com/microsoft/TypeScript/issues/22160\n // https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#the-jsdoc-import-tag\n import: [],\n\n // https://www.typescriptlang.org/tsconfig/#stripInternal\n internal: [],\n\n // https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#overload-support-in-jsdoc\n overload: [],\n\n // https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#satisfies-support-in-jsdoc\n satisfies: [],\n\n // `@template` is also in TypeScript per:\n // https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#template\n template: [\n // Alias as per https://typedoc.org/documents/Tags._typeParam.html\n 'typeParam',\n ],\n};\n\n/**\n * @type {AliasedTags}\n */\nconst undocumentedClosureTags = {\n // These are in Closure source but not in jsdoc source nor in the Closure\n // docs: https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/parsing/Annotation.java\n closurePrimitive: [],\n customElement: [],\n expose: [],\n hidden: [],\n idGenerator: [],\n meaning: [],\n mixinClass: [],\n mixinFunction: [],\n ngInject: [],\n owner: [],\n typeSummary: [],\n wizaction: [],\n};\n\nconst {\n /* eslint-disable no-unused-vars */\n inheritdoc,\n internal,\n overload,\n // Will be inverted to prefer `return`\n returns,\n\n satisfies,\n /* eslint-enable no-unused-vars */\n ...typeScriptTagsInClosure\n} = typeScriptTags;\n\n/**\n * @type {AliasedTags}\n */\nconst closureTags = {\n ...typeScriptTagsInClosure,\n ...undocumentedClosureTags,\n\n // From https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler\n // These are all recognized in https://github.com/jsdoc/jsdoc/blob/master/packages/jsdoc/lib/jsdoc/tag/dictionary/definitions.js\n // except for the experimental `noinline` and the casing differences noted below\n\n // Defined as a synonym of `const` in jsdoc `definitions.js`\n define: [],\n\n dict: [],\n export: [],\n externs: [],\n final: [],\n\n // With casing distinct from jsdoc `definitions.js`\n implicitCast: [],\n\n noalias: [],\n nocollapse: [],\n nocompile: [],\n noinline: [],\n nosideeffects: [],\n polymer: [],\n polymerBehavior: [],\n preserve: [],\n\n // Defined as a synonym of `interface` in jsdoc `definitions.js`\n record: [],\n\n return: [\n 'returns',\n ],\n\n struct: [],\n suppress: [],\n\n unrestricted: [],\n};\n\nexport {\n closureTags,\n jsdocTags,\n typeScriptTags,\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,MAAMA,qBAAqB,GAAG;EAC5B;EACA;EACA;EACAC,QAAQ,EAAE;AACZ,CAAC;;AAED;AACA;AACA;AACA,MAAMC,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG;EAChB,GAAGF,qBAAqB;EACxBI,QAAQ,EAAE,CACR,SAAS,CACV;EACDC,MAAM,EAAE,EAAE;EACVC,KAAK,EAAE,EAAE;EACTC,KAAK,EAAE,EAAE;EACTC,QAAQ,EAAE,CACR,SAAS,CACV;EACDC,MAAM,EAAE,EAAE;EACVC,OAAO,EAAE,EAAE;EACXC,QAAQ,EAAE,EAAE;EACZC,KAAK,EAAE,CACL,aAAa,CACd;EACDC,SAAS,EAAE,EAAE;EACbC,QAAQ,EAAE,CACR,OAAO,CACR;EACDC,UAAU,EAAE,EAAE;EACdC,SAAS,EAAE,EAAE;EACbC,OAAO,EAAE,CACP,cAAc,CACf;EACDC,UAAU,EAAE,EAAE;EACdC,WAAW,EAAE,CACX,MAAM,CACP;EACDC,IAAI,EAAE,EAAE;EACRC,KAAK,EAAE,EAAE;EACTC,OAAO,EAAE,EAAE;EACXnB,OAAO,EAAE,EAAE;EACXoB,QAAQ,EAAE,CACR,MAAM,CACP;EACDC,IAAI,EAAE,CACJ,cAAc,EACd,UAAU,CACX;EACDC,KAAK,EAAE,CACL,OAAO,CACR;EACDC,QAAQ,EAAE,CACR,MAAM,EACN,QAAQ,CACT;EACDC,SAAS,EAAE,EAAE;EACbC,MAAM,EAAE,EAAE;EACVC,eAAe,EAAE,EAAE;EACnBC,M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EAAE;EAEZC,YAAY,EAAE;AAChB,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -23,7 +23,14 @@ export default iterateJsdoc(({
|
|
|
23
23
|
mode,
|
|
24
24
|
} = settings;
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const tgName = /** @type {string} */ (utils.getPreferredTagName({
|
|
27
|
+
tagName: 'template',
|
|
28
|
+
}));
|
|
29
|
+
if (!tgName) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const templateTags = utils.getTags(tgName);
|
|
27
34
|
|
|
28
35
|
const usedNames = new Set();
|
|
29
36
|
/**
|
|
@@ -73,7 +80,7 @@ export default iterateJsdoc(({
|
|
|
73
80
|
const names = utils.parseClosureTemplateTag(tag);
|
|
74
81
|
for (const nme of names) {
|
|
75
82
|
if (!usedNames.has(nme)) {
|
|
76
|
-
report(
|
|
83
|
+
report(`@${tgName} ${nme} not in use`, null, tag);
|
|
77
84
|
}
|
|
78
85
|
}
|
|
79
86
|
}
|
|
@@ -25,7 +25,16 @@ export default iterateJsdoc(({
|
|
|
25
25
|
} = settings;
|
|
26
26
|
|
|
27
27
|
const usedNames = new Set();
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
const tgName = /** @type {string} */ (utils.getPreferredTagName({
|
|
30
|
+
tagName: 'template',
|
|
31
|
+
}));
|
|
32
|
+
if (!tgName) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const templateTags = utils.getTags(tgName);
|
|
37
|
+
|
|
29
38
|
const templateNames = templateTags.flatMap((tag) => {
|
|
30
39
|
return utils.parseClosureTemplateTag(tag);
|
|
31
40
|
});
|
|
@@ -34,7 +43,7 @@ export default iterateJsdoc(({
|
|
|
34
43
|
for (const tag of templateTags) {
|
|
35
44
|
const names = utils.parseClosureTemplateTag(tag);
|
|
36
45
|
if (names.length > 1) {
|
|
37
|
-
report(`Missing separate
|
|
46
|
+
report(`Missing separate @${tgName} for ${names[1]}`, null, tag);
|
|
38
47
|
}
|
|
39
48
|
}
|
|
40
49
|
}
|
|
@@ -64,7 +73,7 @@ export default iterateJsdoc(({
|
|
|
64
73
|
|
|
65
74
|
for (const usedName of usedNames) {
|
|
66
75
|
if (!templateNames.includes(usedName)) {
|
|
67
|
-
report(`Missing
|
|
76
|
+
report(`Missing @${tgName} ${usedName}`);
|
|
68
77
|
}
|
|
69
78
|
}
|
|
70
79
|
};
|
|
@@ -156,7 +165,7 @@ export default iterateJsdoc(({
|
|
|
156
165
|
// Could check against whitelist/blacklist
|
|
157
166
|
for (const usedName of usedNames) {
|
|
158
167
|
if (!templateNames.includes(usedName)) {
|
|
159
|
-
report(`Missing
|
|
168
|
+
report(`Missing @${tgName} ${usedName}`, null, usedNameToTag.get(usedName));
|
|
160
169
|
}
|
|
161
170
|
}
|
|
162
171
|
};
|
package/src/tagNames.js
CHANGED
|
@@ -150,8 +150,11 @@ const typeScriptTags = {
|
|
|
150
150
|
satisfies: [],
|
|
151
151
|
|
|
152
152
|
// `@template` is also in TypeScript per:
|
|
153
|
-
// https://www.typescriptlang.org/docs/handbook/
|
|
154
|
-
template: [
|
|
153
|
+
// https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#template
|
|
154
|
+
template: [
|
|
155
|
+
// Alias as per https://typedoc.org/documents/Tags._typeParam.html
|
|
156
|
+
'typeParam',
|
|
157
|
+
],
|
|
155
158
|
};
|
|
156
159
|
|
|
157
160
|
/**
|