eslint-plugin-jsdoc 65.3.7 → 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.7"
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) {
@@ -204,11 +204,11 @@ export default iterateJsdoc(({
204
204
  }
205
205
 
206
206
  /**
207
- * @param {string} name
207
+ * @param {string} matchingName An identifier (escape module specifiers
208
+ * with `toValidIdentifier` before passing them)
208
209
  * @param {string[]} extrPathSegments
209
210
  */
210
- const getFixer = (name, extrPathSegments) => {
211
- const matchingName = toValidIdentifier(name);
211
+ const getFixer = (matchingName, extrPathSegments) => {
212
212
  return () => {
213
213
  /** @type {import('jsdoc-type-pratt-parser').NamePathResult|undefined} */
214
214
  let node = nodes.at(0);
@@ -434,7 +434,7 @@ export default iterateJsdoc(({
434
434
  'Inline `import()` found; prefer `@import`',
435
435
  tag,
436
436
  enableFixer ? (fixer) => {
437
- getFixer(element.value, [])();
437
+ getFixer(toValidIdentifier(element.value), [])();
438
438
  return createImportInserter(
439
439
  `/** @import * as ${toValidIdentifier(element.value)} from '${element.value}'; */`,
440
440
  )(fixer);
@@ -449,9 +449,9 @@ export default iterateJsdoc(({
449
449
  'Inline `import()` found; prefer `@import`',
450
450
  tag,
451
451
  enableFixer ? (fixer) => {
452
- getFixer(element.value, [])();
452
+ getFixer(toValidIdentifier(element.value), [])();
453
453
  return createImportInserter(
454
- `/** @import ${element.value} from '${element.value}'; */`,
454
+ `/** @import ${toValidIdentifier(element.value)} from '${element.value}'; */`,
455
455
  )(fixer);
456
456
  } : null,
457
457
  );
@@ -463,12 +463,12 @@ export default iterateJsdoc(({
463
463
  tag,
464
464
  enableFixer ? (fixer) => {
465
465
  if (outputType === 'namespaced-import') {
466
- getFixer(element.value, [
466
+ getFixer(toValidIdentifier(element.value), [
467
467
  ...pathSegments,
468
468
  ])();
469
469
  } else {
470
470
  getFixer(
471
- /** @type {string} */ (pathSegments.at(-1)),
471
+ toValidIdentifier(/** @type {string} */ (pathSegments.at(-1))),
472
472
  pathSegments.slice(0, -1),
473
473
  )();
474
474
  }