eslint-plugin-jsdoc 65.3.15 → 65.4.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/package.json CHANGED
@@ -5,9 +5,10 @@
5
5
  "url": "http://gajus.com"
6
6
  },
7
7
  "dependencies": {
8
- "@es-joy/jsdoccomment": "~0.98.0",
8
+ "@es-joy/escodegen": "^4.2.0",
9
+ "@es-joy/jsdoccomment": "~0.100.0",
9
10
  "@es-joy/resolve.exports": "1.2.0",
10
- "@typescript-eslint/utils": "^8.70.1",
11
+ "@typescript-eslint/utils": "^8.72.0",
11
12
  "are-docs-informative": "^0.1.1",
12
13
  "comment-parser": "1.4.9",
13
14
  "debug": "^4.4.3",
@@ -24,11 +25,10 @@
24
25
  "description": "JSDoc linting rules for ESLint.",
25
26
  "devDependencies": {
26
27
  "@arethetypeswrong/cli": "^0.18.5",
27
- "@babel/core": "8.0.6",
28
- "@babel/eslint-parser": "8.0.5",
28
+ "@babel/core": "8.0.7",
29
+ "@babel/eslint-parser": "8.0.7",
29
30
  "@babel/plugin-transform-flow-strip-types": "8.0.1",
30
- "@babel/preset-env": "8.0.6",
31
- "@es-joy/escodegen": "^4.2.0",
31
+ "@babel/preset-env": "8.0.7",
32
32
  "@es-joy/jsdoc-eslint-parser": "^0.29.0",
33
33
  "@eslint/core": "^1.2.1",
34
34
  "@hkdobrev/run-if-changed": "^0.9.0",
@@ -41,36 +41,36 @@
41
41
  "@types/estree": "^1.0.9",
42
42
  "@types/json-schema": "^7.0.15",
43
43
  "@types/mocha": "^10.0.10",
44
- "@types/node": "^26.6.2",
44
+ "@types/node": "^26.6.5",
45
45
  "@types/semver": "^7.8.0",
46
46
  "@types/spdx-expression-parse": "^4.0.0",
47
- "@typescript-eslint/types": "8.70.1",
47
+ "@typescript-eslint/types": "8.72.0",
48
48
  "babel-plugin-add-module-exports": "^1.0.4",
49
- "babel-plugin-transform-import-meta": "^3.0.0",
49
+ "babel-plugin-transform-import-meta": "^3.1.0",
50
50
  "c8": "^12.0.0",
51
- "camelcase": "^9.0.0",
52
- "chai": "^6.2.2",
53
- "decamelize": "^6.0.1",
54
- "eslint": "10.11.0",
51
+ "camelcase": "^10.0.0",
52
+ "chai": "^6.3.0",
53
+ "decamelize": "^7.0.0",
54
+ "eslint": "10.13.0",
55
55
  "eslint-config-canonical": "^47.4.2",
56
56
  "gitdown": "^4.1.1",
57
57
  "glob": "^13.0.6",
58
- "globals": "^17.12.0",
58
+ "globals": "^17.13.0",
59
59
  "husky": "^9.1.7",
60
- "jsdoc-type-pratt-parser": "^9.2.2",
60
+ "jsdoc-type-pratt-parser": "^9.3.0",
61
61
  "json-schema": "^0.4.0",
62
62
  "json-schema-to-typescript": "^16.0.0",
63
- "lint-staged": "^17.5.1",
64
- "mocha": "^12.0.2",
63
+ "lint-staged": "^17.6.0",
64
+ "mocha": "^12.0.3",
65
65
  "open-editor": "^6.0.0",
66
- "playwright": "^1.63.0",
66
+ "playwright": "^1.64.1",
67
67
  "replace": "^1.2.2",
68
68
  "rimraf": "^6.1.3",
69
69
  "semantic-release": "^25.0.9",
70
70
  "sinon": "^22.1.0",
71
71
  "ts-api-utils": "^2.5.0",
72
72
  "typescript": "6.0.3",
73
- "typescript-eslint": "8.70.1"
73
+ "typescript-eslint": "8.72.0"
74
74
  },
75
75
  "engines": {
76
76
  "node": "^22.22.2 || >=24.15.0"
@@ -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.15"
166
+ "version": "65.4.0"
167
167
  }
@@ -1,10 +1,16 @@
1
1
  import iterateJsdoc from './iterateJsdoc.js';
2
+ import {
3
+ generate,
4
+ } from '@es-joy/escodegen';
2
5
  import {
3
6
  parse,
4
7
  stringify,
5
8
  traverse,
6
9
  tryParse,
7
10
  } from '@es-joy/jsdoccomment';
11
+ import {
12
+ parse as espree,
13
+ } from 'espree';
8
14
 
9
15
  /**
10
16
  * Adjusts the parent type node `meta` for generic matches (or type node
@@ -380,7 +386,13 @@ export const buildRejectOrPreferRuleDefinition = ({
380
386
  let typeAst;
381
387
 
382
388
  try {
383
- typeAst = mode === 'permissive' ? tryParse(jsdocTag.type) : parse(jsdocTag.type, mode);
389
+ typeAst = mode === 'permissive' ?
390
+ tryParse(jsdocTag.type, undefined, {
391
+ computedPropertyParser: espree,
392
+ }) :
393
+ parse(jsdocTag.type, mode, {
394
+ computedPropertyParser: espree,
395
+ });
384
396
  } catch {
385
397
  continue;
386
398
  }
@@ -408,7 +420,7 @@ export const buildRejectOrPreferRuleDefinition = ({
408
420
  });
409
421
 
410
422
  if (invalidTypes.length) {
411
- const fixedType = stringify(typeAst);
423
+ const fixedType = stringify(typeAst, generate);
412
424
 
413
425
  /**
414
426
  * @type {import('eslint').Rule.ReportFixer}
package/src/jsdocUtils.js CHANGED
@@ -5,11 +5,17 @@ import {
5
5
  typeScriptTags,
6
6
  } from './tagNames.js';
7
7
  import WarnSettings from './WarnSettings.js';
8
+ import {
9
+ generate,
10
+ } from '@es-joy/escodegen';
8
11
  import {
9
12
  parseComment,
10
13
  stringify,
11
14
  tryParse,
12
15
  } from '@es-joy/jsdoccomment';
16
+ import {
17
+ parse as espree,
18
+ } from 'espree';
13
19
 
14
20
  /**
15
21
  * @typedef {number} Integer
@@ -971,6 +977,9 @@ const mayBeUndefinedTypeTag = (tag, mode) => {
971
977
  mode === 'permissive' ? undefined : [
972
978
  mode,
973
979
  ],
980
+ {
981
+ computedPropertyParser: espree,
982
+ },
974
983
  );
975
984
  } catch {
976
985
  // Ignore
@@ -2042,7 +2051,7 @@ const strictNativeTypes = [
2042
2051
  * @param {string} typeBracketSpacing
2043
2052
  */
2044
2053
  const rewireByParsedType = (jsdoc, tag, parsedType, indent, typeBracketSpacing = '') => {
2045
- const typeLines = stringify(parsedType).split('\n');
2054
+ const typeLines = stringify(parsedType, generate).split('\n');
2046
2055
  const firstTypeLine = typeLines.shift();
2047
2056
  const lastTypeLine = typeLines.pop();
2048
2057
 
@@ -1,4 +1,7 @@
1
1
  import iterateJsdoc from '../iterateJsdoc.js';
2
+ import {
3
+ stringify as stringifyComment,
4
+ } from 'comment-parser';
2
5
  import escapeStringRegexp from 'escape-string-regexp';
3
6
 
4
7
  // https://babeljs.io/docs/en/babel-plugin-transform-react-jsx/
@@ -43,6 +46,133 @@ const isClassMember = (node) => {
43
46
  return node?.parent?.type === 'ClassBody';
44
47
  };
45
48
 
49
+ /**
50
+ * @param {import('@typescript-eslint/types').TSESTree.Node} member
51
+ * @returns {string|undefined}
52
+ */
53
+ const getObjectMemberName = (member) => {
54
+ if (member.type !== 'Property' && member.type !== 'TSPropertySignature') {
55
+ return undefined;
56
+ }
57
+
58
+ const typedMember = /** @type {import('@typescript-eslint/types').TSESTree.Property|import('@typescript-eslint/types').TSESTree.TSPropertySignature} */ (
59
+ member
60
+ );
61
+ if (typedMember.computed && typedMember.key.type !== 'Literal') {
62
+ return undefined;
63
+ }
64
+
65
+ const {
66
+ key,
67
+ } = typedMember;
68
+ if (key.type === 'Identifier') {
69
+ return key.name;
70
+ }
71
+
72
+ if (key.type === 'Literal' && typeof key.value === 'string') {
73
+ return key.value;
74
+ }
75
+
76
+ return undefined;
77
+ };
78
+
79
+ /**
80
+ * @param {import('@typescript-eslint/types').TSESTree.Node[]} members
81
+ * @returns {Map<string, import('eslint').Rule.Node>}
82
+ */
83
+ const indexObjectMembers = (members) => {
84
+ /** @type {Map<string, import('eslint').Rule.Node>} */
85
+ const properties = new Map();
86
+ for (const member of members) {
87
+ const name = getObjectMemberName(member);
88
+ if (!name || properties.has(name)) {
89
+ continue;
90
+ }
91
+
92
+ properties.set(name, /** @type {import('eslint').Rule.Node} */ (member));
93
+ }
94
+
95
+ return properties;
96
+ };
97
+
98
+ /**
99
+ * Object expression or type literal whose properties can receive moved docs.
100
+ * Export wrappers are unwrapped so `export const X = { ... }` is recognized.
101
+ * @param {import('eslint').Rule.Node} node
102
+ * @returns {Map<string, import('eslint').Rule.Node>|null}
103
+ */
104
+ const getAttachedObjectProperties = (node) => {
105
+ if (node.type === 'ExportNamedDeclaration') {
106
+ const exported = /** @type {import('@typescript-eslint/types').TSESTree.ExportNamedDeclaration} */ (
107
+ node
108
+ ).declaration;
109
+ if (!exported) {
110
+ return null;
111
+ }
112
+
113
+ return getAttachedObjectProperties(/** @type {import('eslint').Rule.Node} */ (
114
+ exported
115
+ ));
116
+ }
117
+
118
+ if (node.type !== 'VariableDeclaration') {
119
+ return null;
120
+ }
121
+
122
+ const variableDeclaration = /** @type {import('@typescript-eslint/types').TSESTree.VariableDeclaration} */ (
123
+ node
124
+ );
125
+ const declarator = variableDeclaration.declarations[0];
126
+
127
+ /* c8 ignore next 3 -- `VariableDeclaration` always has a declarator. */
128
+ if (!declarator) {
129
+ return null;
130
+ }
131
+
132
+ if (declarator.init?.type === 'ObjectExpression') {
133
+ return indexObjectMembers(declarator.init.properties);
134
+ }
135
+
136
+ const typeAnnotation = declarator.id.type === 'Identifier' ?
137
+ declarator.id.typeAnnotation?.typeAnnotation :
138
+ undefined;
139
+ if (typeAnnotation?.type === 'TSTypeLiteral') {
140
+ return indexObjectMembers(typeAnnotation.members);
141
+ }
142
+
143
+ return null;
144
+ };
145
+
146
+ /**
147
+ * Description text to move for `@prop NAME - description`, or `null` when
148
+ * the tag is not that shape. A leading hyphen is the JSDoc separator.
149
+ * @param {import('comment-parser').Spec} tag
150
+ * @returns {string|null}
151
+ */
152
+ const getPropertyTagDescription = (tag) => {
153
+ if (!tag.name) {
154
+ return null;
155
+ }
156
+
157
+ /** @type {string[]} */
158
+ const lines = [];
159
+ for (const src of tag.source) {
160
+ if (src.tokens.end && !src.tokens.tag && !src.tokens.description) {
161
+ break;
162
+ }
163
+
164
+ if (src.tokens.tag) {
165
+ lines.push(src.tokens.description.replace(/^\s*-\s*/v, ''));
166
+ continue;
167
+ }
168
+
169
+ lines.push(src.tokens.description);
170
+ }
171
+
172
+ const description = lines.join('\n').trim();
173
+ return description || null;
174
+ };
175
+
46
176
  const typedTagsUnnecessaryOutsideDeclare = new Set([
47
177
  'abstract',
48
178
  'access',
@@ -255,9 +385,252 @@ export default iterateJsdoc(({
255
385
  return false;
256
386
  };
257
387
 
388
+ /**
389
+ * @param {import('eslint').Rule.Node} propNode
390
+ * @returns {boolean}
391
+ */
392
+ const propertyHasJsdoc = (propNode) => {
393
+ return sourceCode.getCommentsBefore(propNode).some((comment) => {
394
+ return comment.type === 'Block' && comment.value.startsWith('*');
395
+ });
396
+ };
397
+
398
+ /**
399
+ * @param {string} tagName
400
+ * @returns {boolean}
401
+ */
402
+ const isRelocatablePropertyTag = (tagName) => {
403
+ return tagName === 'property' ||
404
+ tagName === 'prop' && !Object.hasOwn(tagNamePreference, 'prop');
405
+ };
406
+
407
+ /**
408
+ * @param {string} commentText
409
+ * @returns {boolean}
410
+ */
411
+ const commentHasText = (commentText) => {
412
+ return commentText.split(/\r?\n/v).some((line) => {
413
+ return (/\S/v).test(line.replaceAll('*', '').replaceAll('/', ''));
414
+ });
415
+ };
416
+
417
+ /**
418
+ * @param {import('eslint').Rule.RuleFixer} fixer
419
+ * @returns {import('eslint').Rule.Fix}
420
+ */
421
+ const removeJsdocFix = (fixer) => {
422
+ const text = sourceCode.text;
423
+ const lastLineBreakPos = text.slice(0, jsdocNode.range[0]).search(/\n[ \t]*$/v);
424
+ if (lastLineBreakPos > -1) {
425
+ return fixer.removeRange([
426
+ lastLineBreakPos, jsdocNode.range[1],
427
+ ]);
428
+ }
429
+
430
+ return fixer.removeRange(
431
+ (/\s/v).test(text.charAt(jsdocNode.range[1])) ?
432
+ [
433
+ jsdocNode.range[0], jsdocNode.range[1] + 1,
434
+ ] :
435
+ jsdocNode.range,
436
+ );
437
+ };
438
+
439
+ /**
440
+ * Same end state as the per-tag redundant-property fixer, but applied to
441
+ * every `@prop`/`@property` in this block at once. Doing them together
442
+ * avoids a later pass relocating whichever names still remain.
443
+ * @param {import('comment-parser').Spec[]} tags
444
+ * @returns {string}
445
+ */
446
+ const stripPropertyTags = (tags) => {
447
+ /** @type {Set<number>} */
448
+ const clearTagLine = new Set();
449
+ /** @type {Set<number>} */
450
+ const dropLines = new Set();
451
+ for (const tag of tags) {
452
+ if (tag.description.trim()) {
453
+ clearTagLine.add(tag.source[0].number);
454
+ continue;
455
+ }
456
+
457
+ for (const src of tag.source) {
458
+ if (src.tokens.end && !src.tokens.tag) {
459
+ break;
460
+ }
461
+
462
+ dropLines.add(src.number);
463
+ }
464
+ }
465
+
466
+ const cloned = structuredClone(jsdoc);
467
+ cloned.source = cloned.source.flatMap((line) => {
468
+ if (dropLines.has(line.number)) {
469
+ return [];
470
+ }
471
+
472
+ if (!clearTagLine.has(line.number)) {
473
+ return [
474
+ line,
475
+ ];
476
+ }
477
+
478
+ return [
479
+ {
480
+ ...line,
481
+ tokens: {
482
+ ...line.tokens,
483
+ postTag: '',
484
+ postType: '',
485
+ tag: '',
486
+ type: '',
487
+ },
488
+ },
489
+ ];
490
+ });
491
+
492
+ const stripped = stringifyComment(cloned);
493
+ return commentHasText(stripped) ? stripped : '';
494
+ };
495
+
496
+ /**
497
+ * Relocate every redundant `@prop`/`@property` description onto a matching
498
+ * property, or strip those tags in one step when the object is recognized
499
+ * but not every tag can be moved.
500
+ * @returns {import('eslint').Rule.ReportFixer|null}
501
+ */
502
+ const getPropertyRelocationFixer = () => {
503
+ if (!typed || !enableFixer || !node) {
504
+ return null;
505
+ }
506
+
507
+ const properties = getAttachedObjectProperties(node);
508
+ if (!properties) {
509
+ return null;
510
+ }
511
+
512
+ /** @type {import('comment-parser').Spec[]} */
513
+ const propertyTags = jsdoc.tags.filter((jsdocTag) => {
514
+ return isRelocatablePropertyTag(jsdocTag.tag);
515
+ });
516
+ if (!propertyTags.length) {
517
+ return null;
518
+ }
519
+
520
+ /**
521
+ * @type {{
522
+ * description: string,
523
+ * prop: import('eslint').Rule.Node,
524
+ * tag: import('comment-parser').Spec
525
+ * }[]}
526
+ */
527
+ const moves = [];
528
+ /** @type {Set<string>} */
529
+ const seenNames = new Set();
530
+ let canRelocate = true;
531
+ for (const jsdocTag of propertyTags) {
532
+ const description = getPropertyTagDescription(jsdocTag);
533
+ const prop = description ? properties.get(jsdocTag.name) : undefined;
534
+ if (!description || !prop || propertyHasJsdoc(prop) || seenNames.has(jsdocTag.name)) {
535
+ canRelocate = false;
536
+ break;
537
+ }
538
+
539
+ seenNames.add(jsdocTag.name);
540
+ moves.push({
541
+ description,
542
+ prop,
543
+ tag: jsdocTag,
544
+ });
545
+ }
546
+
547
+ if (!canRelocate) {
548
+ const stripped = stripPropertyTags(propertyTags);
549
+ return (fixer) => {
550
+ return stripped ? fixer.replaceText(jsdocNode, stripped) : removeJsdocFix(fixer);
551
+ };
552
+ }
553
+
554
+ return (fixer) => {
555
+ /** @type {import('eslint').Rule.Fix[]} */
556
+ const fixes = [];
557
+ const lineBreak = sourceCode.text.includes('\r\n') ? '\r\n' : '\n';
558
+ const commentText = sourceCode.getText(jsdocNode);
559
+ const commentLines = commentText.split(/\r?\n/v);
560
+ /** @type {Set<number>} */
561
+ const removeOffsets = new Set();
562
+ for (const move of moves) {
563
+ const srcLines = move.tag.source;
564
+ removeOffsets.add(srcLines[0].number);
565
+ for (const line of srcLines.slice(1)) {
566
+ if (line.tokens.tag || line.tokens.end) {
567
+ break;
568
+ }
569
+
570
+ removeOffsets.add(line.number);
571
+ }
572
+ }
573
+
574
+ const kept = commentLines.filter((_, idx) => {
575
+ return !removeOffsets.has(idx);
576
+ });
577
+ if (commentHasText(kept.join('\n'))) {
578
+ let nextLines = kept;
579
+ const indent = /** @type {RegExpExecArray} */ (
580
+ (/^[ \t]*/v).exec(/** @type {string} */ (commentLines[0]))
581
+ )[0];
582
+ if (!nextLines.some((line) => {
583
+ return line.includes('/**');
584
+ })) {
585
+ nextLines = [
586
+ `${indent}/**`, ...nextLines,
587
+ ];
588
+ }
589
+
590
+ if (!nextLines.at(-1)?.includes('*/')) {
591
+ nextLines = [
592
+ ...nextLines, `${indent} */`,
593
+ ];
594
+ }
595
+
596
+ fixes.push(fixer.replaceText(jsdocNode, nextLines.join(lineBreak)));
597
+ } else {
598
+ fixes.push(removeJsdocFix(fixer));
599
+ }
600
+
601
+ for (const move of moves) {
602
+ const propLine = /** @type {string} */ (sourceCode.lines[
603
+ /** @type {import('eslint').AST.SourceLocation} */
604
+ (move.prop.loc).start.line - 1
605
+ ]);
606
+ const indent = /** @type {RegExpExecArray} */ (
607
+ (/^[ \t]*/v).exec(propLine)
608
+ )[0];
609
+ const descriptionLines = move.description.split('\n');
610
+ const insertion = `/**${lineBreak}${descriptionLines.map((line) => {
611
+ return `${indent} *${line ? ` ${line}` : ''}`;
612
+ }).join(lineBreak)}${lineBreak}${indent} */${lineBreak}${indent}`;
613
+ fixes.push(fixer.insertTextBefore(move.prop, insertion));
614
+ }
615
+
616
+ return fixes;
617
+ };
618
+ };
619
+
620
+ const propertyRelocationFixer = getPropertyRelocationFixer();
621
+
258
622
  for (let tagIndex = 0; tagIndex < jsdoc.tags.length; tagIndex += 1) {
259
623
  const jsdocTag = jsdoc.tags[tagIndex];
260
624
  const tagName = jsdocTag.tag;
625
+
626
+ if (propertyRelocationFixer && isRelocatablePropertyTag(tagName)) {
627
+ const message = tagName === 'property' ?
628
+ `'@${tagName}' is redundant when using a type system.` :
629
+ `Invalid JSDoc tag (preference). Replace "${tagName}" JSDoc tag with "property".`;
630
+ report(message, propertyRelocationFixer, jsdocTag);
631
+ continue;
632
+ }
633
+
261
634
  if (jsxTags && jsxTagNames.has(tagName)) {
262
635
  continue;
263
636
  }
@@ -11,6 +11,9 @@ import {
11
11
  traverse,
12
12
  tryParse as tryParseType,
13
13
  } from '@es-joy/jsdoccomment';
14
+ import {
15
+ parse as espree,
16
+ } from 'espree';
14
17
 
15
18
  export default iterateJsdoc(({
16
19
  jsdoc,
@@ -41,8 +44,12 @@ export default iterateJsdoc(({
41
44
  let parsedType;
42
45
  try {
43
46
  parsedType = mode === 'permissive' ?
44
- tryParseType(/** @type {string} */ (potentialType)) :
45
- parseType(/** @type {string} */ (potentialType), mode);
47
+ tryParseType(/** @type {string} */ (potentialType), undefined, {
48
+ computedPropertyParser: espree,
49
+ }) :
50
+ parseType(/** @type {string} */ (potentialType), mode, {
51
+ computedPropertyParser: espree,
52
+ });
46
53
  } catch {
47
54
  return;
48
55
  }
@@ -5,6 +5,9 @@ import {
5
5
  tryParse,
6
6
  } from '@es-joy/jsdoccomment';
7
7
  import * as resolve from '@es-joy/resolve.exports';
8
+ import {
9
+ parse as espree,
10
+ } from 'espree';
8
11
  import {
9
12
  readFileSync,
10
13
  } from 'node:fs';
@@ -69,7 +72,13 @@ export default iterateJsdoc(({
69
72
  for (const tag of jsdoc.tags) {
70
73
  let typeAst;
71
74
  try {
72
- typeAst = mode === 'permissive' ? tryParse(tag.type) : parse(tag.type, mode);
75
+ typeAst = mode === 'permissive' ?
76
+ tryParse(tag.type, undefined, {
77
+ computedPropertyParser: espree,
78
+ }) :
79
+ parse(tag.type, mode, {
80
+ computedPropertyParser: espree,
81
+ });
73
82
  } catch {
74
83
  continue;
75
84
  }
@@ -11,6 +11,9 @@ import {
11
11
  traverse,
12
12
  tryParse as tryParseType,
13
13
  } from '@es-joy/jsdoccomment';
14
+ import {
15
+ parse as espree,
16
+ } from 'espree';
14
17
  import {
15
18
  parseImportsExports,
16
19
  } from 'parse-imports-exports';
@@ -805,8 +808,12 @@ export default iterateJsdoc(({
805
808
  ];
806
809
  return {
807
810
  parsedType: mode === 'permissive' ?
808
- tryParseType(/** @type {string} */ (potentialType)) :
809
- parseType(/** @type {string} */ (potentialType), mode),
811
+ tryParseType(/** @type {string} */ (potentialType), undefined, {
812
+ computedPropertyParser: espree,
813
+ }) :
814
+ parseType(/** @type {string} */ (potentialType), mode, {
815
+ computedPropertyParser: espree,
816
+ }),
810
817
  tag,
811
818
  };
812
819
  } catch {
@@ -1,6 +1,9 @@
1
1
  import iterateJsdoc, {
2
2
  parseComment,
3
3
  } from '../iterateJsdoc.js';
4
+ import {
5
+ generate,
6
+ } from '@es-joy/escodegen';
4
7
  import {
5
8
  commentParserToESTree,
6
9
  estreeToString,
@@ -13,6 +16,9 @@ import {
13
16
  import {
14
17
  Linter,
15
18
  } from 'eslint';
19
+ import {
20
+ parse as espree,
21
+ } from 'espree';
16
22
  import {
17
23
  parseImportsExports,
18
24
  } from 'parse-imports-exports';
@@ -44,7 +50,15 @@ export default iterateJsdoc(({
44
50
  })
45
51
  .map((commentNode) => {
46
52
  return commentParserToESTree(
47
- parseComment(commentNode, ''), mode === 'permissive' ? 'typescript' : mode,
53
+ parseComment(commentNode, ''),
54
+ mode === 'permissive' ? 'typescript' : mode,
55
+ {
56
+ jsdocTypePrattParserArgs: {
57
+ // Pass it for parity, but probably not needed
58
+ // with the typedefs and import statements below
59
+ computedPropertyParser: espree,
60
+ },
61
+ },
48
62
  );
49
63
  });
50
64
 
@@ -145,8 +159,12 @@ export default iterateJsdoc(({
145
159
  let parsedType;
146
160
  try {
147
161
  parsedType = mode === 'permissive' ?
148
- tryParseType(/** @type {string} */ (potentialType)) :
149
- parseType(/** @type {string} */ (potentialType), mode);
162
+ tryParseType(/** @type {string} */ (potentialType), undefined, {
163
+ computedPropertyParser: espree,
164
+ }) :
165
+ parseType(/** @type {string} */ (potentialType), mode, {
166
+ computedPropertyParser: espree,
167
+ });
150
168
  } catch {
151
169
  return;
152
170
  }
@@ -193,7 +211,7 @@ export default iterateJsdoc(({
193
211
 
194
212
  pathSegments.unshift(
195
213
  currentNode.right.type === 'JsdocTypeIndexedAccessIndex' ?
196
- stringify(currentNode.right.right) :
214
+ stringify(currentNode.right.right, generate) :
197
215
  currentNode.right.value,
198
216
  );
199
217
  nodes.unshift(currentNode);
@@ -272,7 +290,7 @@ export default iterateJsdoc(({
272
290
 
273
291
  for (const src of tag.source) {
274
292
  if (src.tokens.type) {
275
- src.tokens.type = `{${stringify(parsedType)}}`;
293
+ src.tokens.type = `{${stringify(parsedType, generate)}}`;
276
294
  break;
277
295
  }
278
296
  }
@@ -303,7 +321,7 @@ export default iterateJsdoc(({
303
321
 
304
322
  if (
305
323
  (typedefNode.right.type === 'JsdocTypeIndexedAccessIndex' &&
306
- stringify(typedefNode.right.right) !== pathSegment) ||
324
+ stringify(typedefNode.right.right, generate) !== pathSegment) ||
307
325
  (typedefNode.right.type !== 'JsdocTypeIndexedAccessIndex' &&
308
326
  typedefNode.right.value !== pathSegment)
309
327
  ) {
@@ -351,7 +369,9 @@ export default iterateJsdoc(({
351
369
  const findMatchingImport = () => {
352
370
  for (const imprt of imports) {
353
371
  const parsedImport = parseImportsExports(
354
- estreeToString(imprt).replace(/^\s*@/v, '').trim(),
372
+ estreeToString(imprt, {
373
+ jtppStringificationRules: generate,
374
+ }).replace(/^\s*@/v, '').trim(),
355
375
  );
356
376
 
357
377
  const namedImportsModuleSpecifier = Object.keys(parsedImport.namedImports || {})[0];
@@ -7,6 +7,9 @@ import {
7
7
  traverse,
8
8
  tryParse as tryParseType,
9
9
  } from '@es-joy/jsdoccomment';
10
+ import {
11
+ parse as espree,
12
+ } from 'espree';
10
13
 
11
14
  /**
12
15
  * @type {Partial<Record<import('../jsdocUtils.js').ParserMode, import('jsdoc-type-pratt-parser').ParseMode[]>>}
@@ -152,7 +155,9 @@ export default iterateJsdoc(({
152
155
  const returnType = returnTag.type.trim();
153
156
  let parsedType;
154
157
  try {
155
- parsedType = tryParseType(returnType, parseTypeModes[parseMode]);
158
+ parsedType = tryParseType(returnType, parseTypeModes[parseMode], {
159
+ computedPropertyParser: espree,
160
+ });
156
161
  } catch {
157
162
  return false;
158
163
  }
@@ -4,6 +4,9 @@ import {
4
4
  traverse,
5
5
  tryParse as tryParseType,
6
6
  } from '@es-joy/jsdoccomment';
7
+ import {
8
+ parse as espree,
9
+ } from 'espree';
7
10
 
8
11
  export default iterateJsdoc(({
9
12
  context,
@@ -128,8 +131,12 @@ export default iterateJsdoc(({
128
131
  let parsedType;
129
132
  try {
130
133
  parsedType = mode === 'permissive' ?
131
- tryParseType(/** @type {string} */ (potentialTag.type)) :
132
- parseType(/** @type {string} */ (potentialTag.type), mode);
134
+ tryParseType(/** @type {string} */ (potentialTag.type), undefined, {
135
+ computedPropertyParser: espree,
136
+ }) :
137
+ parseType(/** @type {string} */ (potentialTag.type), mode, {
138
+ computedPropertyParser: espree,
139
+ });
133
140
  } catch {
134
141
  return;
135
142
  }
@@ -6,6 +6,9 @@ import {
6
6
  parse as parseType,
7
7
  traverse,
8
8
  } from '@es-joy/jsdoccomment';
9
+ import {
10
+ parse as espree,
11
+ } from 'espree';
9
12
 
10
13
  export default iterateJsdoc(({
11
14
  context,
@@ -26,7 +29,11 @@ export default iterateJsdoc(({
26
29
  let parsedType;
27
30
  try {
28
31
  parsedType = parseType(
29
- /** @type {string} */ (potentialType), 'typescript',
32
+ /** @type {string} */ (potentialType),
33
+ 'typescript',
34
+ {
35
+ computedPropertyParser: espree,
36
+ },
30
37
  );
31
38
  } catch {
32
39
  return;
@@ -3,6 +3,9 @@ import {
3
3
  parse as parseType,
4
4
  traverse,
5
5
  } from '@es-joy/jsdoccomment';
6
+ import {
7
+ parse as espree,
8
+ } from 'espree';
6
9
 
7
10
  export default iterateJsdoc(({
8
11
  settings,
@@ -20,7 +23,11 @@ export default iterateJsdoc(({
20
23
  let parsedType;
21
24
  try {
22
25
  parsedType = parseType(
23
- /** @type {string} */ (potentialType), 'typescript',
26
+ /** @type {string} */ (potentialType),
27
+ 'typescript',
28
+ {
29
+ computedPropertyParser: espree,
30
+ },
24
31
  );
25
32
  } catch {
26
33
  return;
@@ -6,6 +6,9 @@ import {
6
6
  parse as parseType,
7
7
  traverse,
8
8
  } from '@es-joy/jsdoccomment';
9
+ import {
10
+ parse as espree,
11
+ } from 'espree';
9
12
 
10
13
  export default iterateJsdoc(({
11
14
  context,
@@ -31,7 +34,11 @@ export default iterateJsdoc(({
31
34
  let parsedType;
32
35
  try {
33
36
  parsedType = parseType(
34
- /** @type {string} */ (potentialType), 'typescript',
37
+ /** @type {string} */ (potentialType),
38
+ 'typescript',
39
+ {
40
+ computedPropertyParser: espree,
41
+ },
35
42
  );
36
43
  } catch {
37
44
  return;
@@ -6,6 +6,9 @@ import {
6
6
  parse as parseType,
7
7
  traverse,
8
8
  } from '@es-joy/jsdoccomment';
9
+ import {
10
+ parse as espree,
11
+ } from 'espree';
9
12
 
10
13
  export default iterateJsdoc(({
11
14
  context,
@@ -27,7 +30,11 @@ export default iterateJsdoc(({
27
30
  let parsedType;
28
31
  try {
29
32
  parsedType = parseType(
30
- /** @type {string} */ (potentialType), 'typescript',
33
+ /** @type {string} */ (potentialType),
34
+ 'typescript',
35
+ {
36
+ computedPropertyParser: espree,
37
+ },
31
38
  );
32
39
  } catch {
33
40
  return;
@@ -2,12 +2,18 @@ import iterateJsdoc from '../iterateJsdoc.js';
2
2
  import {
3
3
  rewireByParsedType,
4
4
  } from '../jsdocUtils.js';
5
+ import {
6
+ generate,
7
+ } from '@es-joy/escodegen';
5
8
  import {
6
9
  parse as parseType,
7
10
  stringify,
8
11
  traverse,
9
12
  tryParse as tryParseType,
10
13
  } from '@es-joy/jsdoccomment';
14
+ import {
15
+ parse as espree,
16
+ } from 'espree';
11
17
 
12
18
  const digitRegex = (/^(\d+(\.\d*)?|\.\d+)([eE][\-+]?\d+)?$/v);
13
19
 
@@ -65,8 +71,12 @@ export default iterateJsdoc(({
65
71
  let parsedType;
66
72
  try {
67
73
  parsedType = mode === 'permissive' ?
68
- tryParseType(/** @type {string} */ (potentialType)) :
69
- parseType(/** @type {string} */ (potentialType), mode);
74
+ tryParseType(/** @type {string} */ (potentialType), undefined, {
75
+ computedPropertyParser: espree,
76
+ }) :
77
+ parseType(/** @type {string} */ (potentialType), mode, {
78
+ computedPropertyParser: espree,
79
+ });
70
80
  } catch {
71
81
  return;
72
82
  }
@@ -342,9 +352,9 @@ export default iterateJsdoc(({
342
352
  /* c8 ignore next 5 -- jsdoc-type-pratt-parser doesn't encode as should */
343
353
  ((typeNode.meta.trailingPunctuation ?? false) !== objectFieldSeparatorTrailingPunctuation &&
344
354
  ((typeNode.meta.trailingPunctuation && (!trailingPunctuationMultilineOnly ||
345
- !stringify(typeNode).includes('\n'))) ||
355
+ !stringify(typeNode, generate).includes('\n'))) ||
346
356
  (!typeNode.meta.trailingPunctuation && (!trailingPunctuationMultilineOnly ||
347
- stringify(typeNode).includes('\n')))))
357
+ stringify(typeNode, generate).includes('\n')))))
348
358
  ) {
349
359
  typeNode.meta.separator = objectFieldSeparatorOptionalLinebreak && !separator.endsWith('and-linebreak') ?
350
360
  objectFieldSeparator.replace(/-and-linebreak$/v, '') :
@@ -465,7 +475,7 @@ export default iterateJsdoc(({
465
475
  });
466
476
 
467
477
  const differentResult = tag.type !==
468
- typeBracketSpacing + stringify(parsedType) + typeBracketSpacing;
478
+ typeBracketSpacing + stringify(parsedType, generate) + typeBracketSpacing;
469
479
 
470
480
  if (errorMessages.length && differentResult) {
471
481
  for (const errorMessage of errorMessages) {
@@ -6,6 +6,9 @@ import {
6
6
  traverse,
7
7
  tryParse,
8
8
  } from '@es-joy/jsdoccomment';
9
+ import {
10
+ parse as espree,
11
+ } from 'espree';
9
12
 
10
13
  const inlineTags = new Set([
11
14
  // Typdoc
@@ -219,10 +222,12 @@ export default iterateJsdoc(({
219
222
  if (mode === 'permissive') {
220
223
  parsedTypes = tryParse(type, undefined, {
221
224
  classContext: true,
225
+ computedPropertyParser: espree,
222
226
  });
223
227
  } else {
224
228
  parsedTypes = parse(type, mode, {
225
229
  classContext: true,
230
+ computedPropertyParser: espree,
226
231
  });
227
232
  }
228
233
  } catch {
@@ -293,6 +298,7 @@ export default iterateJsdoc(({
293
298
  let parsedTypes;
294
299
 
295
300
  try {
301
+ // We don't need the second arg. for `closure` mode
296
302
  parsedTypes = tryParse(tag.type);
297
303
  } catch {
298
304
  // Ignore