eslint-plugin-jsdoc 38.1.3 → 38.1.4
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/README.md
CHANGED
|
@@ -9889,6 +9889,18 @@ function foo () {
|
|
|
9889
9889
|
}
|
|
9890
9890
|
// Settings: {"jsdoc":{"mode":"jsdoc"}}
|
|
9891
9891
|
// Message: The type 'visibility' is undefined.
|
|
9892
|
+
|
|
9893
|
+
/**
|
|
9894
|
+
* @typedef Todo
|
|
9895
|
+
* @property description
|
|
9896
|
+
* @property otherStuff
|
|
9897
|
+
*/
|
|
9898
|
+
/**
|
|
9899
|
+
* @type {Omit<Todo, "description">}
|
|
9900
|
+
*/
|
|
9901
|
+
const a = new Todo();
|
|
9902
|
+
// Settings: {"jsdoc":{"mode":"jsdoc"}}
|
|
9903
|
+
// Message: The type 'Omit' is undefined.
|
|
9892
9904
|
````
|
|
9893
9905
|
|
|
9894
9906
|
The following patterns are not considered problems:
|
|
@@ -10302,6 +10314,17 @@ export class Foo {
|
|
|
10302
10314
|
* @type {const}
|
|
10303
10315
|
*/
|
|
10304
10316
|
const a = 'string';
|
|
10317
|
+
|
|
10318
|
+
/**
|
|
10319
|
+
* @typedef Todo
|
|
10320
|
+
* @property description
|
|
10321
|
+
* @property otherStuff
|
|
10322
|
+
*/
|
|
10323
|
+
/**
|
|
10324
|
+
* @type {Omit<Todo, "description">}
|
|
10325
|
+
*/
|
|
10326
|
+
const a = new Todo();
|
|
10327
|
+
// Settings: {"jsdoc":{"mode":"typescript"}}
|
|
10305
10328
|
````
|
|
10306
10329
|
|
|
10307
10330
|
|
|
@@ -17,7 +17,9 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
17
17
|
|
|
18
18
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
19
|
|
|
20
|
-
const extraTypes = ['null', 'undefined', 'void', 'string', 'boolean', 'object', 'function', 'symbol', 'number', 'bigint', 'NaN', 'Infinity', 'any', '*', 'never', 'unknown', 'const', 'this', 'true', 'false', 'Array', 'Object', 'RegExp', 'Date', 'Function'];
|
|
20
|
+
const extraTypes = ['null', 'undefined', 'void', 'string', 'boolean', 'object', 'function', 'symbol', 'number', 'bigint', 'NaN', 'Infinity', 'any', '*', 'never', 'unknown', 'const', 'this', 'true', 'false', 'Array', 'Object', 'RegExp', 'Date', 'Function']; // https://www.typescriptlang.org/docs/handbook/utility-types.html
|
|
21
|
+
|
|
22
|
+
const typescriptGlobals = ['Partial', 'Required', 'Readonly', 'Record', 'Pick', 'Omit', 'Exclude', 'Extract', 'NonNullable', 'Parameters', 'ConstructorParameters', 'ReturnType', 'InstanceType', 'ThisParameterType', 'OmitThisParameter', 'ThisType', 'Uppercase', 'Lowercase', 'Capitalize', 'Uncapitalize'];
|
|
21
23
|
|
|
22
24
|
const stripPseudoTypes = str => {
|
|
23
25
|
return str && str.replace(/(?:\.|<>|\.<>|\[\])$/u, '');
|
|
@@ -130,7 +132,7 @@ var _default = (0, _iterateJsdoc.default)(({
|
|
|
130
132
|
name
|
|
131
133
|
}) => {
|
|
132
134
|
return name;
|
|
133
|
-
}) : []).concat(extraTypes).concat(typedefDeclarations).concat(definedTypes).concat(definedPreferredTypes).concat(settings.mode === 'jsdoc' ? [] : closureGenericTypes));
|
|
135
|
+
}) : []).concat(extraTypes).concat(typedefDeclarations).concat(definedTypes).concat(definedPreferredTypes).concat(settings.mode === 'jsdoc' ? [] : [...(settings.mode === 'typescript' ? typescriptGlobals : []), ...closureGenericTypes]));
|
|
134
136
|
const jsdocTagsWithPossibleType = utils.filterTags(({
|
|
135
137
|
tag
|
|
136
138
|
}) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/rules/noUndefinedTypes.js"],"names":["extraTypes","stripPseudoTypes","str","replace","context","node","report","settings","sourceCode","utils","scopeManager","globalScope","definedTypes","options","definedPreferredTypes","preferredTypes","structuredTags","mode","Object","keys","length","values","map","preferredType","undefined","reportSettings","replacement","filter","typedefDeclarations","getAllComments","comment","test","value","commentNode","flatMap","doc","tags","tag","isNamepathDefiningTag","name","ancestorNodes","currentNode","parent","push","getTemplateTags","ancestorNode","jsdoc","jsdocUtils","filterTags","templateTags","getPresentTags","closureGenericTypes","parseClosureTemplateTag","cjsOrESMScope","childScopes","block","type","allDefinedTypes","Set","variables","concat","jsdocTagsWithPossibleType","tagMightHaveTypePosition","parsedType","structuredTypes","has","Array","isArray","includes","markVariableAsUsed","iterateAllJsdocs","meta","docs","description","url","schema","additionalProperties","properties","items"],"mappings":";;;;;;;AAAA;;AAOA;;AAGA;;;;;;;;AAEA,MAAMA,UAAU,GAAG,CACjB,MADiB,EACT,WADS,EACI,MADJ,EACY,QADZ,EACsB,SADtB,EACiC,QADjC,EAEjB,UAFiB,EAEL,QAFK,EAGjB,QAHiB,EAGP,QAHO,EAGG,KAHH,EAGU,UAHV,EAIjB,KAJiB,EAIV,GAJU,EAIL,OAJK,EAII,SAJJ,EAIe,OAJf,EAKjB,MALiB,EAKT,MALS,EAKD,OALC,EAMjB,OANiB,EAMR,QANQ,EAME,QANF,EAMY,MANZ,EAMoB,UANpB,CAAnB;;AASA,MAAMC,gBAAgB,GAAIC,GAAD,IAAS;AAChC,SAAOA,GAAG,IAAIA,GAAG,CAACC,OAAJ,CAAY,uBAAZ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EAAE;AACVjE,QAAAA,YAAY,EAAE;AACZkE,UAAAA,KAAK,EAAE;AACLtB,YAAAA,IAAI,EAAE;AADD,WADK;AAIZA,UAAAA,IAAI,EAAE;AAJM;AADJ,OAFd;AAUEA,MAAAA,IAAI,EAAE;AAVR,KADM,CALJ;AAmBJA,IAAAA,IAAI,EAAE;AAnBF;AAFL,CAlKY,C","sourcesContent":["import {\n getJSDocComment,\n\n traverse,\n parse as parseType,\n tryParse as tryParseType,\n} from '@es-joy/jsdoccomment';\nimport iterateJsdoc, {\n parseComment,\n} from '../iterateJsdoc';\nimport jsdocUtils from '../jsdocUtils';\n\nconst extraTypes = [\n 'null', 'undefined', 'void', 'string', 'boolean', 'object',\n 'function', 'symbol',\n 'number', 'bigint', 'NaN', 'Infinity',\n 'any', '*', 'never', 'unknown', 'const',\n 'this', 'true', 'false',\n 'Array', 'Object', 'RegExp', 'Date', 'Function',\n];\n\nconst stripPseudoTypes = (str) => {\n return str && str.replace(/(?:\\.|<>|\\.<>|\\[\\])$/u, '');\n};\n\nexport default iterateJsdoc(({\n context,\n node,\n report,\n settings,\n sourceCode,\n utils,\n}) => {\n const {\n scopeManager,\n } = sourceCode;\n const {\n globalScope,\n } = scopeManager;\n\n const {\n definedTypes = [],\n } = context.options[0] || {};\n\n let definedPreferredTypes = [];\n const {\n preferredTypes,\n structuredTags,\n mode,\n } = settings;\n if (Object.keys(preferredTypes).length) {\n definedPreferredTypes = Object.values(preferredTypes).map((preferredType) => {\n if (typeof preferredType === 'string') {\n // May become an empty string but will be filtered out below\n return stripPseudoTypes(preferredType);\n }\n\n if (!preferredType) {\n return undefined;\n }\n\n if (typeof preferredType !== 'object') {\n utils.reportSettings(\n 'Invalid `settings.jsdoc.preferredTypes`. Values must be falsy, a string, or an object.',\n );\n }\n\n return stripPseudoTypes(preferredType.replacement);\n })\n .filter((preferredType) => {\n return preferredType;\n });\n }\n\n const typedefDeclarations = context.getAllComments()\n .filter((comment) => {\n return (/^\\*\\s/u).test(comment.value);\n })\n .map((commentNode) => {\n return parseComment(commentNode, '');\n })\n .flatMap((doc) => {\n return doc.tags.filter(({\n tag,\n }) => {\n return utils.isNamepathDefiningTag(tag);\n });\n })\n .map((tag) => {\n return tag.name;\n });\n\n const ancestorNodes = [];\n\n let currentNode = node;\n // No need for Program node?\n while (currentNode?.parent) {\n ancestorNodes.push(currentNode);\n currentNode = currentNode.parent;\n }\n\n const getTemplateTags = function (ancestorNode) {\n const commentNode = getJSDocComment(sourceCode, ancestorNode, settings);\n if (!commentNode) {\n return [];\n }\n\n const jsdoc = parseComment(commentNode, '');\n\n return jsdocUtils.filterTags(jsdoc.tags, (tag) => {\n return tag.tag === 'template';\n });\n };\n\n // `currentScope` may be `null` or `Program`, so in such a case,\n // we look to present tags instead\n const templateTags = ancestorNodes.length ?\n ancestorNodes.flatMap((ancestorNode) => {\n return getTemplateTags(ancestorNode);\n }) :\n utils.getPresentTags('template');\n\n const closureGenericTypes = templateTags.flatMap((tag) => {\n return utils.parseClosureTemplateTag(tag);\n });\n\n // In modules, including Node, there is a global scope at top with the\n // Program scope inside\n const cjsOrESMScope = globalScope.childScopes[0]?.block?.type === 'Program';\n\n const allDefinedTypes = new Set(globalScope.variables.map(({\n name,\n }) => {\n return name;\n })\n\n // If the file is a module, concat the variables from the module scope.\n .concat(\n cjsOrESMScope ?\n globalScope.childScopes.flatMap(({\n variables,\n }) => {\n return variables;\n }).map(({\n name,\n }) => {\n return name;\n }) : [],\n )\n .concat(extraTypes)\n .concat(typedefDeclarations)\n .concat(definedTypes)\n .concat(definedPreferredTypes)\n .concat(settings.mode === 'jsdoc' ? [] : closureGenericTypes));\n\n const jsdocTagsWithPossibleType = utils.filterTags(({\n tag,\n }) => {\n return utils.tagMightHaveTypePosition(tag) && (tag !== 'suppress' || settings.mode !== 'closure');\n });\n\n for (const tag of jsdocTagsWithPossibleType) {\n let parsedType;\n\n try {\n parsedType = mode === 'permissive' ? tryParseType(tag.type) : parseType(tag.type, mode);\n } catch {\n // On syntax error, will be handled by valid-types.\n continue;\n }\n\n traverse(parsedType, ({\n type,\n value,\n }) => {\n if (type === 'JsdocTypeName') {\n const structuredTypes = structuredTags[tag.tag]?.type;\n if (!allDefinedTypes.has(value) &&\n (!Array.isArray(structuredTypes) || !structuredTypes.includes(value))\n ) {\n report(`The type '${value}' is undefined.`, null, tag);\n } else if (!extraTypes.includes(value)) {\n context.markVariableAsUsed(value);\n }\n }\n });\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Checks that types in jsdoc comments are defined.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-no-undefined-types',\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n definedTypes: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"file":"noUndefinedTypes.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/rules/noUndefinedTypes.js"],"names":["extraTypes","typescriptGlobals","stripPseudoTypes","str","replace","context","node","report","settings","sourceCode","utils","scopeManager","globalScope","definedTypes","options","definedPreferredTypes","preferredTypes","structuredTags","mode","Object","keys","length","values","map","preferredType","undefined","reportSettings","replacement","filter","typedefDeclarations","getAllComments","comment","test","value","commentNode","flatMap","doc","tags","tag","isNamepathDefiningTag","name","ancestorNodes","currentNode","parent","push","getTemplateTags","ancestorNode","jsdoc","jsdocUtils","filterTags","templateTags","getPresentTags","closureGenericTypes","parseClosureTemplateTag","cjsOrESMScope","childScopes","block","type","allDefinedTypes","Set","variables","concat","jsdocTagsWithPossibleType","tagMightHaveTypePosition","parsedType","structuredTypes","has","Array","isArray","includes","markVariableAsUsed","iterateAllJsdocs","meta","docs","description","url","schema","additionalProperties","properties","items"],"mappings":";;;;;;;AAAA;;AAOA;;AAGA;;;;;;;;AAEA,MAAMA,UAAU,GAAG,CACjB,MADiB,EACT,WADS,EACI,MADJ,EACY,QADZ,EACsB,SADtB,EACiC,QADjC,EAEjB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AAMQ,eAAe,4BAAGhD,cAAc,CAACqB,GAAG,CAACA,GAAL,CAAjB,0DAAG,sBAAyBmB,IAAjD;;AACA,YAAI,CAACC,eAAe,CAACQ,GAAhB,CAAoBjC,KAApB,CAAD,KACD,CAACkC,KAAK,CAACC,OAAN,CAAcH,eAAd,CAAD,IAAmC,CAACA,eAAe,CAACI,QAAhB,CAAyBpC,KAAzB,CADnC,CAAJ,EAEE;AACA1B,UAAAA,MAAM,CAAE,aAAY0B,KAAM,iBAApB,EAAsC,IAAtC,EAA4CK,GAA5C,CAAN;AACD,SAJD,MAIO,IAAI,CAACtC,UAAU,CAACqE,QAAX,CAAoBpC,KAApB,CAAL,EAAiC;AACtC5B,UAAAA,OAAO,CAACiE,kBAAR,CAA2BrC,KAA3B;AACD;AACF;AACF,KAdD;AAeD;AACF,CAzKc,EAyKZ;AACDsC,EAAAA,gBAAgB,EAAE,IADjB;AAEDC,EAAAA,IAAI,EAAE;AACJC,IAAAA,IAAI,EAAE;AACJC,MAAAA,WAAW,EAAE,kDADT;AAEJC,MAAAA,GAAG,EAAE;AAFD,KADF;AAKJC,IAAAA,MAAM,EAAE,CACN;AACEC,MAAAA,oBAAoB,EAAE,KADxB;AAEEC,MAAAA,UAAU,EAAE;AACVjE,QAAAA,YAAY,EAAE;AACZkE,UAAAA,KAAK,EAAE;AACLtB,YAAAA,IAAI,EAAE;AADD,WADK;AAIZA,UAAAA,IAAI,EAAE;AAJM;AADJ,OAFd;AAUEA,MAAAA,IAAI,EAAE;AAVR,KADM,CALJ;AAmBJA,IAAAA,IAAI,EAAE;AAnBF;AAFL,CAzKY,C","sourcesContent":["import {\n getJSDocComment,\n\n traverse,\n parse as parseType,\n tryParse as tryParseType,\n} from '@es-joy/jsdoccomment';\nimport iterateJsdoc, {\n parseComment,\n} from '../iterateJsdoc';\nimport jsdocUtils from '../jsdocUtils';\n\nconst extraTypes = [\n 'null', 'undefined', 'void', 'string', 'boolean', 'object',\n 'function', 'symbol',\n 'number', 'bigint', 'NaN', 'Infinity',\n 'any', '*', 'never', 'unknown', 'const',\n 'this', 'true', 'false',\n 'Array', 'Object', 'RegExp', 'Date', 'Function',\n];\n\n// https://www.typescriptlang.org/docs/handbook/utility-types.html\nconst typescriptGlobals = [\n 'Partial',\n 'Required',\n 'Readonly',\n 'Record',\n 'Pick',\n 'Omit',\n 'Exclude',\n 'Extract',\n 'NonNullable',\n 'Parameters',\n 'ConstructorParameters',\n 'ReturnType',\n 'InstanceType',\n 'ThisParameterType',\n 'OmitThisParameter',\n 'ThisType',\n 'Uppercase',\n 'Lowercase',\n 'Capitalize',\n 'Uncapitalize',\n];\n\nconst stripPseudoTypes = (str) => {\n return str && str.replace(/(?:\\.|<>|\\.<>|\\[\\])$/u, '');\n};\n\nexport default iterateJsdoc(({\n context,\n node,\n report,\n settings,\n sourceCode,\n utils,\n}) => {\n const {\n scopeManager,\n } = sourceCode;\n const {\n globalScope,\n } = scopeManager;\n\n const {\n definedTypes = [],\n } = context.options[0] || {};\n\n let definedPreferredTypes = [];\n const {\n preferredTypes,\n structuredTags,\n mode,\n } = settings;\n if (Object.keys(preferredTypes).length) {\n definedPreferredTypes = Object.values(preferredTypes).map((preferredType) => {\n if (typeof preferredType === 'string') {\n // May become an empty string but will be filtered out below\n return stripPseudoTypes(preferredType);\n }\n\n if (!preferredType) {\n return undefined;\n }\n\n if (typeof preferredType !== 'object') {\n utils.reportSettings(\n 'Invalid `settings.jsdoc.preferredTypes`. Values must be falsy, a string, or an object.',\n );\n }\n\n return stripPseudoTypes(preferredType.replacement);\n })\n .filter((preferredType) => {\n return preferredType;\n });\n }\n\n const typedefDeclarations = context.getAllComments()\n .filter((comment) => {\n return (/^\\*\\s/u).test(comment.value);\n })\n .map((commentNode) => {\n return parseComment(commentNode, '');\n })\n .flatMap((doc) => {\n return doc.tags.filter(({\n tag,\n }) => {\n return utils.isNamepathDefiningTag(tag);\n });\n })\n .map((tag) => {\n return tag.name;\n });\n\n const ancestorNodes = [];\n\n let currentNode = node;\n // No need for Program node?\n while (currentNode?.parent) {\n ancestorNodes.push(currentNode);\n currentNode = currentNode.parent;\n }\n\n const getTemplateTags = function (ancestorNode) {\n const commentNode = getJSDocComment(sourceCode, ancestorNode, settings);\n if (!commentNode) {\n return [];\n }\n\n const jsdoc = parseComment(commentNode, '');\n\n return jsdocUtils.filterTags(jsdoc.tags, (tag) => {\n return tag.tag === 'template';\n });\n };\n\n // `currentScope` may be `null` or `Program`, so in such a case,\n // we look to present tags instead\n const templateTags = ancestorNodes.length ?\n ancestorNodes.flatMap((ancestorNode) => {\n return getTemplateTags(ancestorNode);\n }) :\n utils.getPresentTags('template');\n\n const closureGenericTypes = templateTags.flatMap((tag) => {\n return utils.parseClosureTemplateTag(tag);\n });\n\n // In modules, including Node, there is a global scope at top with the\n // Program scope inside\n const cjsOrESMScope = globalScope.childScopes[0]?.block?.type === 'Program';\n\n const allDefinedTypes = new Set(globalScope.variables.map(({\n name,\n }) => {\n return name;\n })\n\n // If the file is a module, concat the variables from the module scope.\n .concat(\n cjsOrESMScope ?\n globalScope.childScopes.flatMap(({\n variables,\n }) => {\n return variables;\n }).map(({\n name,\n }) => {\n return name;\n }) : [],\n )\n .concat(extraTypes)\n .concat(typedefDeclarations)\n .concat(definedTypes)\n .concat(definedPreferredTypes)\n .concat(\n settings.mode === 'jsdoc' ?\n [] :\n [\n ...settings.mode === 'typescript' ? typescriptGlobals : [],\n ...closureGenericTypes,\n ],\n ));\n\n const jsdocTagsWithPossibleType = utils.filterTags(({\n tag,\n }) => {\n return utils.tagMightHaveTypePosition(tag) && (tag !== 'suppress' || settings.mode !== 'closure');\n });\n\n for (const tag of jsdocTagsWithPossibleType) {\n let parsedType;\n\n try {\n parsedType = mode === 'permissive' ? tryParseType(tag.type) : parseType(tag.type, mode);\n } catch {\n // On syntax error, will be handled by valid-types.\n continue;\n }\n\n traverse(parsedType, ({\n type,\n value,\n }) => {\n if (type === 'JsdocTypeName') {\n const structuredTypes = structuredTags[tag.tag]?.type;\n if (!allDefinedTypes.has(value) &&\n (!Array.isArray(structuredTypes) || !structuredTypes.includes(value))\n ) {\n report(`The type '${value}' is undefined.`, null, tag);\n } else if (!extraTypes.includes(value)) {\n context.markVariableAsUsed(value);\n }\n }\n });\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Checks that types in jsdoc comments are defined.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-no-undefined-types',\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n definedTypes: {\n items: {\n type: 'string',\n },\n type: 'array',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"file":"noUndefinedTypes.js"}
|
package/package.json
CHANGED