eslint-plugin-jsdoc 65.3.3 → 65.3.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/jsdocUtils.js +23 -7
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.3"
166
+ "version": "65.3.4"
167
167
  }
package/src/jsdocUtils.js CHANGED
@@ -1083,18 +1083,34 @@ const isNameOrNamepathDefiningTag = (tag, tagMap = tagStructure) => {
1083
1083
  tagStruct.get('namepathRole')));
1084
1084
  };
1085
1085
 
1086
+ /**
1087
+ * The parsed JSDoc blocks of each file (and fix pass), keyed by its
1088
+ * `SourceCode` object. Rules such as `no-undefined-types` and
1089
+ * `require-returns-check` ask for all blocks of the file once per JSDoc
1090
+ * block they check, so without this, every comment of the file was parsed
1091
+ * again for each block (quadratic time on larger files).
1092
+ * @type {WeakMap<import('eslint').SourceCode, import('@es-joy/jsdoccomment').JsdocBlockWithInline[]>}
1093
+ */
1094
+ const jsdocCommentBlocksCache = new WeakMap();
1095
+
1086
1096
  /**
1087
1097
  * @param {import('eslint').SourceCode} sourceCode
1088
1098
  * @returns {import('@es-joy/jsdoccomment').JsdocBlockWithInline[]}
1089
1099
  */
1090
1100
  const getJSDocCommentBlocks = (sourceCode) => {
1091
- return sourceCode.getAllComments()
1092
- .filter((comment) => {
1093
- return (/^\*(?!\*)/v).test(comment.value);
1094
- })
1095
- .map((commentNode) => {
1096
- return parseComment(commentNode, '');
1097
- });
1101
+ let blocks = jsdocCommentBlocksCache.get(sourceCode);
1102
+ if (!blocks) {
1103
+ blocks = sourceCode.getAllComments()
1104
+ .filter((comment) => {
1105
+ return (/^\*(?!\*)/v).test(comment.value);
1106
+ })
1107
+ .map((commentNode) => {
1108
+ return parseComment(commentNode, '');
1109
+ });
1110
+ jsdocCommentBlocksCache.set(sourceCode, blocks);
1111
+ }
1112
+
1113
+ return blocks;
1098
1114
  };
1099
1115
 
1100
1116
  /**