eslint-plugin-jsdoc 55.3.0 → 56.0.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.
Files changed (156) hide show
  1. package/dist/cjs/WarnSettings.d.ts +16 -0
  2. package/dist/cjs/WarnSettings.js +30 -0
  3. package/dist/cjs/alignTransform.d.ts +33 -0
  4. package/dist/cjs/alignTransform.js +285 -0
  5. package/dist/cjs/defaultTagOrder.d.ts +4 -0
  6. package/dist/cjs/defaultTagOrder.js +152 -0
  7. package/dist/cjs/exportParser.d.ts +40 -0
  8. package/dist/cjs/exportParser.js +754 -0
  9. package/dist/cjs/getDefaultTagStructureForMode.d.ts +10 -0
  10. package/dist/cjs/getDefaultTagStructureForMode.js +840 -0
  11. package/dist/cjs/getJsdocProcessorPlugin.cjs +4 -0
  12. package/dist/cjs/getJsdocProcessorPlugin.d.cts +1 -0
  13. package/dist/cjs/getJsdocProcessorPlugin.d.ts +66 -0
  14. package/dist/cjs/getJsdocProcessorPlugin.js +553 -0
  15. package/dist/cjs/index-cjs.d.ts +16 -0
  16. package/dist/cjs/index-cjs.js +492 -0
  17. package/dist/cjs/index.cjs.cjs +6 -0
  18. package/dist/cjs/index.cjs.d.cts +2 -0
  19. package/dist/cjs/iterateJsdoc.cjs +38 -0
  20. package/dist/cjs/iterateJsdoc.d.cts +2 -0
  21. package/dist/cjs/iterateJsdoc.d.ts +462 -0
  22. package/dist/cjs/iterateJsdoc.js +1981 -0
  23. package/dist/cjs/jsdocUtils.d.ts +454 -0
  24. package/dist/cjs/jsdocUtils.js +1470 -0
  25. package/dist/cjs/rules/checkAccess.d.ts +2 -0
  26. package/dist/cjs/rules/checkAccess.js +35 -0
  27. package/dist/cjs/rules/checkAlignment.d.ts +2 -0
  28. package/dist/cjs/rules/checkAlignment.js +63 -0
  29. package/dist/cjs/rules/checkExamples.d.ts +3 -0
  30. package/dist/cjs/rules/checkExamples.js +486 -0
  31. package/dist/cjs/rules/checkIndentation.d.ts +2 -0
  32. package/dist/cjs/rules/checkIndentation.js +66 -0
  33. package/dist/cjs/rules/checkLineAlignment.d.ts +9 -0
  34. package/dist/cjs/rules/checkLineAlignment.js +297 -0
  35. package/dist/cjs/rules/checkParamNames.d.ts +2 -0
  36. package/dist/cjs/rules/checkParamNames.js +320 -0
  37. package/dist/cjs/rules/checkPropertyNames.d.ts +2 -0
  38. package/dist/cjs/rules/checkPropertyNames.js +105 -0
  39. package/dist/cjs/rules/checkSyntax.d.ts +2 -0
  40. package/dist/cjs/rules/checkSyntax.js +27 -0
  41. package/dist/cjs/rules/checkTagNames.d.ts +2 -0
  42. package/dist/cjs/rules/checkTagNames.js +252 -0
  43. package/dist/cjs/rules/checkTemplateNames.d.ts +2 -0
  44. package/dist/cjs/rules/checkTemplateNames.js +189 -0
  45. package/dist/cjs/rules/checkTypes.d.ts +2 -0
  46. package/dist/cjs/rules/checkTypes.js +421 -0
  47. package/dist/cjs/rules/checkValues.d.ts +2 -0
  48. package/dist/cjs/rules/checkValues.js +163 -0
  49. package/dist/cjs/rules/convertToJsdocComments.d.ts +251 -0
  50. package/dist/cjs/rules/convertToJsdocComments.js +313 -0
  51. package/dist/cjs/rules/emptyTags.d.ts +2 -0
  52. package/dist/cjs/rules/emptyTags.js +79 -0
  53. package/dist/cjs/rules/implementsOnClasses.d.ts +2 -0
  54. package/dist/cjs/rules/implementsOnClasses.js +63 -0
  55. package/dist/cjs/rules/importsAsDependencies.d.ts +2 -0
  56. package/dist/cjs/rules/importsAsDependencies.js +105 -0
  57. package/dist/cjs/rules/informativeDocs.d.ts +2 -0
  58. package/dist/cjs/rules/informativeDocs.js +153 -0
  59. package/dist/cjs/rules/linesBeforeBlock.d.ts +2 -0
  60. package/dist/cjs/rules/linesBeforeBlock.js +106 -0
  61. package/dist/cjs/rules/matchDescription.d.ts +2 -0
  62. package/dist/cjs/rules/matchDescription.js +240 -0
  63. package/dist/cjs/rules/matchName.d.ts +2 -0
  64. package/dist/cjs/rules/matchName.js +122 -0
  65. package/dist/cjs/rules/multilineBlocks.d.ts +2 -0
  66. package/dist/cjs/rules/multilineBlocks.js +339 -0
  67. package/dist/cjs/rules/noBadBlocks.d.ts +2 -0
  68. package/dist/cjs/rules/noBadBlocks.js +88 -0
  69. package/dist/cjs/rules/noBlankBlockDescriptions.d.ts +2 -0
  70. package/dist/cjs/rules/noBlankBlockDescriptions.js +56 -0
  71. package/dist/cjs/rules/noBlankBlocks.d.ts +2 -0
  72. package/dist/cjs/rules/noBlankBlocks.js +41 -0
  73. package/dist/cjs/rules/noDefaults.d.ts +2 -0
  74. package/dist/cjs/rules/noDefaults.js +84 -0
  75. package/dist/cjs/rules/noMissingSyntax.d.ts +9 -0
  76. package/dist/cjs/rules/noMissingSyntax.js +164 -0
  77. package/dist/cjs/rules/noMultiAsterisks.d.ts +2 -0
  78. package/dist/cjs/rules/noMultiAsterisks.js +83 -0
  79. package/dist/cjs/rules/noRestrictedSyntax.d.ts +2 -0
  80. package/dist/cjs/rules/noRestrictedSyntax.js +75 -0
  81. package/dist/cjs/rules/noTypes.d.ts +2 -0
  82. package/dist/cjs/rules/noTypes.js +88 -0
  83. package/dist/cjs/rules/noUndefinedTypes.d.ts +2 -0
  84. package/dist/cjs/rules/noUndefinedTypes.js +451 -0
  85. package/dist/cjs/rules/requireAsteriskPrefix.d.ts +2 -0
  86. package/dist/cjs/rules/requireAsteriskPrefix.js +144 -0
  87. package/dist/cjs/rules/requireDescription.d.ts +2 -0
  88. package/dist/cjs/rules/requireDescription.js +136 -0
  89. package/dist/cjs/rules/requireDescriptionCompleteSentence.d.ts +2 -0
  90. package/dist/cjs/rules/requireDescriptionCompleteSentence.js +258 -0
  91. package/dist/cjs/rules/requireExample.d.ts +2 -0
  92. package/dist/cjs/rules/requireExample.js +103 -0
  93. package/dist/cjs/rules/requireFileOverview.d.ts +2 -0
  94. package/dist/cjs/rules/requireFileOverview.js +117 -0
  95. package/dist/cjs/rules/requireHyphenBeforeParamDescription.d.ts +2 -0
  96. package/dist/cjs/rules/requireHyphenBeforeParamDescription.js +144 -0
  97. package/dist/cjs/rules/requireJsdoc.d.ts +25 -0
  98. package/dist/cjs/rules/requireJsdoc.js +629 -0
  99. package/dist/cjs/rules/requireParam.d.ts +3 -0
  100. package/dist/cjs/rules/requireParam.js +480 -0
  101. package/dist/cjs/rules/requireParamDescription.d.ts +2 -0
  102. package/dist/cjs/rules/requireParamDescription.js +77 -0
  103. package/dist/cjs/rules/requireParamName.d.ts +2 -0
  104. package/dist/cjs/rules/requireParamName.js +52 -0
  105. package/dist/cjs/rules/requireParamType.d.ts +2 -0
  106. package/dist/cjs/rules/requireParamType.js +77 -0
  107. package/dist/cjs/rules/requireProperty.d.ts +2 -0
  108. package/dist/cjs/rules/requireProperty.js +44 -0
  109. package/dist/cjs/rules/requirePropertyDescription.d.ts +2 -0
  110. package/dist/cjs/rules/requirePropertyDescription.js +22 -0
  111. package/dist/cjs/rules/requirePropertyName.d.ts +2 -0
  112. package/dist/cjs/rules/requirePropertyName.js +22 -0
  113. package/dist/cjs/rules/requirePropertyType.d.ts +2 -0
  114. package/dist/cjs/rules/requirePropertyType.js +22 -0
  115. package/dist/cjs/rules/requireReturns.d.ts +2 -0
  116. package/dist/cjs/rules/requireReturns.js +197 -0
  117. package/dist/cjs/rules/requireReturnsCheck.d.ts +2 -0
  118. package/dist/cjs/rules/requireReturnsCheck.js +108 -0
  119. package/dist/cjs/rules/requireReturnsDescription.d.ts +2 -0
  120. package/dist/cjs/rules/requireReturnsDescription.js +58 -0
  121. package/dist/cjs/rules/requireReturnsType.d.ts +2 -0
  122. package/dist/cjs/rules/requireReturnsType.js +52 -0
  123. package/dist/cjs/rules/requireTemplate.d.ts +2 -0
  124. package/dist/cjs/rules/requireTemplate.js +173 -0
  125. package/dist/cjs/rules/requireThrows.d.ts +2 -0
  126. package/dist/cjs/rules/requireThrows.js +101 -0
  127. package/dist/cjs/rules/requireYields.d.ts +2 -0
  128. package/dist/cjs/rules/requireYields.js +172 -0
  129. package/dist/cjs/rules/requireYieldsCheck.d.ts +2 -0
  130. package/dist/cjs/rules/requireYieldsCheck.js +164 -0
  131. package/dist/cjs/rules/sortTags.d.ts +2 -0
  132. package/dist/cjs/rules/sortTags.js +392 -0
  133. package/dist/cjs/rules/tagLines.d.ts +2 -0
  134. package/dist/cjs/rules/tagLines.js +259 -0
  135. package/dist/cjs/rules/textEscaping.d.ts +2 -0
  136. package/dist/cjs/rules/textEscaping.js +125 -0
  137. package/dist/cjs/rules/typeFormatting.d.ts +2 -0
  138. package/dist/cjs/rules/typeFormatting.js +328 -0
  139. package/dist/cjs/rules/validTypes.d.ts +2 -0
  140. package/dist/cjs/rules/validTypes.js +333 -0
  141. package/dist/cjs/tagNames.d.ts +15 -0
  142. package/dist/cjs/tagNames.js +209 -0
  143. package/dist/cjs/utils/hasReturnValue.d.ts +19 -0
  144. package/dist/cjs/utils/hasReturnValue.js +469 -0
  145. package/dist/getJsdocProcessorPlugin.cts +3 -0
  146. package/dist/index.cjs.cts +3 -0
  147. package/dist/iterateJsdoc.cts +6 -0
  148. package/dist/rules/typeFormatting.cjs +82 -38
  149. package/dist/rules/typeFormatting.cjs.map +1 -1
  150. package/dist/rules.d.ts +4 -7
  151. package/package.json +24 -13
  152. package/src/getJsdocProcessorPlugin.cts +3 -0
  153. package/src/index.cjs.cts +3 -0
  154. package/src/iterateJsdoc.cts +6 -0
  155. package/src/rules/typeFormatting.js +104 -40
  156. package/src/rules.d.ts +4 -7
@@ -0,0 +1,754 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const jsdoccomment_1 = require("@es-joy/jsdoccomment");
7
+ const debug_1 = __importDefault(require("debug"));
8
+ const debug = (0, debug_1.default)('requireExportJsdoc');
9
+ /**
10
+ * @typedef {{
11
+ * value: string
12
+ * }} ValueObject
13
+ */
14
+ /**
15
+ * @typedef {{
16
+ * type?: string,
17
+ * value?: ValueObject|import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node,
18
+ * props: {
19
+ * [key: string]: CreatedNode|null,
20
+ * },
21
+ * special?: true,
22
+ * globalVars?: CreatedNode,
23
+ * exported?: boolean,
24
+ * ANONYMOUS_DEFAULT?: import('eslint').Rule.Node
25
+ * }} CreatedNode
26
+ */
27
+ /**
28
+ * @returns {CreatedNode}
29
+ */
30
+ const createNode = function () {
31
+ return {
32
+ props: {},
33
+ };
34
+ };
35
+ /**
36
+ * @param {CreatedNode|null} symbol
37
+ * @returns {string|null}
38
+ */
39
+ const getSymbolValue = function (symbol) {
40
+ /* c8 ignore next 3 */
41
+ if (!symbol) {
42
+ return null;
43
+ }
44
+ /* c8 ignore else */
45
+ if (symbol.type === 'literal') {
46
+ return /** @type {ValueObject} */ (symbol.value).value;
47
+ }
48
+ /* c8 ignore next 2 */
49
+ // eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
50
+ return null;
51
+ };
52
+ /**
53
+ *
54
+ * @param {import('estree').Identifier} node
55
+ * @param {CreatedNode} globals
56
+ * @param {CreatedNode} scope
57
+ * @param {SymbolOptions} opts
58
+ * @returns {CreatedNode|null}
59
+ */
60
+ const getIdentifier = function (node, globals, scope, opts) {
61
+ if (opts.simpleIdentifier) {
62
+ // Type is Identier for noncomputed properties
63
+ const identifierLiteral = createNode();
64
+ identifierLiteral.type = 'literal';
65
+ identifierLiteral.value = {
66
+ value: node.name,
67
+ };
68
+ return identifierLiteral;
69
+ }
70
+ /* c8 ignore next */
71
+ const block = scope || globals;
72
+ // As scopes are not currently supported, they are not traversed upwards recursively
73
+ if (block.props[node.name]) {
74
+ return block.props[node.name];
75
+ }
76
+ // Seems this will only be entered once scopes added and entered
77
+ /* c8 ignore next 3 */
78
+ if (globals.props[node.name]) {
79
+ return globals.props[node.name];
80
+ }
81
+ return null;
82
+ };
83
+ /**
84
+ * @callback CreateSymbol
85
+ * @param {import('eslint').Rule.Node|null} node
86
+ * @param {CreatedNode} globals
87
+ * @param {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node|null} value
88
+ * @param {CreatedNode} [scope]
89
+ * @param {boolean|SymbolOptions} [isGlobal]
90
+ * @returns {CreatedNode|null}
91
+ */
92
+ /** @type {CreateSymbol} */
93
+ let createSymbol; // eslint-disable-line prefer-const
94
+ /* eslint-disable complexity -- Temporary */
95
+ /**
96
+ * @typedef {{
97
+ * simpleIdentifier?: boolean
98
+ * }} SymbolOptions
99
+ */
100
+ /**
101
+ *
102
+ * @param {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node} node
103
+ * @param {CreatedNode} globals
104
+ * @param {CreatedNode} scope
105
+ * @param {SymbolOptions} [opt]
106
+ * @returns {CreatedNode|null}
107
+ */
108
+ const getSymbol = function (node, globals, scope, opt) {
109
+ /* eslint-enable complexity -- Temporary */
110
+ const opts = opt || {};
111
+ /* c8 ignore next */
112
+ switch (node.type) {
113
+ /* c8 ignore next 4 -- No longer needed? */
114
+ case 'ArrowFunctionExpression':
115
+ // Fallthrough
116
+ case 'ClassDeclaration':
117
+ case 'FunctionDeclaration':
118
+ case 'FunctionExpression':
119
+ case 'TSEnumDeclaration':
120
+ case 'TSInterfaceDeclaration':
121
+ case 'TSTypeAliasDeclaration': {
122
+ const val = createNode();
123
+ val.props.prototype = createNode();
124
+ val.props.prototype.type = 'object';
125
+ val.type = 'object';
126
+ val.value = node;
127
+ return val;
128
+ }
129
+ case 'AssignmentExpression': {
130
+ return createSymbol(
131
+ /** @type {import('eslint').Rule.Node} */
132
+ (node.left), globals,
133
+ /** @type {import('eslint').Rule.Node} */
134
+ (node.right), scope, opts);
135
+ }
136
+ case 'ClassBody': {
137
+ const val = createNode();
138
+ for (const method of node.body) {
139
+ // StaticBlock
140
+ if (!('key' in method)) {
141
+ continue;
142
+ }
143
+ val.props[
144
+ /** @type {import('estree').Identifier} */ (
145
+ /** @type {import('estree').MethodDefinition} */ (method).key).name] = createNode();
146
+ /** @type {{[key: string]: CreatedNode}} */ (val.props)[
147
+ /** @type {import('estree').Identifier} */ (
148
+ /** @type {import('estree').MethodDefinition} */ (method).key).name].type = 'object';
149
+ /** @type {{[key: string]: CreatedNode}} */ (val.props)[
150
+ /** @type {import('estree').Identifier} */ (
151
+ /** @type {import('estree').MethodDefinition} */ (method).key).name].value = /** @type {import('eslint').Rule.Node} */ (
152
+ /** @type {import('estree').MethodDefinition} */ (method).value);
153
+ }
154
+ val.type = 'object';
155
+ val.value = node.parent;
156
+ return val;
157
+ }
158
+ case 'ClassExpression': {
159
+ return getSymbol(
160
+ /** @type {import('eslint').Rule.Node} */
161
+ (node.body), globals, scope, opts);
162
+ }
163
+ case 'Identifier': {
164
+ return getIdentifier(node, globals, scope, opts);
165
+ }
166
+ case 'Literal': {
167
+ const val = createNode();
168
+ val.type = 'literal';
169
+ val.value = node;
170
+ return val;
171
+ }
172
+ case 'MemberExpression': {
173
+ const obj = getSymbol(
174
+ /** @type {import('eslint').Rule.Node} */
175
+ (node.object), globals, scope, opts);
176
+ const propertySymbol = getSymbol(
177
+ /** @type {import('eslint').Rule.Node} */
178
+ (node.property), globals, scope, {
179
+ simpleIdentifier: !node.computed,
180
+ });
181
+ const propertyValue = getSymbolValue(propertySymbol);
182
+ /* c8 ignore else */
183
+ if (obj && propertyValue && obj.props[propertyValue]) {
184
+ const block = obj.props[propertyValue];
185
+ return block;
186
+ }
187
+ /* c8 ignore next 11 */
188
+ /*
189
+ if (opts.createMissingProps && propertyValue) {
190
+ obj.props[propertyValue] = createNode();
191
+
192
+ return obj.props[propertyValue];
193
+ }
194
+ */
195
+ // eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
196
+ debug(`MemberExpression: Missing property ${
197
+ /** @type {import('estree').PrivateIdentifier} */ (node.property).name}`);
198
+ /* c8 ignore next 2 */
199
+ return null;
200
+ }
201
+ case 'ObjectExpression': {
202
+ const val = createNode();
203
+ val.type = 'object';
204
+ for (const prop of node.properties) {
205
+ if ([
206
+ // @babel/eslint-parser
207
+ 'ExperimentalSpreadProperty',
208
+ // typescript-eslint, espree, acorn, etc.
209
+ 'SpreadElement',
210
+ ].includes(prop.type)) {
211
+ continue;
212
+ }
213
+ const propVal = getSymbol(
214
+ /** @type {import('eslint').Rule.Node} */ (
215
+ /** @type {import('estree').Property} */
216
+ (prop).value), globals, scope, opts);
217
+ /* c8 ignore next 8 */
218
+ if (propVal) {
219
+ val.props[
220
+ /** @type {import('estree').PrivateIdentifier} */
221
+ (
222
+ /** @type {import('estree').Property} */ (prop).key).name] = propVal;
223
+ }
224
+ }
225
+ return val;
226
+ }
227
+ }
228
+ /* c8 ignore next 2 */
229
+ // eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
230
+ return null;
231
+ };
232
+ /**
233
+ *
234
+ * @param {CreatedNode} block
235
+ * @param {string} name
236
+ * @param {CreatedNode|null} value
237
+ * @param {CreatedNode} globals
238
+ * @param {boolean|SymbolOptions|undefined} isGlobal
239
+ * @returns {void}
240
+ */
241
+ const createBlockSymbol = function (block, name, value, globals, isGlobal) {
242
+ block.props[name] = value;
243
+ if (isGlobal && globals.props.window && globals.props.window.special) {
244
+ globals.props.window.props[name] = value;
245
+ }
246
+ };
247
+ createSymbol = function (node, globals, value, scope, isGlobal) {
248
+ const block = scope || globals;
249
+ /* c8 ignore next 3 */
250
+ if (!node) {
251
+ return null;
252
+ }
253
+ let symbol;
254
+ switch (node.type) {
255
+ case 'ClassDeclaration':
256
+ /* c8 ignore next */
257
+ // @ts-expect-error TS OK
258
+ // Fall through
259
+ case 'FunctionDeclaration':
260
+ case 'TSEnumDeclaration':
261
+ /* c8 ignore next */
262
+ // @ts-expect-error TS OK
263
+ // Fall through
264
+ case 'TSInterfaceDeclaration':
265
+ case 'TSTypeAliasDeclaration': {
266
+ const nde = /** @type {import('estree').ClassDeclaration} */ (node);
267
+ /* c8 ignore else */
268
+ if (nde.id && nde.id.type === 'Identifier') {
269
+ return createSymbol(
270
+ /** @type {import('eslint').Rule.Node} */ (nde.id), globals, node, globals);
271
+ }
272
+ /* c8 ignore next 3 */
273
+ // eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
274
+ break;
275
+ }
276
+ case 'Identifier': {
277
+ const nde = /** @type {import('estree').Identifier} */ (node);
278
+ if (value) {
279
+ const valueSymbol = getSymbol(value, globals, block);
280
+ /* c8 ignore else */
281
+ if (valueSymbol) {
282
+ createBlockSymbol(block, nde.name, valueSymbol, globals, isGlobal);
283
+ return block.props[nde.name];
284
+ }
285
+ /* c8 ignore next 2 */
286
+ // eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
287
+ debug('Identifier: Missing value symbol for %s', nde.name);
288
+ }
289
+ else {
290
+ createBlockSymbol(block, nde.name, createNode(), globals, isGlobal);
291
+ return block.props[nde.name];
292
+ }
293
+ /* c8 ignore next 3 */
294
+ // eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
295
+ break;
296
+ }
297
+ case 'MemberExpression': {
298
+ const nde = /** @type {import('estree').MemberExpression} */ (node);
299
+ symbol = getSymbol(
300
+ /** @type {import('eslint').Rule.Node} */ (nde.object), globals, block);
301
+ const propertySymbol = getSymbol(
302
+ /** @type {import('eslint').Rule.Node} */ (nde.property), globals, block, {
303
+ simpleIdentifier: !nde.computed,
304
+ });
305
+ const propertyValue = getSymbolValue(propertySymbol);
306
+ if (symbol && propertyValue) {
307
+ createBlockSymbol(symbol, propertyValue, getSymbol(
308
+ /** @type {import('eslint').Rule.Node} */
309
+ (value), globals, block), globals, isGlobal);
310
+ return symbol.props[propertyValue];
311
+ }
312
+ debug('MemberExpression: Missing symbol: %s',
313
+ /** @type {import('estree').Identifier} */ (nde.property).name);
314
+ break;
315
+ }
316
+ }
317
+ return null;
318
+ };
319
+ /**
320
+ * Creates variables from variable definitions
321
+ * @param {import('eslint').Rule.Node} node
322
+ * @param {CreatedNode} globals
323
+ * @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opts
324
+ * @returns {void}
325
+ */
326
+ const initVariables = function (node, globals, opts) {
327
+ switch (node.type) {
328
+ case 'ExportNamedDeclaration': {
329
+ if (node.declaration) {
330
+ initVariables(
331
+ /** @type {import('eslint').Rule.Node} */
332
+ (node.declaration), globals, opts);
333
+ }
334
+ break;
335
+ }
336
+ case 'ExpressionStatement': {
337
+ initVariables(
338
+ /** @type {import('eslint').Rule.Node} */
339
+ (node.expression), globals, opts);
340
+ break;
341
+ }
342
+ case 'Program': {
343
+ for (const childNode of node.body) {
344
+ initVariables(
345
+ /** @type {import('eslint').Rule.Node} */
346
+ (childNode), globals, opts);
347
+ }
348
+ break;
349
+ }
350
+ case 'VariableDeclaration': {
351
+ for (const declaration of node.declarations) {
352
+ // let and const
353
+ const symbol = createSymbol(
354
+ /** @type {import('eslint').Rule.Node} */
355
+ (declaration.id), globals, null, globals);
356
+ if (opts.initWindow && node.kind === 'var' && globals.props.window) {
357
+ // If var, also add to window
358
+ globals.props.window.props[
359
+ /** @type {import('estree').Identifier} */
360
+ (declaration.id).name] = symbol;
361
+ }
362
+ }
363
+ break;
364
+ }
365
+ }
366
+ };
367
+ /* eslint-disable complexity -- Temporary */
368
+ /**
369
+ * Populates variable maps using AST
370
+ * @param {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node} node
371
+ * @param {CreatedNode} globals
372
+ * @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opt
373
+ * @param {true} [isExport]
374
+ * @returns {boolean}
375
+ */
376
+ const mapVariables = function (node, globals, opt, isExport) {
377
+ /* eslint-enable complexity -- Temporary */
378
+ /* c8 ignore next */
379
+ const opts = opt || {};
380
+ /* c8 ignore next */
381
+ switch (node.type) {
382
+ case 'AssignmentExpression': {
383
+ createSymbol(
384
+ /** @type {import('eslint').Rule.Node} */
385
+ (node.left), globals,
386
+ /** @type {import('eslint').Rule.Node} */
387
+ (node.right));
388
+ break;
389
+ }
390
+ case 'ClassDeclaration': {
391
+ createSymbol(
392
+ /** @type {import('eslint').Rule.Node|null} */ (node.id), globals,
393
+ /** @type {import('eslint').Rule.Node} */ (node.body), globals);
394
+ break;
395
+ }
396
+ case 'ExportDefaultDeclaration': {
397
+ const symbol = createSymbol(
398
+ /** @type {import('eslint').Rule.Node} */
399
+ (node.declaration), globals,
400
+ /** @type {import('eslint').Rule.Node} */
401
+ (node.declaration));
402
+ if (symbol) {
403
+ symbol.exported = true;
404
+ /* c8 ignore next 6 */
405
+ }
406
+ else {
407
+ // if (!node.id) {
408
+ globals.ANONYMOUS_DEFAULT = /** @type {import('eslint').Rule.Node} */ (node.declaration);
409
+ }
410
+ break;
411
+ }
412
+ case 'ExportNamedDeclaration': {
413
+ if (node.declaration) {
414
+ if (node.declaration.type === 'VariableDeclaration') {
415
+ mapVariables(
416
+ /** @type {import('eslint').Rule.Node} */
417
+ (node.declaration), globals, opts, true);
418
+ }
419
+ else {
420
+ const symbol = createSymbol(
421
+ /** @type {import('eslint').Rule.Node} */
422
+ (node.declaration), globals,
423
+ /** @type {import('eslint').Rule.Node} */
424
+ (node.declaration));
425
+ /* c8 ignore next 3 */
426
+ if (symbol) {
427
+ symbol.exported = true;
428
+ }
429
+ }
430
+ }
431
+ for (const specifier of node.specifiers) {
432
+ mapVariables(
433
+ /** @type {import('eslint').Rule.Node} */
434
+ (specifier), globals, opts);
435
+ }
436
+ break;
437
+ }
438
+ case 'ExportSpecifier': {
439
+ const symbol = getSymbol(
440
+ /** @type {import('eslint').Rule.Node} */
441
+ (node.local), globals, globals);
442
+ /* c8 ignore next 3 */
443
+ if (symbol) {
444
+ symbol.exported = true;
445
+ }
446
+ break;
447
+ }
448
+ case 'ExpressionStatement': {
449
+ mapVariables(
450
+ /** @type {import('eslint').Rule.Node} */
451
+ (node.expression), globals, opts);
452
+ break;
453
+ }
454
+ case 'FunctionDeclaration':
455
+ case 'TSTypeAliasDeclaration': {
456
+ /* c8 ignore next 10 */
457
+ if ( /** @type {import('estree').Identifier} */(node.id).type === 'Identifier') {
458
+ createSymbol(
459
+ /** @type {import('eslint').Rule.Node} */
460
+ (node.id), globals, node, globals, true);
461
+ }
462
+ break;
463
+ }
464
+ case 'Program': {
465
+ if (opts.ancestorsOnly) {
466
+ return false;
467
+ }
468
+ for (const childNode of node.body) {
469
+ mapVariables(
470
+ /** @type {import('eslint').Rule.Node} */
471
+ (childNode), globals, opts);
472
+ }
473
+ break;
474
+ }
475
+ case 'VariableDeclaration': {
476
+ for (const declaration of node.declarations) {
477
+ const isGlobal = Boolean(opts.initWindow && node.kind === 'var' && globals.props.window);
478
+ const symbol = createSymbol(
479
+ /** @type {import('eslint').Rule.Node} */
480
+ (declaration.id), globals,
481
+ /** @type {import('eslint').Rule.Node} */
482
+ (declaration.init), globals, isGlobal);
483
+ if (symbol && isExport) {
484
+ symbol.exported = true;
485
+ }
486
+ }
487
+ break;
488
+ }
489
+ default: {
490
+ /* c8 ignore next */
491
+ return false;
492
+ }
493
+ }
494
+ return true;
495
+ };
496
+ /**
497
+ *
498
+ * @param {import('eslint').Rule.Node} node
499
+ * @param {CreatedNode|ValueObject|string|undefined|
500
+ * import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node} block
501
+ * @param {(CreatedNode|ValueObject|string|
502
+ * import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node)[]} [cache]
503
+ * @returns {boolean}
504
+ */
505
+ const findNode = function (node, block, cache) {
506
+ let blockCache = cache || [];
507
+ if (!block || blockCache.includes(block)) {
508
+ return false;
509
+ }
510
+ blockCache = blockCache.slice();
511
+ blockCache.push(block);
512
+ if (typeof block === 'object' &&
513
+ 'type' in block &&
514
+ (block.type === 'object' || block.type === 'MethodDefinition') &&
515
+ block.value === node) {
516
+ return true;
517
+ }
518
+ if (typeof block !== 'object') {
519
+ return false;
520
+ }
521
+ const props = ('props' in block && block.props) || ('body' in block && block.body);
522
+ for (const propval of Object.values(props || {})) {
523
+ if (Array.isArray(propval)) {
524
+ /* c8 ignore next 5 */
525
+ if (propval.some((val) => {
526
+ return findNode(node, val, blockCache);
527
+ })) {
528
+ return true;
529
+ }
530
+ }
531
+ else if (findNode(node, propval, blockCache)) {
532
+ return true;
533
+ }
534
+ }
535
+ return false;
536
+ };
537
+ const exportTypes = new Set([
538
+ 'ExportDefaultDeclaration', 'ExportNamedDeclaration',
539
+ ]);
540
+ const ignorableNestedTypes = new Set([
541
+ 'ArrowFunctionExpression', 'FunctionDeclaration', 'FunctionExpression',
542
+ ]);
543
+ /**
544
+ * @param {import('eslint').Rule.Node} nde
545
+ * @returns {import('eslint').Rule.Node|false}
546
+ */
547
+ const getExportAncestor = function (nde) {
548
+ let node = nde;
549
+ let idx = 0;
550
+ const ignorableIfDeep = ignorableNestedTypes.has(nde?.type);
551
+ while (node) {
552
+ // Ignore functions nested more deeply than say `export default function () {}`
553
+ if (idx >= 2 && ignorableIfDeep) {
554
+ break;
555
+ }
556
+ if (exportTypes.has(node.type)) {
557
+ return node;
558
+ }
559
+ node = node.parent;
560
+ idx++;
561
+ }
562
+ return false;
563
+ };
564
+ const canBeExportedByAncestorType = new Set([
565
+ 'ClassProperty',
566
+ 'Method',
567
+ 'PropertyDefinition',
568
+ 'TSMethodSignature',
569
+ 'TSPropertySignature',
570
+ ]);
571
+ const canExportChildrenType = new Set([
572
+ 'ClassBody',
573
+ 'ClassDeclaration',
574
+ 'ClassDefinition',
575
+ 'ClassExpression',
576
+ 'Program',
577
+ 'TSInterfaceBody',
578
+ 'TSInterfaceDeclaration',
579
+ 'TSTypeAliasDeclaration',
580
+ 'TSTypeLiteral',
581
+ 'TSTypeParameterInstantiation',
582
+ 'TSTypeReference',
583
+ ]);
584
+ /**
585
+ * @param {import('eslint').Rule.Node} nde
586
+ * @returns {false|import('eslint').Rule.Node}
587
+ */
588
+ const isExportByAncestor = function (nde) {
589
+ if (!canBeExportedByAncestorType.has(nde.type)) {
590
+ return false;
591
+ }
592
+ let node = nde.parent;
593
+ while (node) {
594
+ if (exportTypes.has(node.type)) {
595
+ return node;
596
+ }
597
+ if (!canExportChildrenType.has(node.type)) {
598
+ return false;
599
+ }
600
+ node = node.parent;
601
+ }
602
+ return false;
603
+ };
604
+ /**
605
+ *
606
+ * @param {CreatedNode} block
607
+ * @param {import('eslint').Rule.Node} node
608
+ * @param {CreatedNode[]} [cache] Currently unused
609
+ * @returns {boolean}
610
+ */
611
+ const findExportedNode = function (block, node, cache) {
612
+ /* c8 ignore next 3 */
613
+ if (block === null) {
614
+ return false;
615
+ }
616
+ const blockCache = cache || [];
617
+ const { props, } = block;
618
+ for (const propval of Object.values(props)) {
619
+ const pval = /** @type {CreatedNode} */ (propval);
620
+ blockCache.push(pval);
621
+ if (pval.exported && (node === pval.value || findNode(node, pval.value))) {
622
+ return true;
623
+ }
624
+ // No need to check `propval` for exported nodes as ESM
625
+ // exports are only global
626
+ }
627
+ return false;
628
+ };
629
+ /**
630
+ *
631
+ * @param {import('eslint').Rule.Node} node
632
+ * @param {CreatedNode} globals
633
+ * @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opt
634
+ * @returns {boolean}
635
+ */
636
+ const isNodeExported = function (node, globals, opt) {
637
+ const moduleExports = globals.props.module?.props?.exports;
638
+ if (opt.initModuleExports && moduleExports && findNode(node, moduleExports)) {
639
+ return true;
640
+ }
641
+ if (opt.initWindow && globals.props.window && findNode(node, globals.props.window)) {
642
+ return true;
643
+ }
644
+ if (opt.esm && findExportedNode(globals, node)) {
645
+ return true;
646
+ }
647
+ return false;
648
+ };
649
+ /**
650
+ *
651
+ * @param {import('eslint').Rule.Node} node
652
+ * @param {CreatedNode} globalVars
653
+ * @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opts
654
+ * @returns {boolean}
655
+ */
656
+ const parseRecursive = function (node, globalVars, opts) {
657
+ // Iterate from top using recursion - stop at first processed node from top
658
+ if (node.parent && parseRecursive(node.parent, globalVars, opts)) {
659
+ return true;
660
+ }
661
+ return mapVariables(node, globalVars, opts);
662
+ };
663
+ /**
664
+ *
665
+ * @param {import('eslint').Rule.Node} ast
666
+ * @param {import('eslint').Rule.Node} node
667
+ * @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opt
668
+ * @returns {CreatedNode}
669
+ */
670
+ const parse = function (ast, node, opt) {
671
+ /* c8 ignore next 6 */
672
+ const opts = opt || {
673
+ ancestorsOnly: false,
674
+ esm: true,
675
+ initModuleExports: true,
676
+ initWindow: true,
677
+ };
678
+ const globalVars = createNode();
679
+ if (opts.initModuleExports) {
680
+ globalVars.props.module = createNode();
681
+ globalVars.props.module.props.exports = createNode();
682
+ globalVars.props.exports = globalVars.props.module.props.exports;
683
+ }
684
+ if (opts.initWindow) {
685
+ globalVars.props.window = createNode();
686
+ globalVars.props.window.special = true;
687
+ }
688
+ if (opts.ancestorsOnly) {
689
+ parseRecursive(node, globalVars, opts);
690
+ }
691
+ else {
692
+ initVariables(ast, globalVars, opts);
693
+ mapVariables(ast, globalVars, opts);
694
+ }
695
+ return {
696
+ globalVars,
697
+ props: {},
698
+ };
699
+ };
700
+ const accessibilityNodes = new Set([
701
+ 'MethodDefinition',
702
+ 'PropertyDefinition',
703
+ ]);
704
+ /**
705
+ *
706
+ * @param {import('eslint').Rule.Node} node
707
+ * @returns {boolean}
708
+ */
709
+ const isPrivate = (node) => {
710
+ return accessibilityNodes.has(node.type) &&
711
+ ('accessibility' in node &&
712
+ node.accessibility !== 'public' && node.accessibility !== undefined) ||
713
+ 'key' in node &&
714
+ node.key.type === 'PrivateIdentifier';
715
+ };
716
+ /**
717
+ *
718
+ * @param {import('eslint').Rule.Node} node
719
+ * @param {import('eslint').SourceCode} sourceCode
720
+ * @param {import('./rules/requireJsdoc.js').RequireJsdocOpts} opt
721
+ * @param {import('./iterateJsdoc.js').Settings} settings
722
+ * @returns {boolean}
723
+ */
724
+ const isUncommentedExport = function (node, sourceCode, opt, settings) {
725
+ // console.log({node});
726
+ // Optimize with ancestor check for esm
727
+ if (opt.esm) {
728
+ if (isPrivate(node) ||
729
+ node.parent && isPrivate(node.parent)) {
730
+ return false;
731
+ }
732
+ const exportNode = getExportAncestor(node);
733
+ // Is export node comment
734
+ if (exportNode && !(0, jsdoccomment_1.findJSDocComment)(exportNode, sourceCode, settings)) {
735
+ return true;
736
+ }
737
+ /**
738
+ * Some typescript types are not in variable map, but inherit exported (interface property and method)
739
+ */
740
+ if (isExportByAncestor(node) &&
741
+ !(0, jsdoccomment_1.findJSDocComment)(node, sourceCode, settings)) {
742
+ return true;
743
+ }
744
+ }
745
+ const ast = /** @type {unknown} */ (sourceCode.ast);
746
+ const parseResult = parse(
747
+ /** @type {import('eslint').Rule.Node} */
748
+ (ast), node, opt);
749
+ return isNodeExported(node, /** @type {CreatedNode} */ (parseResult.globalVars), opt);
750
+ };
751
+ exports.default = {
752
+ isUncommentedExport,
753
+ parse,
754
+ };