eslint-plugin-jsdoc 44.2.2 → 44.2.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 (117) hide show
  1. package/dist/alignTransform.js +86 -4
  2. package/dist/alignTransform.js.map +1 -1
  3. package/dist/exportParser.js +134 -4
  4. package/dist/exportParser.js.map +1 -1
  5. package/dist/getDefaultTagStructureForMode.js +71 -62
  6. package/dist/getDefaultTagStructureForMode.js.map +1 -1
  7. package/dist/index.js +7 -5
  8. package/dist/index.js.map +1 -1
  9. package/dist/iterateJsdoc.js +1081 -111
  10. package/dist/iterateJsdoc.js.map +1 -1
  11. package/dist/jsdocUtils.js +381 -132
  12. package/dist/jsdocUtils.js.map +1 -1
  13. package/dist/rules/checkAlignment.js +6 -0
  14. package/dist/rules/checkAlignment.js.map +1 -1
  15. package/dist/rules/checkExamples.js +70 -6
  16. package/dist/rules/checkExamples.js.map +1 -1
  17. package/dist/rules/checkIndentation.js +11 -1
  18. package/dist/rules/checkIndentation.js.map +1 -1
  19. package/dist/rules/checkLineAlignment.js +69 -5
  20. package/dist/rules/checkLineAlignment.js.map +1 -1
  21. package/dist/rules/checkParamNames.js +12 -7
  22. package/dist/rules/checkParamNames.js.map +1 -1
  23. package/dist/rules/checkPropertyNames.js +13 -7
  24. package/dist/rules/checkPropertyNames.js.map +1 -1
  25. package/dist/rules/checkTagNames.js +45 -5
  26. package/dist/rules/checkTagNames.js.map +1 -1
  27. package/dist/rules/checkTypes.js +97 -36
  28. package/dist/rules/checkTypes.js.map +1 -1
  29. package/dist/rules/checkValues.js +6 -6
  30. package/dist/rules/checkValues.js.map +1 -1
  31. package/dist/rules/emptyTags.js +8 -1
  32. package/dist/rules/emptyTags.js.map +1 -1
  33. package/dist/rules/informativeDocs.js +26 -7
  34. package/dist/rules/informativeDocs.js.map +1 -1
  35. package/dist/rules/matchDescription.js +19 -2
  36. package/dist/rules/matchDescription.js.map +1 -1
  37. package/dist/rules/matchName.js +2 -2
  38. package/dist/rules/matchName.js.map +1 -1
  39. package/dist/rules/multilineBlocks.js +12 -1
  40. package/dist/rules/multilineBlocks.js.map +1 -1
  41. package/dist/rules/noBadBlocks.js +4 -6
  42. package/dist/rules/noBadBlocks.js.map +1 -1
  43. package/dist/rules/noBlankBlockDescriptions.js +2 -0
  44. package/dist/rules/noBlankBlockDescriptions.js.map +1 -1
  45. package/dist/rules/noMissingSyntax.js +58 -15
  46. package/dist/rules/noMissingSyntax.js.map +1 -1
  47. package/dist/rules/noMultiAsterisks.js +1 -6
  48. package/dist/rules/noMultiAsterisks.js.map +1 -1
  49. package/dist/rules/noRestrictedSyntax.js +17 -4
  50. package/dist/rules/noRestrictedSyntax.js.map +1 -1
  51. package/dist/rules/noTypes.js +3 -0
  52. package/dist/rules/noTypes.js.map +1 -1
  53. package/dist/rules/noUndefinedTypes.js +61 -20
  54. package/dist/rules/noUndefinedTypes.js.map +1 -1
  55. package/dist/rules/requireAsteriskPrefix.js +20 -0
  56. package/dist/rules/requireAsteriskPrefix.js.map +1 -1
  57. package/dist/rules/requireDescription.js +6 -2
  58. package/dist/rules/requireDescription.js.map +1 -1
  59. package/dist/rules/requireDescriptionCompleteSentence.js +73 -10
  60. package/dist/rules/requireDescriptionCompleteSentence.js.map +1 -1
  61. package/dist/rules/requireFileOverview.js +9 -4
  62. package/dist/rules/requireFileOverview.js.map +1 -1
  63. package/dist/rules/requireHyphenBeforeParamDescription.js +23 -6
  64. package/dist/rules/requireHyphenBeforeParamDescription.js.map +1 -1
  65. package/dist/rules/requireJsdoc.js +148 -30
  66. package/dist/rules/requireJsdoc.js.map +1 -1
  67. package/dist/rules/requireParam.js +46 -2
  68. package/dist/rules/requireParam.js.map +1 -1
  69. package/dist/rules/requireProperty.js +1 -1
  70. package/dist/rules/requireProperty.js.map +1 -1
  71. package/dist/rules/requireReturns.js +2 -2
  72. package/dist/rules/requireReturns.js.map +1 -1
  73. package/dist/rules/requireReturnsCheck.js +9 -2
  74. package/dist/rules/requireReturnsCheck.js.map +1 -1
  75. package/dist/rules/requireThrows.js +2 -2
  76. package/dist/rules/requireThrows.js.map +1 -1
  77. package/dist/rules/requireYields.js +9 -2
  78. package/dist/rules/requireYields.js.map +1 -1
  79. package/dist/rules/requireYieldsCheck.js +19 -5
  80. package/dist/rules/requireYieldsCheck.js.map +1 -1
  81. package/dist/rules/sortTags.js +67 -9
  82. package/dist/rules/sortTags.js.map +1 -1
  83. package/dist/rules/tagLines.js +22 -3
  84. package/dist/rules/tagLines.js.map +1 -1
  85. package/dist/rules/textEscaping.js +16 -2
  86. package/dist/rules/textEscaping.js.map +1 -1
  87. package/dist/rules/validTypes.js +25 -8
  88. package/dist/rules/validTypes.js.map +1 -1
  89. package/dist/tagNames.js +27 -0
  90. package/dist/tagNames.js.map +1 -1
  91. package/dist/utils/hasReturnValue.js +87 -42
  92. package/dist/utils/hasReturnValue.js.map +1 -1
  93. package/docs/rules/check-tag-names.md +15 -0
  94. package/docs/rules/no-missing-syntax.md +6 -0
  95. package/docs/rules/no-undefined-types.md +18 -0
  96. package/docs/rules/require-description-complete-sentence.md +525 -289
  97. package/docs/rules/require-description.md +289 -525
  98. package/docs/rules/require-file-overview.md +7 -0
  99. package/docs/rules/require-jsdoc.md +1 -1
  100. package/docs/rules/require-param-description.md +116 -1694
  101. package/docs/rules/require-param-name.md +58 -133
  102. package/docs/rules/require-param-type.md +119 -55
  103. package/docs/rules/require-param.md +1700 -111
  104. package/docs/rules/require-property-description.md +39 -79
  105. package/docs/rules/require-property-name.md +21 -30
  106. package/docs/rules/require-property-type.md +21 -21
  107. package/docs/rules/require-property.md +82 -33
  108. package/docs/rules/require-returns-check.md +636 -747
  109. package/docs/rules/require-returns-description.md +61 -933
  110. package/docs/rules/require-returns-type.md +42 -79
  111. package/docs/rules/require-returns.md +1081 -61
  112. package/docs/rules/require-yields-check.md +238 -517
  113. package/docs/rules/require-yields.md +517 -238
  114. package/docs/rules/valid-types.md +1 -1
  115. package/docs/settings.md +1 -1
  116. package/package.json +13 -5
  117. package/tsconfig.json +5 -2
@@ -15,6 +15,531 @@ var _jsdoccomment = require("@es-joy/jsdoccomment");
15
15
  var _commentParser = require("comment-parser");
16
16
  var _jsdocUtils = _interopRequireDefault(require("./jsdocUtils"));
17
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ /**
19
+ * @typedef {number} Integer
20
+ */
21
+
22
+ /**
23
+ * @typedef {{
24
+ * disallowName?: string,
25
+ * allowName?: string,
26
+ * context?: string,
27
+ * comment?: string,
28
+ * tags?: string[],
29
+ * replacement?: string,
30
+ * minimum?: Integer,
31
+ * message?: string
32
+ * }} ContextObject
33
+ */
34
+ /**
35
+ * @typedef {string|ContextObject} Context
36
+ */
37
+
38
+ /**
39
+ * @callback CheckJsdoc
40
+ * @param {{
41
+ * lastIndex?: Integer,
42
+ * isFunctionContext?: boolean,
43
+ * selector?: string
44
+ * }} info
45
+ * @param {null|((jsdoc: import('comment-parser').Block) => boolean|undefined)} handler
46
+ * @param {import('eslint').Rule.Node} node
47
+ * @returns {void}
48
+ */
49
+
50
+ /**
51
+ * @callback ForEachPreferredTag
52
+ * @param {string} tagName
53
+ * @param {(
54
+ * matchingJsdocTag: import('comment-parser').Spec & {
55
+ * line: Integer
56
+ * },
57
+ * targetTagName: string
58
+ * ) => void} arrayHandler
59
+ * @param {boolean} [skipReportingBlockedTag]
60
+ * @returns {void}
61
+ */
62
+
63
+ /**
64
+ * @callback ReportSettings
65
+ * @param {string} message
66
+ * @returns {void}
67
+ */
68
+
69
+ /**
70
+ * @callback ParseClosureTemplateTag
71
+ * @param {import('comment-parser').Spec} tag
72
+ * @returns {string[]}
73
+ */
74
+
75
+ /**
76
+ * @callback GetPreferredTagNameObject
77
+ * @param {{
78
+ * tagName: string
79
+ * }} cfg
80
+ * @returns {string|false|{
81
+ * message: string;
82
+ * replacement?: string|undefined
83
+ * }|{
84
+ * blocked: true,
85
+ * tagName: string
86
+ * }}
87
+ */
88
+
89
+ /**
90
+ * @typedef {{
91
+ * forEachPreferredTag: ForEachPreferredTag,
92
+ * reportSettings: ReportSettings,
93
+ * parseClosureTemplateTag: ParseClosureTemplateTag,
94
+ * getPreferredTagNameObject: GetPreferredTagNameObject,
95
+ * pathDoesNotBeginWith: import('./jsdocUtils.js').PathDoesNotBeginWith
96
+ * }} BasicUtils
97
+ */
98
+
99
+ /**
100
+ * @callback IsIteratingFunction
101
+ * @returns {boolean}
102
+ */
103
+
104
+ /**
105
+ * @callback IsVirtualFunction
106
+ * @returns {boolean}
107
+ */
108
+
109
+ /**
110
+ * @callback Stringify
111
+ * @param {import('comment-parser').Block} tagBlock
112
+ * @param {boolean} [specRewire]
113
+ * @returns {string}
114
+ */
115
+
116
+ /* eslint-disable jsdoc/valid-types -- Old version */
117
+ /**
118
+ * @callback ReportJSDoc
119
+ * @param {string} msg
120
+ * @param {null|import('comment-parser').Spec|{line: Integer, column?: Integer}} [tag]
121
+ * @param {(() => void)|null} [handler]
122
+ * @param {boolean} [specRewire]
123
+ * @param {undefined|{
124
+ * [key: string]: string
125
+ * }} [data]
126
+ */
127
+ /* eslint-enable jsdoc/valid-types -- Old version */
128
+
129
+ /**
130
+ * @callback GetRegexFromString
131
+ * @param {string} str
132
+ * @param {string} [requiredFlags]
133
+ * @returns {RegExp}
134
+ */
135
+
136
+ /**
137
+ * @callback GetTagDescription
138
+ * @param {import('comment-parser').Spec} tg
139
+ * @param {boolean} [returnArray]
140
+ * @returns {string[]|string}
141
+ */
142
+
143
+ /**
144
+ * @callback SetTagDescription
145
+ * @param {import('comment-parser').Spec} tg
146
+ * @param {RegExp} matcher
147
+ * @param {(description: string) => string} setter
148
+ * @returns {Integer}
149
+ */
150
+
151
+ /**
152
+ * @callback GetDescription
153
+ * @returns {{
154
+ * description: string,
155
+ * descriptions: string[],
156
+ * lastDescriptionLine: Integer
157
+ * }}
158
+ */
159
+
160
+ /* eslint-disable jsdoc/no-undefined-types -- Bug */
161
+ /**
162
+ * @callback SetBlockDescription
163
+ * @param {(
164
+ * info: {
165
+ * delimiter: string,
166
+ * postDelimiter: string,
167
+ * start: string
168
+ * },
169
+ * seedTokens: (
170
+ * tokens?: Partial<import('comment-parser').Tokens>
171
+ * ) => import('comment-parser').Tokens,
172
+ * descLines: string[]
173
+ * ) => import('comment-parser').Line[]} setter
174
+ * @returns {void}
175
+ */
176
+ /* eslint-enable jsdoc/no-undefined-types -- Bug */
177
+
178
+ /**
179
+ * @callback SetDescriptionLines
180
+ * @param {RegExp} matcher
181
+ * @param {(description: string) => string} setter
182
+ * @returns {Integer}
183
+ */
184
+
185
+ /* eslint-disable jsdoc/no-undefined-types -- TS */
186
+ /**
187
+ * @callback ChangeTag
188
+ * @param {import('comment-parser').Spec} tag
189
+ * @param {...Partial<import('comment-parser').Tokens>} tokens
190
+ * @returns {void}
191
+ */
192
+ /* eslint-enable jsdoc/no-undefined-types -- TS */
193
+
194
+ /* eslint-disable jsdoc/no-undefined-types -- TS */
195
+ /**
196
+ * @callback SetTag
197
+ * @param {import('comment-parser').Spec & {
198
+ * line: Integer
199
+ * }} tag
200
+ * @param {Partial<import('comment-parser').Tokens>} [tokens]
201
+ * @returns {void}
202
+ */
203
+ /* eslint-enable jsdoc/no-undefined-types -- TS */
204
+
205
+ /**
206
+ * @callback RemoveTag
207
+ * @param {Integer} tagIndex
208
+ * @param {{
209
+ * removeEmptyBlock?: boolean,
210
+ * tagSourceOffset?: Integer
211
+ * }} [cfg]
212
+ * @returns {void}
213
+ */
214
+
215
+ /**
216
+ * @callback AddTag
217
+ * @param {string} targetTagName
218
+ * @param {Integer} [number]
219
+ * @param {import('comment-parser').Tokens|{}} [tokens]
220
+ * @returns {void}
221
+ */
222
+
223
+ /**
224
+ * @callback GetFirstLine
225
+ * @returns {Integer|undefined}
226
+ */
227
+
228
+ /* eslint-disable jsdoc/no-undefined-types -- TS */
229
+ /**
230
+ * @typedef {(
231
+ * tokens?: Partial<import('comment-parser').Tokens> | undefined
232
+ * ) => import('comment-parser').Tokens} SeedTokens
233
+ */
234
+ /* eslint-enable jsdoc/no-undefined-types -- TS */
235
+
236
+ /**
237
+ * Sets tokens to empty string.
238
+ *
239
+ * @callback EmptyTokens
240
+ * @param {import('comment-parser').Tokens} tokens
241
+ * @returns {void}
242
+ */
243
+
244
+ /* eslint-disable jsdoc/no-undefined-types -- TS */
245
+ /**
246
+ * @callback AddLine
247
+ * @param {Integer} sourceIndex
248
+ * @param {Partial<import('comment-parser').Tokens>} tokens
249
+ * @returns {void}
250
+ */
251
+ /* eslint-enable jsdoc/no-undefined-types -- TS */
252
+
253
+ /**
254
+ * @callback AddLines
255
+ * @param {Integer} tagIndex
256
+ * @param {Integer} tagSourceOffset
257
+ * @param {Integer} numLines
258
+ * @returns {void}
259
+ */
260
+
261
+ /**
262
+ * @callback MakeMultiline
263
+ * @returns {void}
264
+ */
265
+
266
+ /**
267
+ * @callback GetFunctionParameterNames
268
+ * @param {boolean} [useDefaultObjectProperties]
269
+ * @returns {import('./jsdocUtils.js').ParamNameInfo[]}
270
+ */
271
+
272
+ /**
273
+ * @callback HasParams
274
+ * @returns {Integer}
275
+ */
276
+
277
+ /**
278
+ * @callback IsGenerator
279
+ * @returns {boolean}
280
+ */
281
+
282
+ /**
283
+ * @callback IsConstructor
284
+ * @returns {boolean}
285
+ */
286
+
287
+ /**
288
+ * @callback GetJsdocTagsDeep
289
+ * @param {string} tagName
290
+ * @returns {false|{
291
+ * idx: Integer,
292
+ * name: string,
293
+ * type: string
294
+ * }[]}
295
+ */
296
+
297
+ /**
298
+ * @callback GetPreferredTagName
299
+ * @param {{
300
+ * tagName: string,
301
+ * skipReportingBlockedTag?: boolean,
302
+ * allowObjectReturn?: boolean,
303
+ * defaultMessage?: string
304
+ * }} cfg
305
+ * @returns {string|undefined|false|{
306
+ * message: string;
307
+ * replacement?: string|undefined;
308
+ * }|{
309
+ * blocked: true,
310
+ * tagName: string
311
+ * }}
312
+ */
313
+
314
+ /**
315
+ * @callback IsValidTag
316
+ * @param {string} name
317
+ * @param {string[]} definedTags
318
+ * @returns {boolean}
319
+ */
320
+
321
+ /**
322
+ * @callback HasATag
323
+ * @param {string[]} names
324
+ * @returns {boolean}
325
+ */
326
+
327
+ /**
328
+ * @callback HasTag
329
+ * @param {string} name
330
+ * @returns {boolean}
331
+ */
332
+
333
+ /**
334
+ * @callback ComparePaths
335
+ * @param {string} name
336
+ * @returns {(otherPathName: string) => void}
337
+ */
338
+
339
+ /**
340
+ * @callback DropPathSegmentQuotes
341
+ * @param {string} name
342
+ * @returns {string}
343
+ */
344
+
345
+ /**
346
+ * @callback AvoidDocs
347
+ * @returns {boolean}
348
+ */
349
+
350
+ /**
351
+ * @callback TagMightHaveNamePositionTypePosition
352
+ * @param {string} tagName
353
+ * @param {import('./getDefaultTagStructureForMode.js').
354
+ * TagStructure[]} [otherModeMaps]
355
+ * @returns {boolean|{otherMode: true}}
356
+ */
357
+
358
+ /**
359
+ * @callback TagMustHave
360
+ * @param {string} tagName
361
+ * @param {import('./getDefaultTagStructureForMode.js').
362
+ * TagStructure[]} otherModeMaps
363
+ * @returns {boolean|{
364
+ * otherMode: false
365
+ * }}
366
+ */
367
+
368
+ /**
369
+ * @callback TagMissingRequiredTypeOrNamepath
370
+ * @param {import('comment-parser').Spec} tag
371
+ * @param {import('./getDefaultTagStructureForMode.js').
372
+ * TagStructure[]} otherModeMaps
373
+ * @returns {boolean|{
374
+ * otherMode: false
375
+ * }}
376
+ */
377
+
378
+ /**
379
+ * @callback IsNamepathX
380
+ * @param {string} tagName
381
+ * @returns {boolean}
382
+ */
383
+
384
+ /**
385
+ * @callback GetTagStructureForMode
386
+ * @param {import('./jsdocUtils.js').ParserMode} mde
387
+ * @returns {import('./getDefaultTagStructureForMode.js').TagStructure}
388
+ */
389
+
390
+ /**
391
+ * @callback MayBeUndefinedTypeTag
392
+ * @param {import('comment-parser').Spec} tag
393
+ * @returns {boolean}
394
+ */
395
+
396
+ /**
397
+ * @callback HasValueOrExecutorHasNonEmptyResolveValue
398
+ * @param {boolean} anyPromiseAsReturn
399
+ * @param {boolean} [allBranches]
400
+ * @returns {boolean}
401
+ */
402
+
403
+ /**
404
+ * @callback HasYieldValue
405
+ * @returns {boolean}
406
+ */
407
+
408
+ /**
409
+ * @callback HasYieldReturnValue
410
+ * @returns {boolean}
411
+ */
412
+
413
+ /**
414
+ * @callback HasThrowValue
415
+ * @returns {boolean}
416
+ */
417
+
418
+ /**
419
+ * @callback IsAsync
420
+ * @returns {boolean|undefined}
421
+ */
422
+
423
+ /**
424
+ * @callback GetTags
425
+ * @param {string} tagName
426
+ * @returns {import('comment-parser').Spec[]}
427
+ */
428
+
429
+ /**
430
+ * @callback GetPresentTags
431
+ * @param {string[]} tagList
432
+ * @returns {import('comment-parser').Spec[]}
433
+ */
434
+
435
+ /**
436
+ * @callback FilterTags
437
+ * @param {(tag: import('comment-parser').Spec) => boolean} filter
438
+ * @returns {import('comment-parser').Spec[]}
439
+ */
440
+
441
+ /**
442
+ * @callback FilterAllTags
443
+ * @param {(tag: (import('comment-parser').Spec|
444
+ * import('@es-joy/jsdoccomment').JsdocInlineTagNoType)) => boolean} filter
445
+ * @returns {(import('comment-parser').Spec|
446
+ * import('@es-joy/jsdoccomment').JsdocInlineTagNoType)[]}
447
+ */
448
+
449
+ /**
450
+ * @callback GetTagsByType
451
+ * @param {import('comment-parser').Spec[]} tags
452
+ * @returns {{
453
+ * tagsWithNames: import('comment-parser').Spec[],
454
+ * tagsWithoutNames: import('comment-parser').Spec[]
455
+ * }}
456
+ */
457
+
458
+ /**
459
+ * @callback HasOptionTag
460
+ * @param {string} tagName
461
+ * @returns {boolean}
462
+ */
463
+
464
+ /**
465
+ * @callback GetClassNode
466
+ * @returns {Node|null}
467
+ */
468
+
469
+ /**
470
+ * @callback GetClassJsdoc
471
+ * @returns {null|import('comment-parser').Block & {
472
+ * inlineTags: import('@es-joy/jsdoccomment').InlineTag[]
473
+ * }}
474
+ */
475
+
476
+ /**
477
+ * @callback ClassHasTag
478
+ * @param {string} tagName
479
+ * @returns {boolean}
480
+ */
481
+ /**
482
+ * @typedef {BasicUtils & {
483
+ * isIteratingFunction: IsIteratingFunction,
484
+ * isVirtualFunction: IsVirtualFunction,
485
+ * stringify: Stringify,
486
+ * reportJSDoc: ReportJSDoc,
487
+ * getRegexFromString: GetRegexFromString,
488
+ * getTagDescription: GetTagDescription,
489
+ * setTagDescription: SetTagDescription,
490
+ * getDescription: GetDescription,
491
+ * setBlockDescription: SetBlockDescription,
492
+ * setDescriptionLines: SetDescriptionLines,
493
+ * changeTag: ChangeTag,
494
+ * setTag: SetTag,
495
+ * removeTag: RemoveTag,
496
+ * addTag: AddTag,
497
+ * getFirstLine: GetFirstLine,
498
+ * seedTokens: SeedTokens,
499
+ * emptyTokens: EmptyTokens,
500
+ * addLine: AddLine,
501
+ * addLines: AddLines,
502
+ * makeMultiline: MakeMultiline,
503
+ * flattenRoots: import('./jsdocUtils.js').FlattenRoots,
504
+ * getFunctionParameterNames: GetFunctionParameterNames,
505
+ * hasParams: HasParams,
506
+ * isGenerator: IsGenerator,
507
+ * isConstructor: IsConstructor,
508
+ * getJsdocTagsDeep: GetJsdocTagsDeep,
509
+ * getPreferredTagName: GetPreferredTagName,
510
+ * isValidTag: IsValidTag,
511
+ * hasATag: HasATag,
512
+ * hasTag: HasTag,
513
+ * comparePaths: ComparePaths,
514
+ * dropPathSegmentQuotes: DropPathSegmentQuotes,
515
+ * avoidDocs: AvoidDocs,
516
+ * tagMightHaveNamePosition: TagMightHaveNamePositionTypePosition,
517
+ * tagMightHaveTypePosition: TagMightHaveNamePositionTypePosition,
518
+ * tagMustHaveNamePosition: TagMustHave,
519
+ * tagMustHaveTypePosition: TagMustHave,
520
+ * tagMissingRequiredTypeOrNamepath: TagMissingRequiredTypeOrNamepath,
521
+ * isNamepathDefiningTag: IsNamepathX,
522
+ * isNamepathReferencingTag: IsNamepathX,
523
+ * isNamepathOrUrlReferencingTag: IsNamepathX,
524
+ * tagMightHaveNamepath: IsNamepathX,
525
+ * getTagStructureForMode: GetTagStructureForMode,
526
+ * mayBeUndefinedTypeTag: MayBeUndefinedTypeTag,
527
+ * hasValueOrExecutorHasNonEmptyResolveValue: HasValueOrExecutorHasNonEmptyResolveValue,
528
+ * hasYieldValue: HasYieldValue,
529
+ * hasYieldReturnValue: HasYieldReturnValue,
530
+ * hasThrowValue: HasThrowValue,
531
+ * isAsync: IsAsync,
532
+ * getTags: GetTags,
533
+ * getPresentTags: GetPresentTags,
534
+ * filterTags: FilterTags,
535
+ * filterAllTags: FilterAllTags,
536
+ * getTagsByType: GetTagsByType,
537
+ * hasOptionTag: HasOptionTag,
538
+ * getClassNode: GetClassNode,
539
+ * getClassJsdoc: GetClassJsdoc,
540
+ * classHasTag: ClassHasTag
541
+ * }} Utils
542
+ */
18
543
  const {
19
544
  rewireSpecs,
20
545
  seedTokens
@@ -25,19 +550,38 @@ const {
25
550
  /**
26
551
  * Should use ESLint rule's typing.
27
552
  *
28
- * @typedef {any} EslintRuleMeta
553
+ * @typedef {import('eslint').Rule.RuleMetaData} EslintRuleMeta
29
554
  */
30
555
 
556
+ /* eslint-disable jsdoc/valid-types -- Old version */
31
557
  /**
32
558
  * A plain object for tracking state as needed by rules across iterations.
33
559
  *
34
- * @typedef {any} StateObject
560
+ * @typedef {{
561
+ * globalTags: {},
562
+ * hasDuplicates: {
563
+ * [key: string]: boolean
564
+ * },
565
+ * selectorMap: {
566
+ * [selector: string]: {
567
+ * [comment: string]: Integer
568
+ * }
569
+ * },
570
+ * hasTag: {
571
+ * [key: string]: boolean
572
+ * },
573
+ * hasNonComment: number,
574
+ * hasNonCommentBeforeTag: {
575
+ * [key: string]: boolean|number
576
+ * }
577
+ * }} StateObject
35
578
  */
579
+ /* eslint-enable jsdoc/valid-types -- Old version */
36
580
 
37
581
  /**
38
582
  * The Node AST as supplied by the parser.
39
583
  *
40
- * @typedef {any} Node
584
+ * @typedef {import('eslint').Rule.Node} Node
41
585
  */
42
586
 
43
587
  /*
@@ -49,14 +593,29 @@ const {
49
593
  */
50
594
 
51
595
  const globalState = new Map();
596
+ /**
597
+ * @param {import('eslint').Rule.RuleContext} context
598
+ * @param {{
599
+ * tagNamePreference?: import('./jsdocUtils.js').TagNamePreference,
600
+ * mode?: import('./jsdocUtils.js').ParserMode
601
+ * }} cfg
602
+ * @returns {BasicUtils}
603
+ */
52
604
  const getBasicUtils = (context, {
53
605
  tagNamePreference,
54
606
  mode
55
607
  }) => {
608
+ /** @type {BasicUtils} */
56
609
  const utils = {};
610
+
611
+ /** @type {ReportSettings} */
57
612
  utils.reportSettings = message => {
58
613
  context.report({
59
614
  loc: {
615
+ end: {
616
+ column: 1,
617
+ line: 1
618
+ },
60
619
  start: {
61
620
  column: 1,
62
621
  line: 1
@@ -65,14 +624,18 @@ const getBasicUtils = (context, {
65
624
  message
66
625
  });
67
626
  };
627
+
628
+ /** @type {ParseClosureTemplateTag} */
68
629
  utils.parseClosureTemplateTag = tag => {
69
630
  return _jsdocUtils.default.parseClosureTemplateTag(tag);
70
631
  };
71
632
  utils.pathDoesNotBeginWith = _jsdocUtils.default.pathDoesNotBeginWith;
633
+
634
+ /** @type {GetPreferredTagNameObject} */
72
635
  utils.getPreferredTagNameObject = ({
73
636
  tagName
74
637
  }) => {
75
- const ret = _jsdocUtils.default.getPreferredTagName(context, mode, tagName, tagNamePreference);
638
+ const ret = _jsdocUtils.default.getPreferredTagName(context, /** @type {import('./jsdocUtils.js').ParserMode} */mode, tagName, tagNamePreference);
76
639
  const isObject = ret && typeof ret === 'object';
77
640
  if (ret === false || isObject && !ret.replacement) {
78
641
  return {
@@ -84,10 +647,41 @@ const getBasicUtils = (context, {
84
647
  };
85
648
  return utils;
86
649
  };
650
+
651
+ /* eslint-disable jsdoc/valid-types -- Old version of pratt */
652
+ /**
653
+ * @callback Report
654
+ * @param {string} message
655
+ * @param {import('eslint').Rule.ReportFixer|null} [fix]
656
+ * @param {null|
657
+ * {line?: Integer, column?: Integer}|
658
+ * import('comment-parser').Spec & {line?: Integer}
659
+ * } [jsdocLoc]
660
+ * @param {undefined|{
661
+ * [key: string]: string
662
+ * }} [data]
663
+ * @returns {void}
664
+ */
665
+ /* eslint-enable jsdoc/valid-types -- Old version of pratt */
666
+
667
+ /**
668
+ * @param {Node|null} node
669
+ * @param {import('comment-parser').Block & {
670
+ * inlineTags: import('@es-joy/jsdoccomment').InlineTag[]
671
+ * }} jsdoc
672
+ * @param {import('eslint').AST.Token} jsdocNode
673
+ * @param {Settings} settings
674
+ * @param {Report} report
675
+ * @param {import('eslint').Rule.RuleContext} context
676
+ * @param {boolean|undefined} iteratingAll
677
+ * @param {RuleConfig} ruleConfig
678
+ * @param {string} indent
679
+ * @returns {Utils}
680
+ */
87
681
  const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAll, ruleConfig, indent) => {
88
- const ancestors = context.getAncestors();
682
+ const ancestors = /** @type {import('eslint').Rule.Node[]} */context.getAncestors();
89
683
  const sourceCode = context.getSourceCode();
90
- const utils = getBasicUtils(context, settings);
684
+ const utils = /** @type {Utils} */getBasicUtils(context, settings);
91
685
  const {
92
686
  tagNamePreference,
93
687
  overrideReplacesDocs,
@@ -98,21 +692,30 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
98
692
  minLines,
99
693
  mode
100
694
  } = settings;
695
+
696
+ /** @type {IsIteratingFunction} */
101
697
  utils.isIteratingFunction = () => {
102
- return !iteratingAll || ['MethodDefinition', 'ArrowFunctionExpression', 'FunctionDeclaration', 'FunctionExpression'].includes(node && node.type);
698
+ return !iteratingAll || ['MethodDefinition', 'ArrowFunctionExpression', 'FunctionDeclaration', 'FunctionExpression'].includes(String(node && node.type));
103
699
  };
700
+
701
+ /** @type {IsVirtualFunction} */
104
702
  utils.isVirtualFunction = () => {
105
- return iteratingAll && utils.hasATag(['callback', 'function', 'func', 'method']);
703
+ return Boolean(iteratingAll) && utils.hasATag(['callback', 'function', 'func', 'method']);
106
704
  };
705
+
706
+ /** @type {Stringify} */
107
707
  utils.stringify = (tagBlock, specRewire) => {
108
708
  let block;
109
709
  if (specRewire) {
110
710
  block = rewireSpecs(tagBlock);
111
711
  }
112
- return (0, _commentParser.stringify)(specRewire ? block : tagBlock);
712
+ return (0, _commentParser.stringify)( /** @type {import('comment-parser').Block} */
713
+ specRewire ? block : tagBlock);
113
714
  };
715
+
716
+ /** @type {ReportJSDoc} */
114
717
  utils.reportJSDoc = (msg, tag, handler, specRewire, data) => {
115
- report(msg, handler ? fixer => {
718
+ report(msg, handler ? /** @type {import('eslint').Rule.ReportFixer} */fixer => {
116
719
  handler();
117
720
  const replacement = utils.stringify(jsdoc, specRewire);
118
721
  if (!replacement) {
@@ -126,10 +729,17 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
126
729
  return fixer.replaceText(jsdocNode, replacement);
127
730
  } : null, tag, data);
128
731
  };
732
+
733
+ /** @type {GetRegexFromString} */
129
734
  utils.getRegexFromString = (str, requiredFlags) => {
130
735
  return _jsdocUtils.default.getRegexFromString(str, requiredFlags);
131
736
  };
737
+
738
+ /** @type {GetTagDescription} */
132
739
  utils.getTagDescription = (tg, returnArray) => {
740
+ /**
741
+ * @type {string[]}
742
+ */
133
743
  const descriptions = [];
134
744
  tg.source.some(({
135
745
  tokens: {
@@ -158,6 +768,8 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
158
768
  });
159
769
  return returnArray ? descriptions : descriptions.join('\n');
160
770
  };
771
+
772
+ /** @type {SetTagDescription} */
161
773
  utils.setTagDescription = (tg, matcher, setter) => {
162
774
  let finalIdx = 0;
163
775
  tg.source.some(({
@@ -174,7 +786,10 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
174
786
  });
175
787
  return finalIdx;
176
788
  };
789
+
790
+ /** @type {GetDescription} */
177
791
  utils.getDescription = () => {
792
+ /** @type {string[]} */
178
793
  const descriptions = [];
179
794
  let lastDescriptionLine = 0;
180
795
  let tagsBegun = false;
@@ -206,10 +821,27 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
206
821
  lastDescriptionLine
207
822
  };
208
823
  };
824
+
825
+ /** @type {SetBlockDescription} */
209
826
  utils.setBlockDescription = setter => {
827
+ /** @type {string[]} */
210
828
  const descLines = [];
829
+ /**
830
+ * @type {undefined|Integer}
831
+ */
211
832
  let startIdx;
833
+ /**
834
+ * @type {undefined|Integer}
835
+ */
212
836
  let endIdx;
837
+
838
+ /**
839
+ * @type {undefined|{
840
+ * delimiter: string,
841
+ * postDelimiter: string,
842
+ * start: string
843
+ * }}
844
+ */
213
845
  let info;
214
846
  jsdoc.source.some(({
215
847
  tokens: {
@@ -242,9 +874,19 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
242
874
 
243
875
  /* istanbul ignore else -- Won't be called if missing */
244
876
  if (descLines.length) {
245
- jsdoc.source.splice(startIdx, endIdx - startIdx, ...setter(info, seedTokens, descLines));
877
+ jsdoc.source.splice( /** @type {Integer} */startIdx, /** @type {Integer} */endIdx - /** @type {Integer} */startIdx, ...setter(
878
+ /**
879
+ * @type {{
880
+ * delimiter: string,
881
+ * postDelimiter: string,
882
+ * start: string
883
+ * }}
884
+ */
885
+ info, seedTokens, descLines));
246
886
  }
247
887
  };
888
+
889
+ /** @type {SetDescriptionLines} */
248
890
  utils.setDescriptionLines = (matcher, setter) => {
249
891
  let finalIdx = 0;
250
892
  jsdoc.source.some(({
@@ -267,6 +909,8 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
267
909
  });
268
910
  return finalIdx;
269
911
  };
912
+
913
+ /** @type {ChangeTag} */
270
914
  utils.changeTag = (tag, ...tokens) => {
271
915
  for (const [idx, src] of tag.source.entries()) {
272
916
  src.tokens = {
@@ -275,10 +919,13 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
275
919
  };
276
920
  }
277
921
  };
922
+
923
+ /** @type {SetTag} */
278
924
  utils.setTag = (tag, tokens) => {
279
925
  tag.source = [{
280
- // Or tag.source[0].number?
281
926
  number: tag.line,
927
+ // Or tag.source[0].number?
928
+ source: '',
282
929
  tokens: seedTokens({
283
930
  delimiter: '*',
284
931
  postDelimiter: ' ',
@@ -288,6 +935,8 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
288
935
  })
289
936
  }];
290
937
  };
938
+
939
+ /** @type {RemoveTag} */
291
940
  utils.removeTag = (tagIndex, {
292
941
  removeEmptyBlock = false,
293
942
  tagSourceOffset = 0
@@ -295,6 +944,7 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
295
944
  const {
296
945
  source: tagSource
297
946
  } = jsdoc.tags[tagIndex];
947
+ /** @type {Integer|undefined} */
298
948
  let lastIndex;
299
949
  const firstNumber = jsdoc.source[0].number;
300
950
  tagSource.some(({
@@ -332,7 +982,12 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
332
982
  tokens
333
983
  } = jsdoc.source[spliceIdx];
334
984
  for (const item of ['postDelimiter', 'tag', 'postTag', 'type', 'postType', 'name', 'postName', 'description']) {
335
- tokens[item] = '';
985
+ tokens[
986
+ /**
987
+ * @type {"postDelimiter"|"tag"|"type"|"postType"|
988
+ * "postTag"|"name"|"postName"|"description"}
989
+ */
990
+ item] = '';
336
991
  }
337
992
  } else {
338
993
  jsdoc.source.splice(spliceIdx, spliceCount - tagSourceOffset + (spliceIdx ? 0 : jsdoc.source.length));
@@ -346,14 +1001,16 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
346
1001
  return false;
347
1002
  });
348
1003
  for (const [idx, src] of jsdoc.source.slice(lastIndex).entries()) {
349
- src.number = firstNumber + lastIndex + idx;
1004
+ src.number = firstNumber + /** @type {Integer} */lastIndex + idx;
350
1005
  }
351
1006
 
352
- // Todo: Once rewiring of tags may be fixed in comment-parser to reflect missing tags,
353
- // this step should be added here (so that, e.g., if accessing `jsdoc.tags`,
354
- // such as to add a new tag, the correct information will be available)
1007
+ // Todo: Once rewiring of tags may be fixed in comment-parser to reflect
1008
+ // missing tags, this step should be added here (so that, e.g.,
1009
+ // if accessing `jsdoc.tags`, such as to add a new tag, the
1010
+ // correct information will be available)
355
1011
  };
356
1012
 
1013
+ /** @type {AddTag} */
357
1014
  utils.addTag = (targetTagName, number = ((() => {
358
1015
  var _jsdoc$tags, _jsdoc$tags$source$;
359
1016
  return (_jsdoc$tags = jsdoc.tags[jsdoc.tags.length - 1]) === null || _jsdoc$tags === void 0 ? void 0 : (_jsdoc$tags$source$ = _jsdoc$tags.source[0]) === null || _jsdoc$tags$source$ === void 0 ? void 0 : _jsdoc$tags$source$.number;
@@ -379,6 +1036,8 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
379
1036
  src.number++;
380
1037
  }
381
1038
  };
1039
+
1040
+ /** @type {GetFirstLine} */
382
1041
  utils.getFirstLine = () => {
383
1042
  let firstLine;
384
1043
  for (const {
@@ -394,12 +1053,23 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
394
1053
  }
395
1054
  return firstLine;
396
1055
  };
1056
+
1057
+ /** @type {SeedTokens} */
397
1058
  utils.seedTokens = seedTokens;
1059
+
1060
+ /** @type {EmptyTokens} */
398
1061
  utils.emptyTokens = tokens => {
399
1062
  for (const prop of ['start', 'postDelimiter', 'tag', 'type', 'postType', 'postTag', 'name', 'postName', 'description', 'end', 'lineEnd']) {
400
- tokens[prop] = '';
1063
+ tokens[
1064
+ /**
1065
+ * @type {"start"|"postDelimiter"|"tag"|"type"|"postType"|
1066
+ * "postTag"|"name"|"postName"|"description"|"end"|"lineEnd"}
1067
+ */
1068
+ prop] = '';
401
1069
  }
402
1070
  };
1071
+
1072
+ /** @type {AddLine} */
403
1073
  utils.addLine = (sourceIndex, tokens) => {
404
1074
  var _jsdoc$source;
405
1075
  const number = (((_jsdoc$source = jsdoc.source[sourceIndex - 1]) === null || _jsdoc$source === void 0 ? void 0 : _jsdoc$source.number) || 0) + 1;
@@ -415,10 +1085,12 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
415
1085
  // rewireSource(jsdoc);
416
1086
  };
417
1087
 
1088
+ /** @type {AddLines} */
418
1089
  utils.addLines = (tagIndex, tagSourceOffset, numLines) => {
419
1090
  const {
420
1091
  source: tagSource
421
1092
  } = jsdoc.tags[tagIndex];
1093
+ /** @type {Integer|undefined} */
422
1094
  let lastIndex;
423
1095
  const firstNumber = jsdoc.source[0].number;
424
1096
  tagSource.some(({
@@ -461,9 +1133,11 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
461
1133
  return false;
462
1134
  });
463
1135
  for (const [idx, src] of jsdoc.source.slice(lastIndex).entries()) {
464
- src.number = firstNumber + lastIndex + idx;
1136
+ src.number = firstNumber + /** @type {Integer} */lastIndex + idx;
465
1137
  }
466
1138
  };
1139
+
1140
+ /** @type {MakeMultiline} */
467
1141
  utils.makeMultiline = () => {
468
1142
  const {
469
1143
  source: [{
@@ -517,23 +1191,45 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
517
1191
  start: indent + ' '
518
1192
  });
519
1193
  };
520
- utils.flattenRoots = params => {
521
- return _jsdocUtils.default.flattenRoots(params);
522
- };
1194
+
1195
+ /**
1196
+ * @type {import('./jsdocUtils.js').FlattenRoots}
1197
+ */
1198
+ utils.flattenRoots = _jsdocUtils.default.flattenRoots;
1199
+
1200
+ /** @type {GetFunctionParameterNames} */
523
1201
  utils.getFunctionParameterNames = useDefaultObjectProperties => {
524
1202
  return _jsdocUtils.default.getFunctionParameterNames(node, useDefaultObjectProperties);
525
1203
  };
1204
+
1205
+ /** @type {HasParams} */
526
1206
  utils.hasParams = () => {
527
- return _jsdocUtils.default.hasParams(node);
1207
+ return _jsdocUtils.default.hasParams( /** @type {Node} */node);
528
1208
  };
1209
+
1210
+ /** @type {IsGenerator} */
529
1211
  utils.isGenerator = () => {
530
- return node && (node.generator || node.type === 'MethodDefinition' && node.value.generator || ['ExportNamedDeclaration', 'ExportDefaultDeclaration'].includes(node.type) && node.declaration.generator);
1212
+ return node !== null && Boolean(
1213
+ /**
1214
+ * @type {import('estree').FunctionDeclaration|
1215
+ * import('estree').FunctionExpression}
1216
+ */
1217
+ node.generator || node.type === 'MethodDefinition' && node.value.generator || ['ExportNamedDeclaration', 'ExportDefaultDeclaration'].includes(node.type) && /** @type {import('estree').FunctionDeclaration} */
1218
+ /**
1219
+ * @type {import('estree').ExportNamedDeclaration|
1220
+ * import('estree').ExportDefaultDeclaration}
1221
+ */
1222
+ node.declaration.generator);
531
1223
  };
1224
+
1225
+ /** @type {IsConstructor} */
532
1226
  utils.isConstructor = () => {
533
- return _jsdocUtils.default.isConstructor(node);
1227
+ return _jsdocUtils.default.isConstructor( /** @type {Node} */node);
534
1228
  };
1229
+
1230
+ /** @type {GetJsdocTagsDeep} */
535
1231
  utils.getJsdocTagsDeep = tagName => {
536
- const name = utils.getPreferredTagName({
1232
+ const name = /** @type {string|false} */utils.getPreferredTagName({
537
1233
  tagName
538
1234
  });
539
1235
  if (!name) {
@@ -541,6 +1237,8 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
541
1237
  }
542
1238
  return _jsdocUtils.default.getJsdocTagsDeep(jsdoc, name);
543
1239
  };
1240
+
1241
+ /** @type {GetPreferredTagName} */
544
1242
  utils.getPreferredTagName = ({
545
1243
  tagName,
546
1244
  skipReportingBlockedTag = false,
@@ -562,27 +1260,40 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
562
1260
  }
563
1261
  return isObject && !allowObjectReturn ? ret.replacement : ret;
564
1262
  };
1263
+
1264
+ /** @type {IsValidTag} */
565
1265
  utils.isValidTag = (name, definedTags) => {
566
1266
  return _jsdocUtils.default.isValidTag(context, mode, name, definedTags);
567
1267
  };
1268
+
1269
+ /** @type {HasATag} */
568
1270
  utils.hasATag = names => {
569
1271
  return _jsdocUtils.default.hasATag(jsdoc, names);
570
1272
  };
1273
+
1274
+ /** @type {HasTag} */
571
1275
  utils.hasTag = name => {
572
1276
  return _jsdocUtils.default.hasTag(jsdoc, name);
573
1277
  };
1278
+
1279
+ /** @type {ComparePaths} */
574
1280
  utils.comparePaths = name => {
575
1281
  return _jsdocUtils.default.comparePaths(name);
576
1282
  };
1283
+
1284
+ /** @type {DropPathSegmentQuotes} */
577
1285
  utils.dropPathSegmentQuotes = name => {
578
1286
  return _jsdocUtils.default.dropPathSegmentQuotes(name);
579
1287
  };
1288
+
1289
+ /** @type {AvoidDocs} */
580
1290
  utils.avoidDocs = () => {
581
1291
  var _context$options$;
582
1292
  if (ignoreReplacesDocs !== false && (utils.hasTag('ignore') || utils.classHasTag('ignore')) || overrideReplacesDocs !== false && (utils.hasTag('override') || utils.classHasTag('override')) || implementsReplacesDocs !== false && (utils.hasTag('implements') || utils.classHasTag('implements')) || augmentsExtendsReplacesDocs && (utils.hasATag(['augments', 'extends']) || utils.classHasTag('augments') || utils.classHasTag('extends'))) {
583
1293
  return true;
584
1294
  }
585
- if (_jsdocUtils.default.exemptSpeciaMethods(jsdoc, node, context, ruleConfig.meta.schema)) {
1295
+ if (_jsdocUtils.default.exemptSpeciaMethods(jsdoc, node, context, /** @type {import('json-schema').JSONSchema4|import('json-schema').JSONSchema4[]} */
1296
+ ruleConfig.meta.schema)) {
586
1297
  return true;
587
1298
  }
588
1299
  const exemptedBy = ((_context$options$ = context.options[0]) === null || _context$options$ === void 0 ? void 0 : _context$options$.exemptedBy) ?? ['inheritDoc', ...(mode === 'closure' ? [] : ['inheritdoc'])];
@@ -592,8 +1303,11 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
592
1303
  return false;
593
1304
  };
594
1305
  for (const method of ['tagMightHaveNamePosition', 'tagMightHaveTypePosition']) {
595
- utils[method] = (tagName, otherModeMaps) => {
596
- const result = _jsdocUtils.default[method](tagName);
1306
+ /** @type {TagMightHaveNamePositionTypePosition} */
1307
+ utils[/** @type {"tagMightHaveNamePosition"|"tagMightHaveTypePosition"} */
1308
+ method] = (tagName, otherModeMaps) => {
1309
+ const result = _jsdocUtils.default[/** @type {"tagMightHaveNamePosition"|"tagMightHaveTypePosition"} */
1310
+ method](tagName);
597
1311
  if (result) {
598
1312
  return true;
599
1313
  }
@@ -601,16 +1315,34 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
601
1315
  return false;
602
1316
  }
603
1317
  const otherResult = otherModeMaps.some(otherModeMap => {
604
- return _jsdocUtils.default[method](tagName, otherModeMap);
1318
+ return _jsdocUtils.default[/** @type {"tagMightHaveNamePosition"|"tagMightHaveTypePosition"} */
1319
+ method](tagName, otherModeMap);
605
1320
  });
606
1321
  return otherResult ? {
607
1322
  otherMode: true
608
1323
  } : false;
609
1324
  };
610
1325
  }
611
- for (const method of ['tagMustHaveNamePosition', 'tagMustHaveTypePosition', 'tagMissingRequiredTypeOrNamepath']) {
612
- utils[method] = (tagName, otherModeMaps) => {
613
- const result = _jsdocUtils.default[method](tagName);
1326
+
1327
+ /** @type {TagMissingRequiredTypeOrNamepath} */
1328
+ utils.tagMissingRequiredTypeOrNamepath = (tagName, otherModeMaps) => {
1329
+ const result = _jsdocUtils.default.tagMissingRequiredTypeOrNamepath(tagName);
1330
+ if (!result) {
1331
+ return false;
1332
+ }
1333
+ const otherResult = otherModeMaps.every(otherModeMap => {
1334
+ return _jsdocUtils.default.tagMissingRequiredTypeOrNamepath(tagName, otherModeMap);
1335
+ });
1336
+ return otherResult ? true : {
1337
+ otherMode: false
1338
+ };
1339
+ };
1340
+ for (const method of ['tagMustHaveNamePosition', 'tagMustHaveTypePosition']) {
1341
+ /** @type {TagMustHave} */
1342
+ utils[/** @type {"tagMustHaveNamePosition"|"tagMustHaveTypePosition"} */
1343
+ method] = (tagName, otherModeMaps) => {
1344
+ const result = _jsdocUtils.default[/** @type {"tagMustHaveNamePosition"|"tagMustHaveTypePosition"} */
1345
+ method](tagName);
614
1346
  if (!result) {
615
1347
  return false;
616
1348
  }
@@ -618,7 +1350,8 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
618
1350
  // if (!otherModeMaps) { return true; }
619
1351
 
620
1352
  const otherResult = otherModeMaps.every(otherModeMap => {
621
- return _jsdocUtils.default[method](tagName, otherModeMap);
1353
+ return _jsdocUtils.default[/** @type {"tagMustHaveNamePosition"|"tagMustHaveTypePosition"} */
1354
+ method](tagName, otherModeMap);
622
1355
  });
623
1356
  return otherResult ? true : {
624
1357
  otherMode: false
@@ -626,62 +1359,104 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
626
1359
  };
627
1360
  }
628
1361
  for (const method of ['isNamepathDefiningTag', 'isNamepathReferencingTag', 'isNamepathOrUrlReferencingTag', 'tagMightHaveNamepath']) {
629
- utils[method] = tagName => {
630
- return _jsdocUtils.default[method](tagName);
1362
+ /** @type {IsNamepathX} */
1363
+ utils[/** @type {"isNamepathDefiningTag"|"isNamepathReferencingTag"|"isNamepathOrUrlReferencingTag"|"tagMightHaveNamepath"} */
1364
+ method] = tagName => {
1365
+ return _jsdocUtils.default[/** @type {"isNamepathDefiningTag"|"isNamepathReferencingTag"|"isNamepathOrUrlReferencingTag"|"tagMightHaveNamepath"} */
1366
+ method](tagName);
631
1367
  };
632
1368
  }
1369
+
1370
+ /** @type {GetTagStructureForMode} */
633
1371
  utils.getTagStructureForMode = mde => {
634
1372
  return _jsdocUtils.default.getTagStructureForMode(mde, settings.structuredTags);
635
1373
  };
1374
+
1375
+ /** @type {MayBeUndefinedTypeTag} */
636
1376
  utils.mayBeUndefinedTypeTag = tag => {
637
1377
  return _jsdocUtils.default.mayBeUndefinedTypeTag(tag, settings.mode);
638
1378
  };
1379
+
1380
+ /** @type {HasValueOrExecutorHasNonEmptyResolveValue} */
639
1381
  utils.hasValueOrExecutorHasNonEmptyResolveValue = (anyPromiseAsReturn, allBranches) => {
640
- return _jsdocUtils.default.hasValueOrExecutorHasNonEmptyResolveValue(node, anyPromiseAsReturn, allBranches);
1382
+ return _jsdocUtils.default.hasValueOrExecutorHasNonEmptyResolveValue( /** @type {Node} */node, anyPromiseAsReturn, allBranches);
641
1383
  };
1384
+
1385
+ /** @type {HasYieldValue} */
642
1386
  utils.hasYieldValue = () => {
643
- if (['ExportNamedDeclaration', 'ExportDefaultDeclaration'].includes(node.type)) {
644
- return _jsdocUtils.default.hasYieldValue(node.declaration);
1387
+ if (['ExportNamedDeclaration', 'ExportDefaultDeclaration'].includes( /** @type {Node} */node.type)) {
1388
+ return _jsdocUtils.default.hasYieldValue( /** @type {import('estree').Declaration|import('estree').Expression} */
1389
+ /** @type {import('estree').ExportNamedDeclaration|import('estree').ExportDefaultDeclaration} */
1390
+ node.declaration);
645
1391
  }
646
- return _jsdocUtils.default.hasYieldValue(node);
1392
+ return _jsdocUtils.default.hasYieldValue( /** @type {Node} */node);
647
1393
  };
1394
+
1395
+ /** @type {HasYieldReturnValue} */
648
1396
  utils.hasYieldReturnValue = () => {
649
- return _jsdocUtils.default.hasYieldValue(node, true);
1397
+ return _jsdocUtils.default.hasYieldValue( /** @type {Node} */node, true);
650
1398
  };
1399
+
1400
+ /** @type {HasThrowValue} */
651
1401
  utils.hasThrowValue = () => {
652
1402
  return _jsdocUtils.default.hasThrowValue(node);
653
1403
  };
1404
+
1405
+ /** @type {IsAsync} */
654
1406
  utils.isAsync = () => {
655
- return node.async;
1407
+ return 'async' in /** @type {Node} */node && node.async;
656
1408
  };
1409
+
1410
+ /** @type {GetTags} */
657
1411
  utils.getTags = tagName => {
658
1412
  return utils.filterTags(item => {
659
1413
  return item.tag === tagName;
660
1414
  });
661
1415
  };
1416
+
1417
+ /** @type {GetPresentTags} */
662
1418
  utils.getPresentTags = tagList => {
663
1419
  return utils.filterTags(tag => {
664
1420
  return tagList.includes(tag.tag);
665
1421
  });
666
1422
  };
667
- utils.filterTags = (filter, includeInlineTags = false) => {
668
- const tags = _jsdocUtils.default.getAllTags(jsdoc, includeInlineTags);
669
- return _jsdocUtils.default.filterTags(tags, filter);
1423
+
1424
+ /** @type {FilterTags} */
1425
+ utils.filterTags = filter => {
1426
+ return jsdoc.tags.filter(tag => {
1427
+ return filter(tag);
1428
+ });
670
1429
  };
1430
+
1431
+ /** @type {FilterAllTags} */
1432
+ utils.filterAllTags = filter => {
1433
+ const tags = _jsdocUtils.default.getAllTags(jsdoc);
1434
+ return tags.filter(tag => {
1435
+ return filter(tag);
1436
+ });
1437
+ };
1438
+
1439
+ /** @type {GetTagsByType} */
671
1440
  utils.getTagsByType = tags => {
672
1441
  return _jsdocUtils.default.getTagsByType(context, mode, tags, tagNamePreference);
673
1442
  };
1443
+
1444
+ /** @type {HasOptionTag} */
674
1445
  utils.hasOptionTag = tagName => {
675
1446
  const {
676
1447
  tags
677
1448
  } = context.options[0] ?? {};
678
1449
  return Boolean(tags && tags.includes(tagName));
679
1450
  };
1451
+
1452
+ /** @type {GetClassNode} */
680
1453
  utils.getClassNode = () => {
681
1454
  return [...ancestors, node].reverse().find(parent => {
682
1455
  return parent && ['ClassDeclaration', 'ClassExpression'].includes(parent.type);
683
- }) || null;
1456
+ }) ?? null;
684
1457
  };
1458
+
1459
+ /** @type {GetClassJsdoc} */
685
1460
  utils.getClassJsdoc = () => {
686
1461
  const classNode = utils.getClassNode();
687
1462
  if (!classNode) {
@@ -696,12 +1471,17 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
696
1471
  }
697
1472
  return null;
698
1473
  };
1474
+
1475
+ /** @type {ClassHasTag} */
699
1476
  utils.classHasTag = tagName => {
700
1477
  const classJsdoc = utils.getClassJsdoc();
701
- return Boolean(classJsdoc) && _jsdocUtils.default.hasTag(classJsdoc, tagName);
1478
+ return classJsdoc !== null && _jsdocUtils.default.hasTag(classJsdoc, tagName);
702
1479
  };
1480
+
1481
+ /** @type {ForEachPreferredTag} */
703
1482
  utils.forEachPreferredTag = (tagName, arrayHandler, skipReportingBlockedTag = false) => {
704
- const targetTagName = utils.getPreferredTagName({
1483
+ const targetTagName = /** @type {string|false} */
1484
+ utils.getPreferredTagName({
705
1485
  skipReportingBlockedTag,
706
1486
  tagName
707
1487
  });
@@ -714,11 +1494,57 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
714
1494
  return tag === targetTagName;
715
1495
  });
716
1496
  for (const matchingJsdocTag of matchingJsdocTags) {
717
- arrayHandler(matchingJsdocTag, targetTagName);
1497
+ arrayHandler(
1498
+ /**
1499
+ * @type {import('comment-parser').Spec & {
1500
+ * line: Integer
1501
+ * }}
1502
+ */
1503
+ matchingJsdocTag, targetTagName);
718
1504
  }
719
1505
  };
720
1506
  return utils;
721
1507
  };
1508
+
1509
+ /* eslint-disable jsdoc/valid-types -- Old version */
1510
+ /**
1511
+ * @typedef {{
1512
+ * [key: string]: false|string|{
1513
+ * message: string,
1514
+ * replacement?: false|string
1515
+ * skipRootChecking?: boolean
1516
+ * }
1517
+ * }} PreferredTypes
1518
+ */
1519
+ /**
1520
+ * @typedef {{
1521
+ * [key: string]: {
1522
+ * name?: "text"|"namepath-defining"|"namepath-referencing"|false,
1523
+ * type?: boolean|string[],
1524
+ * required?: ("name"|"type"|"typeOrNameRequired")[]
1525
+ * }
1526
+ * }} StructuredTags
1527
+ */
1528
+ /**
1529
+ * Settings from ESLint types.
1530
+ *
1531
+ * @typedef {{
1532
+ * maxLines: Integer,
1533
+ * minLines: Integer,
1534
+ * tagNamePreference: import('./jsdocUtils.js').TagNamePreference,
1535
+ * mode: import('./jsdocUtils.js').ParserMode,
1536
+ * preferredTypes: PreferredTypes,
1537
+ * structuredTags: StructuredTags,
1538
+ * [name: string]: any,
1539
+ * contexts?: Context[]
1540
+ * }} Settings
1541
+ */
1542
+ /* eslint-enable jsdoc/valid-types -- Old version */
1543
+
1544
+ /**
1545
+ * @param {import('eslint').Rule.RuleContext} context
1546
+ * @returns {Settings|false}
1547
+ */
722
1548
  const getSettings = context => {
723
1549
  var _context$settings$jsd, _context$settings$jsd2, _context$settings$jsd3, _context$settings$jsd4, _context$settings$jsd5, _context$settings$jsd6, _context$settings$jsd7, _context$settings$jsd8, _context$settings$jsd9, _context$settings$jsd10, _context$settings$jsd11, _context$settings$jsd12, _context$settings$jsd13, _context$settings$jsd14;
724
1550
  /* eslint-disable canonical/sort-keys */
@@ -755,12 +1581,16 @@ const getSettings = context => {
755
1581
  } catch (error) {
756
1582
  context.report({
757
1583
  loc: {
1584
+ end: {
1585
+ column: 1,
1586
+ line: 1
1587
+ },
758
1588
  start: {
759
1589
  column: 1,
760
1590
  line: 1
761
1591
  }
762
1592
  },
763
- message: error.message
1593
+ message: /** @type {Error} */error.message
764
1594
  });
765
1595
  return false;
766
1596
  }
@@ -770,18 +1600,24 @@ const getSettings = context => {
770
1600
  /**
771
1601
  * Create the report function
772
1602
  *
773
- * @param {object} context
774
- * @param {object} commentNode
1603
+ * @callback MakeReport
1604
+ * @param {import('eslint').Rule.RuleContext} context
1605
+ * @param {import('estree').Node} commentNode
1606
+ * @returns {Report}
775
1607
  */
1608
+
1609
+ /** @type {MakeReport} */
776
1610
  exports.getSettings = getSettings;
777
1611
  const makeReport = (context, commentNode) => {
778
- const report = (message, fix = null, jsdocLoc = null, data = null) => {
1612
+ /** @type {Report} */
1613
+ const report = (message, fix = null, jsdocLoc = null, data = undefined) => {
1614
+ /* eslint-enable jsdoc/valid-types -- Old version */
779
1615
  let loc;
780
1616
  if (jsdocLoc) {
781
1617
  if (!('line' in jsdocLoc)) {
782
- jsdocLoc.line = jsdocLoc.source[0].number;
1618
+ jsdocLoc.line = /** @type {import('comment-parser').Spec & {line?: Integer}} */jsdocLoc.source[0].number;
783
1619
  }
784
- const lineNumber = commentNode.loc.start.line + jsdocLoc.line;
1620
+ const lineNumber = /** @type {import('eslint').AST.SourceLocation} */commentNode.loc.start.line + /** @type {Integer} */jsdocLoc.line;
785
1621
  loc = {
786
1622
  end: {
787
1623
  column: 0,
@@ -795,8 +1631,8 @@ const makeReport = (context, commentNode) => {
795
1631
 
796
1632
  // Todo: Remove ignore once `check-examples` can be restored for ESLint 8+
797
1633
  // istanbul ignore if
798
- if (jsdocLoc.column) {
799
- const colNumber = commentNode.loc.start.column + jsdocLoc.column;
1634
+ if ('column' in jsdocLoc && typeof jsdocLoc.column === 'number') {
1635
+ const colNumber = /** @type {import('eslint').AST.SourceLocation} */commentNode.loc.start.column + jsdocLoc.column;
800
1636
  loc.end.column = colNumber;
801
1637
  loc.start.column = colNumber;
802
1638
  }
@@ -812,29 +1648,89 @@ const makeReport = (context, commentNode) => {
812
1648
  return report;
813
1649
  };
814
1650
 
815
- /* eslint-disable jsdoc/no-undefined-types -- canonical still using an older version where not defined */
1651
+ /* eslint-disable jsdoc/valid-types -- Old version */
816
1652
  /**
817
- * @typedef {ReturnType<typeof getUtils>} Utils
818
- * @typedef {ReturnType<typeof getSettings>} Settings
819
1653
  * @typedef {(
820
1654
  * arg: {
821
- * context: object,
822
- * sourceCode: object,
1655
+ * context: import('eslint').Rule.RuleContext,
1656
+ * sourceCode: import('eslint').SourceCode,
1657
+ * indent?: string,
1658
+ * info?: {
1659
+ * comment?: string|undefined,
1660
+ * lastIndex?: Integer|undefined
1661
+ * },
1662
+ * state?: StateObject,
1663
+ * globalState?: Map<string, Map<string, string>>,
1664
+ * jsdoc?: import('comment-parser').Block,
1665
+ * jsdocNode?: import('eslint').Rule.Node & {
1666
+ * range: [number, number]
1667
+ * },
1668
+ * node?: Node,
1669
+ * allComments?: import('estree').Node[]
1670
+ * report?: Report,
1671
+ * makeReport?: MakeReport,
1672
+ * settings: Settings,
1673
+ * utils: BasicUtils,
1674
+ * }
1675
+ * ) => any } JsdocVisitorBasic
1676
+ */
1677
+ /**
1678
+ * @typedef {(
1679
+ * arg: {
1680
+ * context: import('eslint').Rule.RuleContext,
1681
+ * sourceCode: import('eslint').SourceCode,
823
1682
  * indent: string,
824
- * jsdoc: object,
825
- * jsdocNode: object,
826
- * node: Node | null,
827
- * report: ReturnType<typeof makeReport>,
1683
+ * info: {
1684
+ * comment?: string|undefined,
1685
+ * lastIndex?: Integer|undefined
1686
+ * },
1687
+ * state: StateObject,
1688
+ * globalState: Map<string, Map<string, string>>,
1689
+ * jsdoc: import('comment-parser').Block,
1690
+ * jsdocNode: import('eslint').Rule.Node & {
1691
+ * range: [number, number]
1692
+ * },
1693
+ * node: Node|null,
1694
+ * allComments?: import('estree').Node[]
1695
+ * report: Report,
1696
+ * makeReport?: MakeReport,
828
1697
  * settings: Settings,
829
1698
  * utils: Utils,
830
1699
  * }
831
1700
  * ) => any } JsdocVisitor
832
1701
  */
1702
+ /* eslint-enable jsdoc/valid-types -- Old version */
833
1703
  /* eslint-enable jsdoc/no-undefined-types -- canonical still using an older version where not defined */
834
1704
 
1705
+ /**
1706
+ * @param {{
1707
+ * comment?: string,
1708
+ * lastIndex?: Integer,
1709
+ * selector?: string,
1710
+ * isFunctionContext?: boolean,
1711
+ * }} info
1712
+ * @param {string} indent
1713
+ * @param {import('comment-parser').Block & {
1714
+ * inlineTags: import('@es-joy/jsdoccomment').InlineTag[]
1715
+ * }} jsdoc
1716
+ * @param {RuleConfig} ruleConfig
1717
+ * @param {import('eslint').Rule.RuleContext} context
1718
+ * @param {string[]} lines
1719
+ * @param {import('@es-joy/jsdoccomment').Token} jsdocNode
1720
+ * @param {Node|null} node
1721
+ * @param {Settings} settings
1722
+ * @param {import('eslint').SourceCode} sourceCode
1723
+ * @param {JsdocVisitor} iterator
1724
+ * @param {StateObject} state
1725
+ * @param {boolean} [iteratingAll]
1726
+ * @returns {void}
1727
+ */
835
1728
  const iterate = (info, indent, jsdoc, ruleConfig, context, lines, jsdocNode, node, settings, sourceCode, iterator, state, iteratingAll) => {
836
- const report = makeReport(context, jsdocNode);
837
- const utils = getUtils(node, jsdoc, jsdocNode, settings, report, context, iteratingAll, ruleConfig, indent);
1729
+ const jsdocNde = /** @type {unknown} */jsdocNode;
1730
+ const report = makeReport(context, /** @type {import('estree').Node} */
1731
+ jsdocNde);
1732
+ const utils = getUtils(node, jsdoc, /** @type {import('eslint').AST.Token} */
1733
+ jsdocNode, settings, report, context, iteratingAll, ruleConfig, indent);
838
1734
  if (!ruleConfig.checkInternal && settings.ignoreInternal && utils.hasTag('internal')) {
839
1735
  return;
840
1736
  }
@@ -854,9 +1750,13 @@ const iterate = (info, indent, jsdoc, ruleConfig, context, lines, jsdocNode, nod
854
1750
  globalState,
855
1751
  indent,
856
1752
  info,
857
- iteratingAll,
858
1753
  jsdoc,
859
- jsdocNode,
1754
+ jsdocNode:
1755
+ /**
1756
+ * @type {import('eslint').Rule.Node & {
1757
+ * range: [number, number];}}
1758
+ */
1759
+ jsdocNde,
860
1760
  node,
861
1761
  report,
862
1762
  settings,
@@ -865,23 +1765,28 @@ const iterate = (info, indent, jsdoc, ruleConfig, context, lines, jsdocNode, nod
865
1765
  utils
866
1766
  });
867
1767
  };
1768
+
1769
+ /**
1770
+ * @param {string[]} lines
1771
+ * @param {import('estree').Comment} jsdocNode
1772
+ * @returns {[indent: string, jsdoc: import('comment-parser').Block & {
1773
+ * inlineTags: import('@es-joy/jsdoccomment').InlineTag[]
1774
+ * }]}
1775
+ */
868
1776
  const getIndentAndJSDoc = function (lines, jsdocNode) {
869
- const sourceLine = lines[jsdocNode.loc.start.line - 1];
870
- const indnt = sourceLine.charAt(0).repeat(jsdocNode.loc.start.column);
1777
+ const sourceLine = lines[/** @type {import('estree').SourceLocation} */
1778
+ jsdocNode.loc.start.line - 1];
1779
+ const indnt = sourceLine.charAt(0).repeat( /** @type {import('estree').SourceLocation} */
1780
+ jsdocNode.loc.start.column);
871
1781
  const jsdc = (0, _jsdoccomment.parseComment)(jsdocNode, '');
872
1782
  return [indnt, jsdc];
873
1783
  };
874
1784
 
875
1785
  /**
876
1786
  *
877
- * @typedef {{node: Node, state: StateObject}} NonCommentArgs
878
- */
879
-
880
- /**
881
- * Our internal dynamic set of utilities.
882
- *
883
- * @todo Document
884
- * @typedef {any} Utils
1787
+ * @typedef {{node: Node & {
1788
+ * range: [number, number]
1789
+ * }, state: StateObject}} NonCommentArgs
885
1790
  */
886
1791
 
887
1792
  /**
@@ -891,9 +1796,20 @@ const getIndentAndJSDoc = function (lines, jsdocNode) {
891
1796
  * @property {true} [contextSelected] Whether to force a `contexts` check
892
1797
  * @property {true} [iterateAllJsdocs] Whether to iterate all JSDoc blocks by default
893
1798
  * regardless of context
894
- * @property {(context, state: StateObject, utils: Utils) => void} [exit] Handler to be executed
895
- * upon exiting iteration of program AST
896
- * @property {(NonCommentArgs) => void} [nonComment] Handler to be executed if rule wishes
1799
+ * @property {true} [checkPrivate] Whether to check `@private` blocks (normally exempted)
1800
+ * @property {true} [checkInternal] Whether to check `@internal` blocks (normally exempted)
1801
+ * @property {true} [checkFile] Whether to iterates over all JSDoc blocks regardless of attachment
1802
+ * @property {true} [nonGlobalSettings] Whether to avoid relying on settings for global contexts
1803
+ * @property {true} [noTracking] Whether to disable the tracking of visited comment nodes (as
1804
+ * non-tracked may conduct further actions)
1805
+ * @property {true} [matchContext] Whether the rule expects contexts to be based on a match option
1806
+ * @property {(args: {
1807
+ * context: import('eslint').Rule.RuleContext,
1808
+ * state: StateObject,
1809
+ * settings: Settings,
1810
+ * utils: BasicUtils
1811
+ * }) => void} [exit] Handler to be executed upon exiting iteration of program AST
1812
+ * @property {(nca: NonCommentArgs) => void} [nonComment] Handler to be executed if rule wishes
897
1813
  * to be supplied nodes without comments
898
1814
  */
899
1815
 
@@ -903,30 +1819,46 @@ const getIndentAndJSDoc = function (lines, jsdocNode) {
903
1819
  *
904
1820
  * @param {JsdocVisitor} iterator
905
1821
  * @param {RuleConfig} ruleConfig The rule's configuration
906
- * @param contexts The `contexts` containing relevant `comment` info.
907
- * @param {boolean} additiveCommentContexts If true, will have a separate
1822
+ * @param {ContextObject[]|null} [contexts] The `contexts` containing relevant `comment` info.
1823
+ * @param {boolean} [additiveCommentContexts] If true, will have a separate
908
1824
  * iteration for each matching comment context. Otherwise, will iterate
909
1825
  * once if there is a single matching comment context.
1826
+ * @returns {import('eslint').Rule.RuleModule}
910
1827
  */
911
1828
  const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContexts) => {
912
1829
  const trackedJsdocs = new Set();
1830
+
1831
+ /** @type {import('@es-joy/jsdoccomment').CommentHandler} */
913
1832
  let handler;
1833
+
1834
+ /** @type {Settings|false} */
914
1835
  let settings;
1836
+
1837
+ /**
1838
+ * @param {import('eslint').Rule.RuleContext} context
1839
+ * @param {Node|null} node
1840
+ * @param {import('estree').Comment[]} jsdocNodes
1841
+ * @param {StateObject} state
1842
+ * @param {boolean} [lastCall]
1843
+ * @returns {void}
1844
+ */
915
1845
  const callIterator = (context, node, jsdocNodes, state, lastCall) => {
916
1846
  const sourceCode = context.getSourceCode();
917
1847
  const {
918
1848
  lines
919
1849
  } = sourceCode;
920
- const utils = getBasicUtils(context, settings);
1850
+ const utils = getBasicUtils(context, /** @type {Settings} */settings);
921
1851
  for (const jsdocNode of jsdocNodes) {
922
- if (!/^\/\*\*\s/u.test(sourceCode.getText(jsdocNode))) {
1852
+ const jsdocNde = /** @type {unknown} */jsdocNode;
1853
+ if (!/^\/\*\*\s/u.test(sourceCode.getText( /** @type {import('estree').Node} */
1854
+ jsdocNde))) {
923
1855
  continue;
924
1856
  }
925
1857
  const [indent, jsdoc] = getIndentAndJSDoc(lines, jsdocNode);
926
1858
  if (additiveCommentContexts) {
927
1859
  for (const [idx, {
928
1860
  comment
929
- }] of contexts.entries()) {
1861
+ }] of /** @type {ContextObject[]} */contexts.entries()) {
930
1862
  if (comment && handler(comment, jsdoc) === false) {
931
1863
  continue;
932
1864
  }
@@ -934,7 +1866,9 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext
934
1866
  comment,
935
1867
  lastIndex: idx,
936
1868
  selector: node === null || node === void 0 ? void 0 : node.type
937
- }, indent, jsdoc, ruleConfig, context, lines, jsdocNode, node, settings, sourceCode, iterator, state, true);
1869
+ }, indent, jsdoc, ruleConfig, context, lines, jsdocNode, /** @type {Node} */
1870
+ node, /** @type {Settings} */
1871
+ settings, sourceCode, iterator, state, true);
938
1872
  }
939
1873
  continue;
940
1874
  }
@@ -957,18 +1891,21 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext
957
1891
  } : {
958
1892
  lastIndex,
959
1893
  selector: node === null || node === void 0 ? void 0 : node.type
960
- }, indent, jsdoc, ruleConfig, context, lines, jsdocNode, node, settings, sourceCode, iterator, state, true);
1894
+ }, indent, jsdoc, ruleConfig, context, lines, jsdocNode, node, /** @type {Settings} */
1895
+ settings, sourceCode, iterator, state, true);
961
1896
  }
1897
+ const settngs = /** @type {Settings} */settings;
962
1898
  if (lastCall && ruleConfig.exit) {
963
1899
  ruleConfig.exit({
964
1900
  context,
965
- settings,
1901
+ settings: settngs,
966
1902
  state,
967
1903
  utils
968
1904
  });
969
1905
  }
970
1906
  };
971
1907
  return {
1908
+ // @ts-expect-error ESLint accepts
972
1909
  create(context) {
973
1910
  const sourceCode = context.getSourceCode();
974
1911
  settings = getSettings(context);
@@ -980,29 +1917,38 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext
980
1917
  }
981
1918
  const state = {};
982
1919
  return {
1920
+ /**
1921
+ * @param {import('eslint').Rule.Node & {
1922
+ * range: [Integer, Integer];
1923
+ * }} node
1924
+ * @returns {void}
1925
+ */
983
1926
  '*:not(Program)'(node) {
984
- const commentNode = (0, _jsdoccomment.getJSDocComment)(sourceCode, node, settings);
1927
+ const commentNode = (0, _jsdoccomment.getJSDocComment)(sourceCode, node, /** @type {Settings} */settings);
985
1928
  if (!ruleConfig.noTracking && trackedJsdocs.has(commentNode)) {
986
1929
  return;
987
1930
  }
988
1931
  if (!commentNode) {
989
1932
  if (ruleConfig.nonComment) {
1933
+ const ste = /** @type {StateObject} */state;
990
1934
  ruleConfig.nonComment({
991
1935
  node,
992
- state
1936
+ state: ste
993
1937
  });
994
1938
  }
995
1939
  return;
996
1940
  }
997
1941
  trackedJsdocs.add(commentNode);
998
- callIterator(context, node, [commentNode], state);
1942
+ callIterator(context, node, [/** @type {import('estree').Comment} */
1943
+ commentNode], /** @type {StateObject} */state);
999
1944
  },
1000
1945
  'Program:exit'() {
1001
1946
  const allComments = sourceCode.getAllComments();
1002
1947
  const untrackedJSdoc = allComments.filter(node => {
1003
1948
  return !trackedJsdocs.has(node);
1004
1949
  });
1005
- callIterator(context, null, untrackedJSdoc, state, true);
1950
+ callIterator(context, null, untrackedJSdoc, /** @type {StateObject} */
1951
+ state, true);
1006
1952
  }
1007
1953
  };
1008
1954
  },
@@ -1014,8 +1960,9 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext
1014
1960
  * Create an eslint rule that iterates over all JSDocs, regardless of whether
1015
1961
  * they are attached to a function-like node.
1016
1962
  *
1017
- * @param {JsdocVisitor} iterator
1963
+ * @param {JsdocVisitorBasic} iterator
1018
1964
  * @param {RuleConfig} ruleConfig
1965
+ * @returns {import('eslint').Rule.RuleModule}
1019
1966
  */
1020
1967
  const checkFile = (iterator, ruleConfig) => {
1021
1968
  return {
@@ -1027,15 +1974,11 @@ const checkFile = (iterator, ruleConfig) => {
1027
1974
  }
1028
1975
  return {
1029
1976
  'Program:exit'() {
1030
- const allComments = sourceCode.getAllComments();
1031
- const {
1032
- lines
1033
- } = sourceCode;
1977
+ const allComms = /** @type {unknown} */sourceCode.getAllComments();
1034
1978
  const utils = getBasicUtils(context, settings);
1035
1979
  iterator({
1036
- allComments,
1980
+ allComments: /** @type {import('estree').Node[]} */allComms,
1037
1981
  context,
1038
- lines,
1039
1982
  makeReport,
1040
1983
  settings,
1041
1984
  sourceCode,
@@ -1050,6 +1993,7 @@ const checkFile = (iterator, ruleConfig) => {
1050
1993
  /**
1051
1994
  * @param {JsdocVisitor} iterator
1052
1995
  * @param {RuleConfig} ruleConfig
1996
+ * @returns {import('eslint').Rule.RuleModule}
1053
1997
  */
1054
1998
  function iterateJsdoc(iterator, ruleConfig) {
1055
1999
  var _ruleConfig$meta;
@@ -1061,27 +2005,34 @@ function iterateJsdoc(iterator, ruleConfig) {
1061
2005
  throw new TypeError('The iterator argument must be a function.');
1062
2006
  }
1063
2007
  if (ruleConfig.checkFile) {
1064
- return checkFile(iterator, ruleConfig);
2008
+ return checkFile( /** @type {JsdocVisitorBasic} */iterator, ruleConfig);
1065
2009
  }
1066
2010
  if (ruleConfig.iterateAllJsdocs) {
1067
2011
  return iterateAllJsdocs(iterator, ruleConfig);
1068
2012
  }
2013
+
2014
+ /** @type {import('eslint').Rule.RuleModule} */
1069
2015
  return {
1070
2016
  /**
1071
2017
  * The entrypoint for the JSDoc rule.
1072
2018
  *
1073
- * @param {*} context
2019
+ * @param {import('eslint').Rule.RuleContext} context
1074
2020
  * a reference to the context which hold all important information
1075
2021
  * like settings and the sourcecode to check.
1076
- * @returns {object}
1077
- * a list with parser callback function.
2022
+ * @returns {import('eslint').Rule.RuleListener}
2023
+ * a listener with parser callback function.
1078
2024
  */
1079
2025
  create(context) {
1080
2026
  const settings = getSettings(context);
1081
2027
  if (!settings) {
1082
2028
  return {};
1083
2029
  }
2030
+
2031
+ /**
2032
+ * @type {Context[]|undefined}
2033
+ */
1084
2034
  let contexts;
2035
+ /* eslint-enable jsdoc/valid-types -- Old version */
1085
2036
  if (ruleConfig.contextDefaults || ruleConfig.contextSelected || ruleConfig.matchContext) {
1086
2037
  var _context$options$2, _contexts, _contexts2;
1087
2038
  contexts = ruleConfig.matchContext && (_context$options$2 = context.options[0]) !== null && _context$options$2 !== void 0 && _context$options$2.match ? context.options[0].match : _jsdocUtils.default.enforcedContexts(context, ruleConfig.contextDefaults, ruleConfig.nonGlobalSettings ? {} : settings);
@@ -1098,23 +2049,33 @@ function iterateJsdoc(iterator, ruleConfig) {
1098
2049
  }
1099
2050
  const hasPlainAny = (_contexts = contexts) === null || _contexts === void 0 ? void 0 : _contexts.includes('any');
1100
2051
  const hasObjectAny = !hasPlainAny && ((_contexts2 = contexts) === null || _contexts2 === void 0 ? void 0 : _contexts2.find(ctxt => {
2052
+ if (typeof ctxt === 'string') {
2053
+ return false;
2054
+ }
1101
2055
  return (ctxt === null || ctxt === void 0 ? void 0 : ctxt.context) === 'any';
1102
2056
  }));
1103
2057
  if (hasPlainAny || hasObjectAny) {
1104
- return iterateAllJsdocs(iterator, ruleConfig, hasObjectAny ? contexts : null, ruleConfig.matchContext).create(context);
2058
+ return iterateAllJsdocs(iterator, ruleConfig, hasObjectAny ? /** @type {ContextObject[]} */contexts : null, ruleConfig.matchContext).create(context);
1105
2059
  }
1106
2060
  }
1107
2061
  const sourceCode = context.getSourceCode();
1108
2062
  const {
1109
2063
  lines
1110
2064
  } = sourceCode;
2065
+
2066
+ /* eslint-disable jsdoc/no-undefined-types -- TS */
2067
+ /** @type {Partial<StateObject>} */
1111
2068
  const state = {};
2069
+ /* eslint-enable jsdoc/no-undefined-types -- TS */
2070
+
2071
+ /** @type {CheckJsdoc} */
1112
2072
  const checkJsdoc = (info, handler, node) => {
1113
2073
  const jsdocNode = (0, _jsdoccomment.getJSDocComment)(sourceCode, node, settings);
1114
2074
  if (!jsdocNode) {
1115
2075
  return;
1116
2076
  }
1117
- const [indent, jsdoc] = getIndentAndJSDoc(lines, jsdocNode);
2077
+ const [indent, jsdoc] = getIndentAndJSDoc(lines, /** @type {import('estree').Comment} */
2078
+ jsdocNode);
1118
2079
  if (
1119
2080
  // Note, `handler` should already be bound in its first argument
1120
2081
  // with these only to be called after the value of
@@ -1122,8 +2083,11 @@ function iterateJsdoc(iterator, ruleConfig) {
1122
2083
  handler && handler(jsdoc) === false) {
1123
2084
  return;
1124
2085
  }
1125
- iterate(info, indent, jsdoc, ruleConfig, context, lines, jsdocNode, node, settings, sourceCode, iterator, state);
2086
+ iterate(info, indent, jsdoc, ruleConfig, context, lines, jsdocNode, node, settings, sourceCode, iterator, /** @type {StateObject} */
2087
+ state);
1126
2088
  };
2089
+
2090
+ /** @type {import('eslint').Rule.RuleListener} */
1127
2091
  let contextObject = {};
1128
2092
  if (contexts && (ruleConfig.contextDefaults || ruleConfig.contextSelected || ruleConfig.matchContext)) {
1129
2093
  contextObject = _jsdocUtils.default.getContextObject(contexts, checkJsdoc, (0, _jsdoccomment.commentHandler)(settings));
@@ -1134,15 +2098,21 @@ function iterateJsdoc(iterator, ruleConfig) {
1134
2098
  }, null);
1135
2099
  }
1136
2100
  }
1137
- if (ruleConfig.exit) {
2101
+ if (typeof ruleConfig.exit === 'function') {
1138
2102
  contextObject['Program:exit'] = () => {
2103
+ const ste = /** @type {StateObject} */state;
2104
+ /* eslint-disable jsdoc/no-undefined-types -- Bug */
2105
+ // @ts-expect-error `utils` not needed at this point
2106
+ /** @type {Required<RuleConfig>} */
1139
2107
  ruleConfig.exit({
1140
2108
  context,
1141
2109
  settings,
1142
- state
2110
+ state: ste
1143
2111
  });
2112
+ /* eslint-enable jsdoc/no-undefined-types -- Bug */
1144
2113
  };
1145
2114
  }
2115
+
1146
2116
  return contextObject;
1147
2117
  },
1148
2118
  meta: ruleConfig.meta