eslint-plugin-jsdoc 65.3.8 → 65.3.9

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.
@@ -166,6 +166,13 @@ export function getAllTags(jsdoc: import("./iterateJsdoc.js").JsdocBlockWithInli
166
166
  line?: number | undefined;
167
167
  column?: number | undefined;
168
168
  }))[];
169
+ /**
170
+ * Gets the default types of GCC Generic/Template types, e.g., `T[]` for
171
+ * `@template [U=T[]]`
172
+ * @param {import('comment-parser').Spec} tag
173
+ * @returns {string[]}
174
+ */
175
+ export function getClosureTemplateTagDefaults(tag: import("comment-parser").Spec): string[];
169
176
  /**
170
177
  * @param {import('./iterateJsdoc.js').Context[]} contexts
171
178
  * @param {import('./iterateJsdoc.js').CheckJsdoc} checkJsdoc
package/package.json CHANGED
@@ -163,5 +163,5 @@
163
163
  "test-cov": "TIMING=1 c8 --reporter text pnpm run test-no-cov",
164
164
  "test-index": "pnpm run test-no-cov test/rules/index.js"
165
165
  },
166
- "version": "65.3.8"
166
+ "version": "65.3.9"
167
167
  }
package/src/jsdocUtils.js CHANGED
@@ -1641,6 +1641,20 @@ const parseClosureTemplateTag = (tag) => {
1641
1641
  });
1642
1642
  };
1643
1643
 
1644
+ /**
1645
+ * Gets the default types of GCC Generic/Template types, e.g., `T[]` for
1646
+ * `@template [U=T[]]`
1647
+ * @param {import('comment-parser').Spec} tag
1648
+ * @returns {string[]}
1649
+ */
1650
+ const getClosureTemplateTagDefaults = (tag) => {
1651
+ return splitTopLevelCommas(tag.name)
1652
+ .map((type) => {
1653
+ return type.trim().replace(/^\[?[^=]*(?:=(?<dflt>.*?)\]?)?$/v, '$<dflt>').trim();
1654
+ })
1655
+ .filter(Boolean);
1656
+ };
1657
+
1644
1658
  /**
1645
1659
  * @typedef {true|string[]} DefaultContexts
1646
1660
  */
@@ -2200,6 +2214,7 @@ export {
2200
2214
  flattenRoots,
2201
2215
  forEachPreferredTag,
2202
2216
  getAllTags,
2217
+ getClosureTemplateTagDefaults,
2203
2218
  getContextObject,
2204
2219
  getDocumentNamepathDefiningTags,
2205
2220
  getFunctionParameterNames,
@@ -2,6 +2,7 @@ import iterateJsdoc, {
2
2
  parseComment,
3
3
  } from '../iterateJsdoc.js';
4
4
  import {
5
+ getClosureTemplateTagDefaults,
5
6
  getTags,
6
7
  } from '../jsdocUtils.js';
7
8
  import {
@@ -46,13 +47,21 @@ export default iterateJsdoc(({
46
47
  return;
47
48
  }
48
49
 
49
- traverse(parsedType, (nde) => {
50
+ traverse(parsedType, (nde, parentNode) => {
50
51
  const {
51
52
  type,
52
53
  value,
53
54
  } = /** @type {import('jsdoc-type-pratt-parser').NameResult} */ (nde);
54
55
  if (type === 'JsdocTypeName') {
55
56
  usedNames.add(value);
57
+ // An unquoted index of an indexed access type, e.g., `K` in `T[K]`
58
+ } else if (
59
+ type === 'JsdocTypeProperty' &&
60
+ parentNode?.type === 'JsdocTypeNamePath' &&
61
+ parentNode.pathType === 'property-brackets' &&
62
+ !(/** @type {import('jsdoc-type-pratt-parser').PropertyResult} */ (nde).meta.quote)
63
+ ) {
64
+ usedNames.add(value);
56
65
  }
57
66
  });
58
67
  };
@@ -76,6 +85,16 @@ export default iterateJsdoc(({
76
85
  };
77
86
 
78
87
  const checkTemplateTags = () => {
88
+ // A template name may be used only within the constraint or default of
89
+ // another template, e.g., `T` in `@template {keyof T} K` or
90
+ // `@template [U=T[]]`
91
+ for (const tag of templateTags) {
92
+ checkForUsedTypes(tag.type);
93
+ for (const defaultType of getClosureTemplateTagDefaults(tag)) {
94
+ checkForUsedTypes(defaultType);
95
+ }
96
+ }
97
+
79
98
  for (const tag of templateTags) {
80
99
  const names = utils.parseClosureTemplateTag(tag);
81
100
  for (const nme of names) {