eslint-plugin-jsdoc 48.10.2 → 48.11.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.
@@ -39,6 +39,35 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
39
39
  }
40
40
  });
41
41
  };
42
+ const checkParamsAndReturnsTags = () => {
43
+ const paramName = /** @type {string} */utils.getPreferredTagName({
44
+ tagName: 'param'
45
+ });
46
+ const paramTags = utils.getTags(paramName);
47
+ for (const paramTag of paramTags) {
48
+ checkForUsedTypes(paramTag.type);
49
+ }
50
+ const returnsName = /** @type {string} */utils.getPreferredTagName({
51
+ tagName: 'returns'
52
+ });
53
+ const returnsTags = utils.getTags(returnsName);
54
+ for (const returnsTag of returnsTags) {
55
+ checkForUsedTypes(returnsTag.type);
56
+ }
57
+ };
58
+ const checkTemplateTags = () => {
59
+ for (const tag of templateTags) {
60
+ const {
61
+ name
62
+ } = tag;
63
+ const names = name.split(/,\s*/);
64
+ for (const name of names) {
65
+ if (!usedNames.has(name)) {
66
+ report(`@template ${name} not in use`, null, tag);
67
+ }
68
+ }
69
+ }
70
+ };
42
71
 
43
72
  /**
44
73
  * @param {import('@typescript-eslint/types').TSESTree.FunctionDeclaration|
@@ -62,32 +91,9 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
62
91
  usedNames.add(name);
63
92
  }
64
93
  if (checkParamsAndReturns) {
65
- const paramName = /** @type {string} */utils.getPreferredTagName({
66
- tagName: 'param'
67
- });
68
- const paramTags = utils.getTags(paramName);
69
- for (const paramTag of paramTags) {
70
- checkForUsedTypes(paramTag.type);
71
- }
72
- const returnsName = /** @type {string} */utils.getPreferredTagName({
73
- tagName: 'returns'
74
- });
75
- const returnsTags = utils.getTags(returnsName);
76
- for (const returnsTag of returnsTags) {
77
- checkForUsedTypes(returnsTag.type);
78
- }
79
- }
80
- for (const tag of templateTags) {
81
- const {
82
- name
83
- } = tag;
84
- const names = name.split(/,\s*/);
85
- for (const name of names) {
86
- if (!usedNames.has(name)) {
87
- report(`@template ${name} not in use`, null, tag);
88
- }
89
- }
94
+ checkParamsAndReturnsTags();
90
95
  }
96
+ checkTemplateTags();
91
97
  };
92
98
  const handleTypeAliases = () => {
93
99
  var _nde$declaration;
@@ -120,6 +126,13 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
120
126
  break;
121
127
  }
122
128
  };
129
+ const callbackTags = utils.getTags('callback');
130
+ const functionTags = utils.getTags('function');
131
+ if (callbackTags.length || functionTags.length) {
132
+ checkParamsAndReturnsTags();
133
+ checkTemplateTags();
134
+ return;
135
+ }
123
136
  const typedefTags = utils.getTags('typedef');
124
137
  if (!typedefTags.length || typedefTags.length >= 2) {
125
138
  handleTypeAliases();
@@ -1 +1 @@
1
- {"version":3,"file":"checkTemplateNames.cjs","names":["_jsdoccomment","require","_iterateJsdoc","_interopRequireDefault","e","__esModule","default","_default","exports","iterateJsdoc","context","utils","node","settings","report","mode","templateTags","getTags","usedNames","Set","checkForUsedTypes","potentialType","parsedType","tryParseType","parseType","traverse","nde","type","value","test","add","checkParameters","aliasDeclaration","checkParamsAndReturns","params","typeParameters","name","paramName","getPreferredTagName","tagName","paramTags","paramTag","returnsName","returnsTags","returnsTag","tag","names","split","has","handleTypeAliases","_nde$declaration","declaration","typedefTags","length","potentialTypedefType","propertyName","propertyTags","propertyTag","iterateAllJsdocs","meta","docs","description","url","schema","module"],"sources":["../../src/rules/checkTemplateNames.js"],"sourcesContent":["import {\n parse as parseType,\n traverse,\n tryParse as tryParseType,\n} from '@es-joy/jsdoccomment';\nimport iterateJsdoc from '../iterateJsdoc.js';\n\nexport default iterateJsdoc(({\n context,\n utils,\n node,\n settings,\n report,\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' && (/^[A-Z]$/).test(value)) {\n usedNames.add(value);\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 {params} = aliasDeclaration.typeParameters ?? {params: []};\n for (const {name: {name}} of params) {\n usedNames.add(name);\n }\n if (checkParamsAndReturns) {\n const paramName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'param',\n }));\n const paramTags = utils.getTags(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 = utils.getTags(returnsName);\n for (const returnsTag of returnsTags) {\n checkForUsedTypes(returnsTag.type);\n }\n }\n for (const tag of templateTags) {\n const {name} = tag;\n const names = name.split(/,\\s*/);\n for (const name of names) {\n if (!usedNames.has(name)) {\n report(`@template ${name} not in use`, null, tag);\n }\n }\n }\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 switch (nde.type) {\n case 'ExportDefaultDeclaration':\n case 'ExportNamedDeclaration':\n switch (nde.declaration?.type) {\n case 'FunctionDeclaration':\n checkParameters(nde.declaration, true);\n break;\n case 'ClassDeclaration':\n case 'TSTypeAliasDeclaration':\n case 'TSInterfaceDeclaration':\n checkParameters(nde.declaration);\n break;\n }\n break;\n case 'FunctionDeclaration':\n checkParameters(nde, true);\n break;\n case 'ClassDeclaration':\n case 'TSTypeAliasDeclaration':\n case 'TSInterfaceDeclaration':\n checkParameters(nde);\n break;\n }\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 for (const tag of templateTags) {\n const {name} = tag;\n const names = name.split(/,\\s*/);\n for (const name of names) {\n if (!usedNames.has(name)) {\n report(`@template ${name} not in use`, null, tag);\n }\n }\n }\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/require-template.md#repos-sticky-header',\n },\n schema: [],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAKA,IAAAC,aAAA,GAAAC,sBAAA,CAAAF,OAAA;AAA8C,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAE/B,IAAAG,qBAAY,EAAC,CAAC;EAC3BC,OAAO;EACPC,KAAK;EACLC,IAAI;EACJC,QAAQ;EACRC;AACF,CAAC,KAAK;EACJ,MAAM;IACJC;EACF,CAAC,GAAGF,QAAQ;EAEZ,MAAMG,YAAY,GAAGL,KAAK,CAACM,OAAO,CAAC,UAAU,CAAC;EAE9C,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAC,CAAC;EAC3B;AACF;AACA;EACE,MAAMC,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doc","_interopRequireDefault","e","__esModule","default","_default","exports","iterateJsdoc","context","utils","node","settings","report","mode","templateTags","getTags","usedNames","Set","checkForUsedTypes","potentialType","parsedType","tryParseType","parseType","traverse","nde","type","value","test","add","checkParamsAndReturnsTags","paramName","getPreferredTagName","tagName","paramTags","paramTag","returnsName","returnsTags","returnsTag","checkTemplateTags","tag","name","names","split","has","checkParameters","aliasDeclaration","checkParamsAndReturns","params","typeParameters","handleTypeAliases","_nde$declaration","declaration","callbackTags","functionTags","length","typedefTags","potentialTypedefType","propertyName","propertyTags","propertyTag","iterateAllJsdocs","meta","docs","description","url","schema","module"],"sources":["../../src/rules/checkTemplateNames.js"],"sourcesContent":["import {\n parse as parseType,\n traverse,\n tryParse as tryParseType,\n} from '@es-joy/jsdoccomment';\nimport iterateJsdoc from '../iterateJsdoc.js';\n\nexport default iterateJsdoc(({\n context,\n utils,\n node,\n settings,\n report,\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' && (/^[A-Z]$/).test(value)) {\n usedNames.add(value);\n }\n });\n };\n\n const checkParamsAndReturnsTags = () => {\n const paramName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'param',\n }));\n const paramTags = utils.getTags(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 = utils.getTags(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 {name} = tag;\n const names = name.split(/,\\s*/);\n for (const name of names) {\n if (!usedNames.has(name)) {\n report(`@template ${name} 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 {params} = aliasDeclaration.typeParameters ?? {params: []};\n for (const {name: {name}} of params) {\n usedNames.add(name);\n }\n if (checkParamsAndReturns) {\n checkParamsAndReturnsTags();\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 switch (nde.type) {\n case 'ExportDefaultDeclaration':\n case 'ExportNamedDeclaration':\n switch (nde.declaration?.type) {\n case 'FunctionDeclaration':\n checkParameters(nde.declaration, true);\n break;\n case 'ClassDeclaration':\n case 'TSTypeAliasDeclaration':\n case 'TSInterfaceDeclaration':\n checkParameters(nde.declaration);\n break;\n }\n break;\n case 'FunctionDeclaration':\n checkParameters(nde, true);\n break;\n case 'ClassDeclaration':\n case 'TSTypeAliasDeclaration':\n case 'TSInterfaceDeclaration':\n checkParameters(nde);\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 for (const tag of templateTags) {\n const {name} = tag;\n const names = name.split(/,\\s*/);\n for (const name of names) {\n if (!usedNames.has(name)) {\n report(`@template ${name} not in use`, null, tag);\n }\n }\n }\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/require-template.md#repos-sticky-header',\n },\n schema: [],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAKA,IAAAC,aAAA,GAAAC,sBAAA,CAAAF,OAAA;AAA8C,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAE/B,IAAAG,qBAAY,EAAC,CAAC;EAC3BC,OAAO;EACPC,KAAK;EACLC,IAAI;EACJC,QAAQ;EACRC;AACF,CAAC,KAAK;EACJ,MAAM;IACJC;EACF,CAAC,GAAGF,QAAQ;EAEZ,MAAMG,YAAY,GAAGL,KAAK,CAACM,OAAO,CAAC,UAAU,CAAC;EAE9C,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAC,CAAC;EAC3B;AACF;AACA;EACE,MAAMC,iBAAiB,GAAIC,aAAa,IAAK;IAC3C,IAAIC,UAAU;IACd,IAAI;MACFA,UAAU,GAAGP,IAAI,KAAK,YAAY,GAChC,IAAAQ,sBAAY,GAAC,qBAAuBF,aAAc,CAAC,GACnD,IAAAG,mBAAS,GAAC,qBAAuBH,aAAa,EAAGN,IAAI,CAAC;IAC1D,CAAC,CAAC,MAAM;MACN;IACF;IAEA,IAAAU,sBAAQ,EAACH,UAAU,EAAGI,GAAG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;AACF,CAAC,CAAC;AAAAyC,MAAA,CAAA5D,OAAA,GAAAA,OAAA,CAAAF,OAAA","ignoreList":[]}
@@ -98,11 +98,6 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
98
98
  break;
99
99
  }
100
100
  };
101
- const typedefTags = utils.getTags('typedef');
102
- if (!typedefTags.length || typedefTags.length >= 2) {
103
- handleTypes();
104
- return;
105
- }
106
101
  const usedNameToTag = new Map();
107
102
 
108
103
  /**
@@ -128,22 +123,42 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
128
123
  }
129
124
  });
130
125
  };
131
- const potentialTypedef = typedefTags[0];
132
- checkForUsedTypes(potentialTypedef);
133
- const tagName = /** @type {string} */utils.getPreferredTagName({
134
- tagName: 'property'
135
- });
136
- const propertyTags = utils.getTags(tagName);
137
- for (const propertyTag of propertyTags) {
138
- checkForUsedTypes(propertyTag);
139
- }
140
126
 
141
- // Could check against whitelist/blacklist
142
- for (const usedName of usedNames) {
143
- if (!templateNames.includes(usedName)) {
144
- report(`Missing @template ${usedName}`, null, usedNameToTag.get(usedName));
127
+ /**
128
+ * @param {string[]} tagNames
129
+ */
130
+ const checkTagsAndTemplates = tagNames => {
131
+ for (const tagName of tagNames) {
132
+ const preferredTagName = /** @type {string} */utils.getPreferredTagName({
133
+ tagName
134
+ });
135
+ const matchingTags = utils.getTags(preferredTagName);
136
+ for (const matchingTag of matchingTags) {
137
+ checkForUsedTypes(matchingTag);
138
+ }
139
+ }
140
+
141
+ // Could check against whitelist/blacklist
142
+ for (const usedName of usedNames) {
143
+ if (!templateNames.includes(usedName)) {
144
+ report(`Missing @template ${usedName}`, null, usedNameToTag.get(usedName));
145
+ }
145
146
  }
147
+ };
148
+ const callbackTags = utils.getTags('callback');
149
+ const functionTags = utils.getTags('function');
150
+ if (callbackTags.length || functionTags.length) {
151
+ checkTagsAndTemplates(['param', 'returns']);
152
+ return;
146
153
  }
154
+ const typedefTags = utils.getTags('typedef');
155
+ if (!typedefTags.length || typedefTags.length >= 2) {
156
+ handleTypes();
157
+ return;
158
+ }
159
+ const potentialTypedef = typedefTags[0];
160
+ checkForUsedTypes(potentialTypedef);
161
+ checkTagsAndTemplates(['property']);
147
162
  }, {
148
163
  iterateAllJsdocs: true,
149
164
  meta: {
@@ -1 +1 @@
1
- {"version":3,"file":"requireTemplate.cjs","names":["_jsdoccomment","require","_iterateJsdoc","_interopRequireDefault","e","__esModule","default","_default","exports","iterateJsdoc","context","utils","node","settings","report","requireSeparateTemplates","options","mode","usedNames","Set","templateTags","getTags","templateNames","flatMap","name","split","tag","names","length","checkTypeParams","aliasDeclaration","params","typeParameters","add","usedName","includes","handleTypes","_nde$declaration","_nde$declaration2","nde","type","declaration","typedefTags","usedNameToTag","Map","checkForUsedTypes","potentialTag","parsedType","tryParseType","parseType","traverse","value","test","has","set","potentialTypedef","tagName","getPreferredTagName","propertyTags","propertyTag","get","iterateAllJsdocs","meta","docs","description","url","schema","additionalProperties","properties","module"],"sources":["../../src/rules/requireTemplate.js"],"sourcesContent":["import {\n parse as parseType,\n traverse,\n tryParse as tryParseType,\n} from '@es-joy/jsdoccomment';\nimport iterateJsdoc from '../iterateJsdoc.js';\n\nexport default iterateJsdoc(({\n context,\n utils,\n node,\n settings,\n report,\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(({name}) => {\n return name.split(/,\\s*/);\n });\n\n for (const tag of templateTags) {\n const {name} = tag;\n const names = name.split(/,\\s*/);\n if (requireSeparateTemplates && names.length > 1) {\n report(`Missing separate @template for ${names[1]}`, null, tag);\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 */\n const checkTypeParams = (aliasDeclaration) => {\n /* c8 ignore next -- Guard */\n const {params} = aliasDeclaration.typeParameters ?? {params: []};\n for (const {name: {name}} of params) {\n usedNames.add(name);\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 switch (nde.type) {\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 break;\n case 'ExportNamedDeclaration':\n switch (nde.declaration?.type) {\n case 'ClassDeclaration':\n case 'FunctionDeclaration':\n case 'TSTypeAliasDeclaration':\n case 'TSInterfaceDeclaration':\n checkTypeParams(nde.declaration);\n break;\n }\n break;\n case 'ClassDeclaration':\n case 'FunctionDeclaration':\n case 'TSTypeAliasDeclaration':\n case 'TSInterfaceDeclaration':\n checkTypeParams(nde);\n break;\n }\n };\n\n const typedefTags = utils.getTags('typedef');\n if (!typedefTags.length || typedefTags.length >= 2) {\n handleTypes();\n return;\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]$/).test(value)) {\n usedNames.add(value);\n if (!usedNameToTag.has(value)) {\n usedNameToTag.set(value, potentialTag);\n }\n }\n });\n };\n\n const potentialTypedef = typedefTags[0];\n checkForUsedTypes(potentialTypedef);\n\n const tagName = /** @type {string} */ (utils.getPreferredTagName({\n tagName: 'property',\n }));\n const propertyTags = utils.getTags(tagName);\n for (const propertyTag of propertyTags) {\n checkForUsedTypes(propertyTag);\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 iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Requires template tags for each generic type parameter',\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 requireSeparateTemplates: {\n type: 'boolean'\n }\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAKA,IAAAC,aAAA,GAAAC,sBAAA,CAAAF,OAAA;AAA8C,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAE/B,IAAAG,qBAAY,EAAC,CAAC;EAC3BC,OAAO;EACPC,KAAK;EACLC,IAAI;EACJC,QAAQ;EACRC;AACF,CAAC,KAAK;EACJ,MAAM;IACJC,wBAAwB,GAAG;EAC7B,CAAC,GAAGL,OAAO,CAACM,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;EAE5B,MAAM;IACJC;EACF,CAAC,GAAGJ,QAAQ;EAEZ,MAAMK,SAAS,GAAG,IAAIC,GAAG,CAAC,CAAC;EAC3B,MAAMC,YAAY,GAAGT,KAAK,CAACU,OAAO,CAAC,UAAU,CAAC;EAC9C,MAAMC,aAAa,GAAGF,YAAY,CAACG,OAAO,CAAC,CAAC;IAACC;EAAI,CAAC,KAAK;IACrD,OAAOA,IAAI,CAACC,KAAK,CAAC,MAAM,CAAC;EAC3B,CAAC,CAAC;E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AAG,CAACH,KAAK,EAAEL,YAAY,CAAC;QACxC;MACF;IACF,CAAC,CAAC;EACJ,CAAC;EAED,MAAMS,gBAAgB,GAAGb,WAAW,CAAC,CAAC,CAAC;EACvCG,iBAAiB,CAACU,gBAAgB,CAAC;EAEnC,MAAMC,OAAO,GAAG,qBAAuB7C,KAAK,CAAC8C,mBAAmB,CAAC;IAC/DD,OAAO,EAAE;EACX,CAAC,CAAE;EACH,MAAME,YAAY,GAAG/C,KAAK,CAACU,OAAO,CAACmC,OAAO,CAAC;EAC3C,KAAK,MAAMG,WAAW,IAAID,YAAY,EAAE;IACtCb,iBAAiB,CAACc,WAAW,CAAC;EAChC;;EAEA;EACA,KAAK,MAAMzB,QAAQ,IAAIhB,SAAS,EAAE;IAChC,IAAI,CAACI,aAAa,CAACa,QAAQ,CAACD,QAAQ,CAAC,EAAE;MACrCpB,MAAM,CAAC,qBAAqBoB,QAAQ,EAAE,EAAE,IAAI,EAAES,aAAa,CAACiB,GAAG,CAAC1B,QAAQ,CAAC,CAAC;IAC5E;EACF;AACF,CAAC,EAAE;EACD2B,gBAAgB,EAAE,IAAI;EACtBC,IAAI,EAAE;IACJC,IAAI,EAAE;MACJC,WAAW,EAAE,wDAAwD;MACrEC,GAAG,EAAE;IACP,CAAC;IACDC,MAAM,EAAE,CACN;MACEC,oBAAoB,EAAE,KAAK;MAC3BC,UAAU,EAAE;QACVrD,wBAAwB,EAAE;UACxByB,IAAI,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAA6B,MAAA,CAAA7D,OAAA,GAAAA,OAAA,CAAAF,OAAA","ignoreList":[]}
1
+ {"version":3,"file":"requireTemplate.cjs","names":["_jsdoccomment","require","_iterateJsdoc","_interopRequireDefault","e","__esModule","default","_default","exports","iterateJsdoc","context","utils","node","settings","report","requireSeparateTemplates","options","mode","usedNames","Set","templateTags","getTags","templateNames","flatMap","name","split","tag","names","length","checkTypeParams","aliasDeclaration","params","typeParameters","add","usedName","includes","handleTypes","_nde$declaration","_nde$declaration2","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","module"],"sources":["../../src/rules/requireTemplate.js"],"sourcesContent":["import {\n parse as parseType,\n traverse,\n tryParse as tryParseType,\n} from '@es-joy/jsdoccomment';\nimport iterateJsdoc from '../iterateJsdoc.js';\n\nexport default iterateJsdoc(({\n context,\n utils,\n node,\n settings,\n report,\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(({name}) => {\n return name.split(/,\\s*/);\n });\n\n for (const tag of templateTags) {\n const {name} = tag;\n const names = name.split(/,\\s*/);\n if (requireSeparateTemplates && names.length > 1) {\n report(`Missing separate @template for ${names[1]}`, null, tag);\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 */\n const checkTypeParams = (aliasDeclaration) => {\n /* c8 ignore next -- Guard */\n const {params} = aliasDeclaration.typeParameters ?? {params: []};\n for (const {name: {name}} of params) {\n usedNames.add(name);\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 switch (nde.type) {\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 break;\n case 'ExportNamedDeclaration':\n switch (nde.declaration?.type) {\n case 'ClassDeclaration':\n case 'FunctionDeclaration':\n case 'TSTypeAliasDeclaration':\n case 'TSInterfaceDeclaration':\n checkTypeParams(nde.declaration);\n break;\n }\n break;\n case 'ClassDeclaration':\n case 'FunctionDeclaration':\n case 'TSTypeAliasDeclaration':\n case 'TSInterfaceDeclaration':\n checkTypeParams(nde);\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]$/).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(['param', 'returns']);\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(['property']);\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Requires template tags for each generic type parameter',\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 requireSeparateTemplates: {\n type: 'boolean'\n }\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAKA,IAAAC,aAAA,GAAAC,sBAAA,CAAAF,OAAA;AAA8C,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAE/B,IAAAG,qBAAY,EAAC,CAAC;EAC3BC,OAAO;EACPC,KAAK;EACLC,IAAI;EACJC,QAAQ;EACRC;AACF,CAAC,KAAK;EACJ,MAAM;IACJC,wBAAwB,GAAG;EAC7B,CAAC,GAAGL,OAAO,CAACM,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;EAE5B,MAAM;IACJC;EACF,CAAC,GAAGJ,QAAQ;EAEZ,MAAMK,SAAS,GAAG,IAAIC,GAAG,CAAC,CAAC;EAC3B,MAAMC,YAAY,GAAGT,KAAK,CAACU,OAAO,CAAC,UAAU,CAAC;EAC9C,MAAMC,aAAa,GAAGF,YAAY,CAACG,OAAO,CAAC,CAAC;IAACC;EAAI,CAAC,KAAK;IACrD,OAAOA,IAAI,CAACC,KAAK,CAAC,MAAM,CAAC;EAC3B,CAAC,CAAC;EAEF,KAAK,MAAMC,GAAG,IAAIN,YAAY,EAAE;IAC9B,MAAM;MAACI;IAAI,CAAC,GAAGE,GAAG;IAClB,MAAMC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,EAAE;QACR;MACF,CAAC;MACDA,IAAI,EAAE;IACR,CAAC,CACF;IACDA,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAAkC,MAAA,CAAAlE,OAAA,GAAAA,OAAA,CAAAF,OAAA","ignoreList":[]}
package/package.json CHANGED
@@ -152,5 +152,5 @@
152
152
  "test-cov": "cross-env TIMING=1 c8 --reporter text npm run test-no-cov",
153
153
  "test-index": "npm run test-no-cov -- test/rules/index.js"
154
154
  },
155
- "version": "48.10.2"
155
+ "version": "48.11.0"
156
156
  }
@@ -43,6 +43,36 @@ export default iterateJsdoc(({
43
43
  });
44
44
  };
45
45
 
46
+ const checkParamsAndReturnsTags = () => {
47
+ const paramName = /** @type {string} */ (utils.getPreferredTagName({
48
+ tagName: 'param',
49
+ }));
50
+ const paramTags = utils.getTags(paramName);
51
+ for (const paramTag of paramTags) {
52
+ checkForUsedTypes(paramTag.type);
53
+ }
54
+
55
+ const returnsName = /** @type {string} */ (utils.getPreferredTagName({
56
+ tagName: 'returns',
57
+ }));
58
+ const returnsTags = utils.getTags(returnsName);
59
+ for (const returnsTag of returnsTags) {
60
+ checkForUsedTypes(returnsTag.type);
61
+ }
62
+ };
63
+
64
+ const checkTemplateTags = () => {
65
+ for (const tag of templateTags) {
66
+ const {name} = tag;
67
+ const names = name.split(/,\s*/);
68
+ for (const name of names) {
69
+ if (!usedNames.has(name)) {
70
+ report(`@template ${name} not in use`, null, tag);
71
+ }
72
+ }
73
+ }
74
+ };
75
+
46
76
  /**
47
77
  * @param {import('@typescript-eslint/types').TSESTree.FunctionDeclaration|
48
78
  * import('@typescript-eslint/types').TSESTree.ClassDeclaration|
@@ -57,31 +87,10 @@ export default iterateJsdoc(({
57
87
  usedNames.add(name);
58
88
  }
59
89
  if (checkParamsAndReturns) {
60
- const paramName = /** @type {string} */ (utils.getPreferredTagName({
61
- tagName: 'param',
62
- }));
63
- const paramTags = utils.getTags(paramName);
64
- for (const paramTag of paramTags) {
65
- checkForUsedTypes(paramTag.type);
66
- }
67
-
68
- const returnsName = /** @type {string} */ (utils.getPreferredTagName({
69
- tagName: 'returns',
70
- }));
71
- const returnsTags = utils.getTags(returnsName);
72
- for (const returnsTag of returnsTags) {
73
- checkForUsedTypes(returnsTag.type);
74
- }
75
- }
76
- for (const tag of templateTags) {
77
- const {name} = tag;
78
- const names = name.split(/,\s*/);
79
- for (const name of names) {
80
- if (!usedNames.has(name)) {
81
- report(`@template ${name} not in use`, null, tag);
82
- }
83
- }
90
+ checkParamsAndReturnsTags();
84
91
  }
92
+
93
+ checkTemplateTags();
85
94
  };
86
95
 
87
96
  const handleTypeAliases = () => {
@@ -116,6 +125,14 @@ export default iterateJsdoc(({
116
125
  }
117
126
  };
118
127
 
128
+ const callbackTags = utils.getTags('callback');
129
+ const functionTags = utils.getTags('function');
130
+ if (callbackTags.length || functionTags.length) {
131
+ checkParamsAndReturnsTags();
132
+ checkTemplateTags();
133
+ return;
134
+ }
135
+
119
136
  const typedefTags = utils.getTags('typedef');
120
137
  if (!typedefTags.length || typedefTags.length >= 2) {
121
138
  handleTypeAliases();
@@ -89,12 +89,6 @@ export default iterateJsdoc(({
89
89
  }
90
90
  };
91
91
 
92
- const typedefTags = utils.getTags('typedef');
93
- if (!typedefTags.length || typedefTags.length >= 2) {
94
- handleTypes();
95
- return;
96
- }
97
-
98
92
  const usedNameToTag = new Map();
99
93
 
100
94
  /**
@@ -124,23 +118,45 @@ export default iterateJsdoc(({
124
118
  });
125
119
  };
126
120
 
127
- const potentialTypedef = typedefTags[0];
128
- checkForUsedTypes(potentialTypedef);
121
+ /**
122
+ * @param {string[]} tagNames
123
+ */
124
+ const checkTagsAndTemplates = (tagNames) => {
125
+ for (const tagName of tagNames) {
126
+ const preferredTagName = /** @type {string} */ (utils.getPreferredTagName({
127
+ tagName,
128
+ }));
129
+ const matchingTags = utils.getTags(preferredTagName);
130
+ for (const matchingTag of matchingTags) {
131
+ checkForUsedTypes(matchingTag);
132
+ }
133
+ }
134
+
135
+ // Could check against whitelist/blacklist
136
+ for (const usedName of usedNames) {
137
+ if (!templateNames.includes(usedName)) {
138
+ report(`Missing @template ${usedName}`, null, usedNameToTag.get(usedName));
139
+ }
140
+ }
141
+ };
129
142
 
130
- const tagName = /** @type {string} */ (utils.getPreferredTagName({
131
- tagName: 'property',
132
- }));
133
- const propertyTags = utils.getTags(tagName);
134
- for (const propertyTag of propertyTags) {
135
- checkForUsedTypes(propertyTag);
143
+ const callbackTags = utils.getTags('callback');
144
+ const functionTags = utils.getTags('function');
145
+ if (callbackTags.length || functionTags.length) {
146
+ checkTagsAndTemplates(['param', 'returns']);
147
+ return;
136
148
  }
137
149
 
138
- // Could check against whitelist/blacklist
139
- for (const usedName of usedNames) {
140
- if (!templateNames.includes(usedName)) {
141
- report(`Missing @template ${usedName}`, null, usedNameToTag.get(usedName));
142
- }
150
+ const typedefTags = utils.getTags('typedef');
151
+ if (!typedefTags.length || typedefTags.length >= 2) {
152
+ handleTypes();
153
+ return;
143
154
  }
155
+
156
+ const potentialTypedef = typedefTags[0];
157
+ checkForUsedTypes(potentialTypedef);
158
+
159
+ checkTagsAndTemplates(['property']);
144
160
  }, {
145
161
  iterateAllJsdocs: true,
146
162
  meta: {