eslint-plugin-jsdoc 60.2.0 → 60.3.1

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.
@@ -59,8 +59,12 @@ export default iterateJsdoc(({
59
59
  report,
60
60
  settings,
61
61
  sourceCode,
62
+ state,
62
63
  utils,
63
64
  }) => {
65
+ /** @type {string[]} */
66
+ const foundTypedefValues = [];
67
+
64
68
  const {
65
69
  scopeManager,
66
70
  } = sourceCode;
@@ -73,11 +77,13 @@ export default iterateJsdoc(({
73
77
  const
74
78
  /**
75
79
  * @type {{
80
+ * checkUsedTypedefs: boolean
76
81
  * definedTypes: string[],
77
82
  * disableReporting: boolean,
78
- * markVariablesAsUsed: boolean
83
+ * markVariablesAsUsed: boolean,
79
84
  * }}
80
85
  */ {
86
+ checkUsedTypedefs = false,
81
87
  definedTypes = [],
82
88
  disableReporting = false,
83
89
  markVariablesAsUsed = true,
@@ -128,14 +134,16 @@ export default iterateJsdoc(({
128
134
  return commentNode.value.replace(/^\s*globals/v, '').trim().split(/,\s*/v);
129
135
  }).concat(Object.keys(context.languageOptions.globals ?? []));
130
136
 
131
- const typedefDeclarations = comments
137
+ const typedefs = comments
132
138
  .flatMap((doc) => {
133
139
  return doc.tags.filter(({
134
140
  tag,
135
141
  }) => {
136
142
  return utils.isNamepathDefiningTag(tag);
137
143
  });
138
- })
144
+ });
145
+
146
+ const typedefDeclarations = typedefs
139
147
  .map((tag) => {
140
148
  return tag.name;
141
149
  });
@@ -204,9 +212,9 @@ export default iterateJsdoc(({
204
212
  return [];
205
213
  }
206
214
 
207
- const jsdoc = parseComment(commentNode, '');
215
+ const jsdc = parseComment(commentNode, '');
208
216
 
209
- return jsdoc.tags.filter((tag) => {
217
+ return jsdc.tags.filter((tag) => {
210
218
  return tag.tag === 'template';
211
219
  });
212
220
  };
@@ -510,10 +518,74 @@ export default iterateJsdoc(({
510
518
  context.markVariableAsUsed(val);
511
519
  }
512
520
  }
521
+
522
+ if (checkUsedTypedefs && typedefDeclarations.includes(val)) {
523
+ foundTypedefValues.push(val);
524
+ }
513
525
  }
514
526
  });
515
527
  }
528
+
529
+ state.foundTypedefValues = foundTypedefValues;
516
530
  }, {
531
+ // We use this method rather than checking at end of handler above because
532
+ // in that case, it is invoked too many times and would thus report errors
533
+ // too many times.
534
+ exit ({
535
+ context,
536
+ state,
537
+ utils,
538
+ }) {
539
+ const {
540
+ checkUsedTypedefs = false,
541
+ } = context.options[0] || {};
542
+
543
+ if (!checkUsedTypedefs) {
544
+ return;
545
+ }
546
+
547
+ const allComments = context.sourceCode.getAllComments();
548
+ const comments = allComments
549
+ .filter((comment) => {
550
+ return (/^\*(?!\*)/v).test(comment.value);
551
+ })
552
+ .map((commentNode) => {
553
+ return {
554
+ doc: parseComment(commentNode, ''),
555
+ loc: commentNode.loc,
556
+ };
557
+ });
558
+ const typedefs = comments
559
+ .flatMap(({
560
+ doc,
561
+ loc,
562
+ }) => {
563
+ const tags = doc.tags.filter(({
564
+ tag,
565
+ }) => {
566
+ return utils.isNamepathDefiningTag(tag);
567
+ });
568
+ if (!tags.length) {
569
+ return [];
570
+ }
571
+
572
+ return {
573
+ loc,
574
+ tags,
575
+ };
576
+ });
577
+
578
+ for (const typedef of typedefs) {
579
+ if (
580
+ !state.foundTypedefValues.includes(typedef.tags[0].name)
581
+ ) {
582
+ context.report({
583
+ loc: /** @type {import('@eslint/core').SourceLocation} */ (typedef.loc),
584
+ message: 'This typedef was not used within the file',
585
+ });
586
+ }
587
+ }
588
+ },
517
589
  iterateAllJsdocs: true,
518
590
  meta: {
519
591
  docs: {
@@ -524,6 +596,10 @@ export default iterateJsdoc(({
524
596
  {
525
597
  additionalProperties: false,
526
598
  properties: {
599
+ checkUsedTypedefs: {
600
+ description: 'Whether to check typedefs for use within the file',
601
+ type: 'boolean',
602
+ },
527
603
  definedTypes: {
528
604
  description: `This array can be populated to indicate other types which
529
605
  are automatically considered as defined (in addition to globals, etc.).
@@ -536,7 +612,7 @@ Defaults to an empty array.`,
536
612
  disableReporting: {
537
613
  description: `Whether to disable reporting of errors. Defaults to
538
614
  \`false\`. This may be set to \`true\` in order to take advantage of only
539
- marking defined variables as used.`,
615
+ marking defined variables as used or checking used typedefs.`,
540
616
  type: 'boolean',
541
617
  },
542
618
  markVariablesAsUsed: {
package/src/rules.d.ts CHANGED
@@ -1250,6 +1250,10 @@ export interface Rules {
1250
1250
  | []
1251
1251
  | [
1252
1252
  {
1253
+ /**
1254
+ * Whether to check typedefs for use within the file
1255
+ */
1256
+ checkUsedTypedefs?: boolean;
1253
1257
  /**
1254
1258
  * This array can be populated to indicate other types which
1255
1259
  * are automatically considered as defined (in addition to globals, etc.).
@@ -1259,7 +1263,7 @@ export interface Rules {
1259
1263
  /**
1260
1264
  * Whether to disable reporting of errors. Defaults to
1261
1265
  * `false`. This may be set to `true` in order to take advantage of only
1262
- * marking defined variables as used.
1266
+ * marking defined variables as used or checking used typedefs.
1263
1267
  */
1264
1268
  disableReporting?: boolean;
1265
1269
  /**