eslint-plugin-jsdoc 52.0.1 → 52.0.3

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 (357) hide show
  1. package/dist/WarnSettings.cjs +18 -35
  2. package/dist/WarnSettings.cjs.map +1 -1
  3. package/dist/WarnSettings.js +20 -0
  4. package/dist/WarnSettings.js.map +1 -0
  5. package/dist/_virtual/rolldown_runtime.cjs +32 -0
  6. package/dist/_virtual/rolldown_runtime.js +11 -0
  7. package/dist/alignTransform.cjs +224 -305
  8. package/dist/alignTransform.cjs.map +1 -1
  9. package/dist/alignTransform.js +241 -0
  10. package/dist/alignTransform.js.map +1 -0
  11. package/dist/defaultTagOrder.cjs +132 -43
  12. package/dist/defaultTagOrder.cjs.map +1 -1
  13. package/dist/defaultTagOrder.js +134 -0
  14. package/dist/defaultTagOrder.js.map +1 -0
  15. package/dist/exportParser.cjs +478 -696
  16. package/dist/exportParser.cjs.map +1 -1
  17. package/dist/exportParser.js +518 -0
  18. package/dist/exportParser.js.map +1 -0
  19. package/dist/getDefaultTagStructureForMode.cjs +184 -288
  20. package/dist/getDefaultTagStructureForMode.cjs.map +1 -1
  21. package/dist/getDefaultTagStructureForMode.js +188 -0
  22. package/dist/getDefaultTagStructureForMode.js.map +1 -0
  23. package/dist/getJsdocProcessorPlugin.cjs +365 -532
  24. package/dist/getJsdocProcessorPlugin.cjs.map +1 -1
  25. package/dist/getJsdocProcessorPlugin.d.cts +70 -0
  26. package/dist/getJsdocProcessorPlugin.d.cts.map +1 -0
  27. package/dist/getJsdocProcessorPlugin.d.ts +68 -90
  28. package/dist/getJsdocProcessorPlugin.d.ts.map +1 -1
  29. package/dist/getJsdocProcessorPlugin.js +383 -0
  30. package/dist/getJsdocProcessorPlugin.js.map +1 -0
  31. package/dist/index.cjs +398 -383
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.cts +22 -0
  34. package/dist/index.d.cts.map +1 -0
  35. package/dist/index.d.ts +11 -6
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +425 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/iterateJsdoc.cjs +1528 -1988
  40. package/dist/iterateJsdoc.cjs.map +1 -1
  41. package/dist/iterateJsdoc.d.cts +471 -0
  42. package/dist/iterateJsdoc.d.cts.map +1 -0
  43. package/dist/iterateJsdoc.d.ts +358 -349
  44. package/dist/iterateJsdoc.d.ts.map +1 -1
  45. package/dist/iterateJsdoc.js +1617 -0
  46. package/dist/iterateJsdoc.js.map +1 -0
  47. package/dist/jsdocUtils.cjs +1009 -1376
  48. package/dist/jsdocUtils.cjs.map +1 -1
  49. package/dist/jsdocUtils.js +1123 -0
  50. package/dist/jsdocUtils.js.map +1 -0
  51. package/dist/rules/checkAccess.cjs +29 -36
  52. package/dist/rules/checkAccess.cjs.map +1 -1
  53. package/dist/rules/checkAccess.js +33 -0
  54. package/dist/rules/checkAccess.js.map +1 -0
  55. package/dist/rules/checkAlignment.cjs +41 -54
  56. package/dist/rules/checkAlignment.cjs.map +1 -1
  57. package/dist/rules/checkAlignment.js +47 -0
  58. package/dist/rules/checkAlignment.js.map +1 -0
  59. package/dist/rules/checkExamples.cjs +327 -484
  60. package/dist/rules/checkExamples.cjs.map +1 -1
  61. package/dist/rules/checkExamples.js +348 -0
  62. package/dist/rules/checkExamples.js.map +1 -0
  63. package/dist/rules/checkIndentation.cjs +50 -65
  64. package/dist/rules/checkIndentation.cjs.map +1 -1
  65. package/dist/rules/checkIndentation.js +59 -0
  66. package/dist/rules/checkIndentation.js.map +1 -0
  67. package/dist/rules/checkLineAlignment.cjs +220 -311
  68. package/dist/rules/checkLineAlignment.cjs.map +1 -1
  69. package/dist/rules/checkLineAlignment.js +229 -0
  70. package/dist/rules/checkLineAlignment.js.map +1 -0
  71. package/dist/rules/checkParamNames.cjs +227 -335
  72. package/dist/rules/checkParamNames.cjs.map +1 -1
  73. package/dist/rules/checkParamNames.js +237 -0
  74. package/dist/rules/checkParamNames.js.map +1 -0
  75. package/dist/rules/checkPropertyNames.cjs +78 -106
  76. package/dist/rules/checkPropertyNames.cjs.map +1 -1
  77. package/dist/rules/checkPropertyNames.js +88 -0
  78. package/dist/rules/checkPropertyNames.js.map +1 -0
  79. package/dist/rules/checkSyntax.cjs +21 -34
  80. package/dist/rules/checkSyntax.cjs.map +1 -1
  81. package/dist/rules/checkSyntax.js +25 -0
  82. package/dist/rules/checkSyntax.js.map +1 -0
  83. package/dist/rules/checkTagNames.cjs +188 -210
  84. package/dist/rules/checkTagNames.cjs.map +1 -1
  85. package/dist/rules/checkTagNames.js +191 -0
  86. package/dist/rules/checkTagNames.js.map +1 -0
  87. package/dist/rules/checkTemplateNames.cjs +121 -178
  88. package/dist/rules/checkTemplateNames.cjs.map +1 -1
  89. package/dist/rules/checkTemplateNames.js +124 -0
  90. package/dist/rules/checkTemplateNames.js.map +1 -0
  91. package/dist/rules/checkTypes.cjs +291 -385
  92. package/dist/rules/checkTypes.cjs.map +1 -1
  93. package/dist/rules/checkTypes.js +299 -0
  94. package/dist/rules/checkTypes.js.map +1 -0
  95. package/dist/rules/checkValues.cjs +100 -146
  96. package/dist/rules/checkValues.cjs.map +1 -1
  97. package/dist/rules/checkValues.js +103 -0
  98. package/dist/rules/checkValues.js.map +1 -0
  99. package/dist/rules/convertToJsdocComments.cjs +228 -306
  100. package/dist/rules/convertToJsdocComments.cjs.map +1 -1
  101. package/dist/rules/convertToJsdocComments.js +231 -0
  102. package/dist/rules/convertToJsdocComments.js.map +1 -0
  103. package/dist/rules/emptyTags.cjs +62 -72
  104. package/dist/rules/emptyTags.cjs.map +1 -1
  105. package/dist/rules/emptyTags.js +67 -0
  106. package/dist/rules/emptyTags.js.map +1 -0
  107. package/dist/rules/implementsOnClasses.cjs +36 -56
  108. package/dist/rules/implementsOnClasses.cjs.map +1 -1
  109. package/dist/rules/implementsOnClasses.js +40 -0
  110. package/dist/rules/implementsOnClasses.js.map +1 -0
  111. package/dist/rules/importsAsDependencies.cjs +62 -99
  112. package/dist/rules/importsAsDependencies.cjs.map +1 -1
  113. package/dist/rules/importsAsDependencies.js +68 -0
  114. package/dist/rules/importsAsDependencies.js.map +1 -0
  115. package/dist/rules/informativeDocs.cjs +105 -142
  116. package/dist/rules/informativeDocs.cjs.map +1 -1
  117. package/dist/rules/informativeDocs.js +110 -0
  118. package/dist/rules/informativeDocs.js.map +1 -0
  119. package/dist/rules/linesBeforeBlock.cjs +70 -105
  120. package/dist/rules/linesBeforeBlock.cjs.map +1 -1
  121. package/dist/rules/linesBeforeBlock.js +75 -0
  122. package/dist/rules/linesBeforeBlock.js.map +1 -0
  123. package/dist/rules/matchDescription.cjs +160 -222
  124. package/dist/rules/matchDescription.cjs.map +1 -1
  125. package/dist/rules/matchDescription.js +167 -0
  126. package/dist/rules/matchDescription.js.map +1 -0
  127. package/dist/rules/matchName.cjs +73 -128
  128. package/dist/rules/matchName.cjs.map +1 -1
  129. package/dist/rules/matchName.js +77 -0
  130. package/dist/rules/matchName.js.map +1 -0
  131. package/dist/rules/multilineBlocks.cjs +235 -352
  132. package/dist/rules/multilineBlocks.cjs.map +1 -1
  133. package/dist/rules/multilineBlocks.js +245 -0
  134. package/dist/rules/multilineBlocks.js.map +1 -0
  135. package/dist/rules/noBadBlocks.cjs +63 -86
  136. package/dist/rules/noBadBlocks.cjs.map +1 -1
  137. package/dist/rules/noBadBlocks.js +68 -0
  138. package/dist/rules/noBadBlocks.js.map +1 -0
  139. package/dist/rules/noBlankBlockDescriptions.cjs +35 -57
  140. package/dist/rules/noBlankBlockDescriptions.cjs.map +1 -1
  141. package/dist/rules/noBlankBlockDescriptions.js +41 -0
  142. package/dist/rules/noBlankBlockDescriptions.js.map +1 -0
  143. package/dist/rules/noBlankBlocks.cjs +26 -48
  144. package/dist/rules/noBlankBlocks.cjs.map +1 -1
  145. package/dist/rules/noBlankBlocks.js +30 -0
  146. package/dist/rules/noBlankBlocks.js.map +1 -0
  147. package/dist/rules/noDefaults.cjs +52 -79
  148. package/dist/rules/noDefaults.cjs.map +1 -1
  149. package/dist/rules/noDefaults.js +56 -0
  150. package/dist/rules/noDefaults.js.map +1 -0
  151. package/dist/rules/noMissingSyntax.cjs +115 -165
  152. package/dist/rules/noMissingSyntax.cjs.map +1 -1
  153. package/dist/rules/noMissingSyntax.js +126 -0
  154. package/dist/rules/noMissingSyntax.js.map +1 -0
  155. package/dist/rules/noMultiAsterisks.cjs +48 -89
  156. package/dist/rules/noMultiAsterisks.cjs.map +1 -1
  157. package/dist/rules/noMultiAsterisks.js +58 -0
  158. package/dist/rules/noMultiAsterisks.js.map +1 -0
  159. package/dist/rules/noRestrictedSyntax.cjs +45 -79
  160. package/dist/rules/noRestrictedSyntax.cjs.map +1 -1
  161. package/dist/rules/noRestrictedSyntax.js +49 -0
  162. package/dist/rules/noRestrictedSyntax.js.map +1 -0
  163. package/dist/rules/noTypes.cjs +59 -80
  164. package/dist/rules/noTypes.cjs.map +1 -1
  165. package/dist/rules/noTypes.js +65 -0
  166. package/dist/rules/noTypes.js.map +1 -0
  167. package/dist/rules/noUndefinedTypes.cjs +297 -388
  168. package/dist/rules/noUndefinedTypes.cjs.map +1 -1
  169. package/dist/rules/noUndefinedTypes.js +303 -0
  170. package/dist/rules/noUndefinedTypes.js.map +1 -0
  171. package/dist/rules/requireAsteriskPrefix.cjs +108 -159
  172. package/dist/rules/requireAsteriskPrefix.cjs.map +1 -1
  173. package/dist/rules/requireAsteriskPrefix.js +112 -0
  174. package/dist/rules/requireAsteriskPrefix.js.map +1 -0
  175. package/dist/rules/requireDescription.cjs +89 -129
  176. package/dist/rules/requireDescription.cjs.map +1 -1
  177. package/dist/rules/requireDescription.js +95 -0
  178. package/dist/rules/requireDescription.js.map +1 -0
  179. package/dist/rules/requireDescriptionCompleteSentence.cjs +201 -262
  180. package/dist/rules/requireDescriptionCompleteSentence.cjs.map +1 -1
  181. package/dist/rules/requireDescriptionCompleteSentence.js +220 -0
  182. package/dist/rules/requireDescriptionCompleteSentence.js.map +1 -0
  183. package/dist/rules/requireExample.cjs +73 -104
  184. package/dist/rules/requireExample.cjs.map +1 -1
  185. package/dist/rules/requireExample.js +77 -0
  186. package/dist/rules/requireExample.js.map +1 -0
  187. package/dist/rules/requireFileOverview.cjs +75 -129
  188. package/dist/rules/requireFileOverview.cjs.map +1 -1
  189. package/dist/rules/requireFileOverview.js +81 -0
  190. package/dist/rules/requireFileOverview.js.map +1 -0
  191. package/dist/rules/requireHyphenBeforeParamDescription.cjs +85 -133
  192. package/dist/rules/requireHyphenBeforeParamDescription.cjs.map +1 -1
  193. package/dist/rules/requireHyphenBeforeParamDescription.js +89 -0
  194. package/dist/rules/requireHyphenBeforeParamDescription.js.map +1 -0
  195. package/dist/rules/requireJsdoc.cjs +384 -557
  196. package/dist/rules/requireJsdoc.cjs.map +1 -1
  197. package/dist/rules/requireJsdoc.js +404 -0
  198. package/dist/rules/requireJsdoc.js.map +1 -0
  199. package/dist/rules/requireParam.cjs +336 -526
  200. package/dist/rules/requireParam.cjs.map +1 -1
  201. package/dist/rules/requireParam.js +344 -0
  202. package/dist/rules/requireParam.js.map +1 -0
  203. package/dist/rules/requireParamDescription.cjs +55 -80
  204. package/dist/rules/requireParamDescription.cjs.map +1 -1
  205. package/dist/rules/requireParamDescription.js +59 -0
  206. package/dist/rules/requireParamDescription.js.map +1 -0
  207. package/dist/rules/requireParamName.cjs +32 -50
  208. package/dist/rules/requireParamName.cjs.map +1 -1
  209. package/dist/rules/requireParamName.js +36 -0
  210. package/dist/rules/requireParamName.js.map +1 -0
  211. package/dist/rules/requireParamType.cjs +55 -80
  212. package/dist/rules/requireParamType.cjs.map +1 -1
  213. package/dist/rules/requireParamType.js +59 -0
  214. package/dist/rules/requireParamType.js.map +1 -0
  215. package/dist/rules/requireProperty.cjs +31 -42
  216. package/dist/rules/requireProperty.cjs.map +1 -1
  217. package/dist/rules/requireProperty.js +35 -0
  218. package/dist/rules/requireProperty.js.map +1 -0
  219. package/dist/rules/requirePropertyDescription.cjs +17 -25
  220. package/dist/rules/requirePropertyDescription.cjs.map +1 -1
  221. package/dist/rules/requirePropertyDescription.js +21 -0
  222. package/dist/rules/requirePropertyDescription.js.map +1 -0
  223. package/dist/rules/requirePropertyName.cjs +17 -25
  224. package/dist/rules/requirePropertyName.cjs.map +1 -1
  225. package/dist/rules/requirePropertyName.js +21 -0
  226. package/dist/rules/requirePropertyName.js.map +1 -0
  227. package/dist/rules/requirePropertyType.cjs +17 -25
  228. package/dist/rules/requirePropertyType.cjs.map +1 -1
  229. package/dist/rules/requirePropertyType.js +21 -0
  230. package/dist/rules/requirePropertyType.js.map +1 -0
  231. package/dist/rules/requireReturns.cjs +125 -203
  232. package/dist/rules/requireReturns.cjs.map +1 -1
  233. package/dist/rules/requireReturns.js +131 -0
  234. package/dist/rules/requireReturns.js.map +1 -0
  235. package/dist/rules/requireReturnsCheck.cjs +60 -103
  236. package/dist/rules/requireReturnsCheck.cjs.map +1 -1
  237. package/dist/rules/requireReturnsCheck.js +66 -0
  238. package/dist/rules/requireReturnsCheck.js.map +1 -0
  239. package/dist/rules/requireReturnsDescription.cjs +39 -54
  240. package/dist/rules/requireReturnsDescription.cjs.map +1 -1
  241. package/dist/rules/requireReturnsDescription.js +43 -0
  242. package/dist/rules/requireReturnsDescription.js.map +1 -0
  243. package/dist/rules/requireReturnsType.cjs +32 -50
  244. package/dist/rules/requireReturnsType.cjs.map +1 -1
  245. package/dist/rules/requireReturnsType.js +36 -0
  246. package/dist/rules/requireReturnsType.js.map +1 -0
  247. package/dist/rules/requireTemplate.cjs +119 -178
  248. package/dist/rules/requireTemplate.cjs.map +1 -1
  249. package/dist/rules/requireTemplate.js +122 -0
  250. package/dist/rules/requireTemplate.js.map +1 -0
  251. package/dist/rules/requireThrows.cjs +61 -95
  252. package/dist/rules/requireThrows.cjs.map +1 -1
  253. package/dist/rules/requireThrows.js +67 -0
  254. package/dist/rules/requireThrows.js.map +1 -0
  255. package/dist/rules/requireYields.cjs +106 -166
  256. package/dist/rules/requireYields.cjs.map +1 -1
  257. package/dist/rules/requireYields.js +115 -0
  258. package/dist/rules/requireYields.js.map +1 -0
  259. package/dist/rules/requireYieldsCheck.cjs +96 -152
  260. package/dist/rules/requireYieldsCheck.cjs.map +1 -1
  261. package/dist/rules/requireYieldsCheck.js +105 -0
  262. package/dist/rules/requireYieldsCheck.js.map +1 -0
  263. package/dist/rules/sortTags.cjs +258 -444
  264. package/dist/rules/sortTags.cjs.map +1 -1
  265. package/dist/rules/sortTags.js +262 -0
  266. package/dist/rules/sortTags.js.map +1 -0
  267. package/dist/rules/tagLines.cjs +179 -266
  268. package/dist/rules/tagLines.cjs.map +1 -1
  269. package/dist/rules/tagLines.js +183 -0
  270. package/dist/rules/tagLines.js.map +1 -0
  271. package/dist/rules/textEscaping.cjs +92 -127
  272. package/dist/rules/textEscaping.cjs.map +1 -1
  273. package/dist/rules/textEscaping.js +102 -0
  274. package/dist/rules/textEscaping.js.map +1 -0
  275. package/dist/rules/validTypes.cjs +252 -265
  276. package/dist/rules/validTypes.cjs.map +1 -1
  277. package/dist/rules/validTypes.js +259 -0
  278. package/dist/rules/validTypes.js.map +1 -0
  279. package/dist/tagNames.cjs +134 -170
  280. package/dist/tagNames.cjs.map +1 -1
  281. package/dist/tagNames.js +144 -0
  282. package/dist/tagNames.js.map +1 -0
  283. package/dist/utils/hasReturnValue.cjs +246 -474
  284. package/dist/utils/hasReturnValue.cjs.map +1 -1
  285. package/dist/utils/hasReturnValue.js +265 -0
  286. package/dist/utils/hasReturnValue.js.map +1 -0
  287. package/package.json +48 -38
  288. package/dist/generateRule.cjs +0 -242
  289. package/dist/generateRule.cjs.map +0 -1
  290. package/src/WarnSettings.js +0 -34
  291. package/src/alignTransform.js +0 -358
  292. package/src/defaultTagOrder.js +0 -169
  293. package/src/exportParser.js +0 -978
  294. package/src/getDefaultTagStructureForMode.js +0 -969
  295. package/src/getJsdocProcessorPlugin.js +0 -652
  296. package/src/index.js +0 -530
  297. package/src/iterateJsdoc.js +0 -2518
  298. package/src/jsdocUtils.js +0 -1896
  299. package/src/rules/checkAccess.js +0 -45
  300. package/src/rules/checkAlignment.js +0 -63
  301. package/src/rules/checkExamples.js +0 -589
  302. package/src/rules/checkIndentation.js +0 -75
  303. package/src/rules/checkLineAlignment.js +0 -372
  304. package/src/rules/checkParamNames.js +0 -474
  305. package/src/rules/checkPropertyNames.js +0 -152
  306. package/src/rules/checkSyntax.js +0 -30
  307. package/src/rules/checkTagNames.js +0 -314
  308. package/src/rules/checkTemplateNames.js +0 -204
  309. package/src/rules/checkTypes.js +0 -535
  310. package/src/rules/checkValues.js +0 -248
  311. package/src/rules/convertToJsdocComments.js +0 -398
  312. package/src/rules/emptyTags.js +0 -98
  313. package/src/rules/implementsOnClasses.js +0 -64
  314. package/src/rules/importsAsDependencies.js +0 -133
  315. package/src/rules/informativeDocs.js +0 -189
  316. package/src/rules/linesBeforeBlock.js +0 -134
  317. package/src/rules/matchDescription.js +0 -286
  318. package/src/rules/matchName.js +0 -151
  319. package/src/rules/multilineBlocks.js +0 -493
  320. package/src/rules/noBadBlocks.js +0 -119
  321. package/src/rules/noBlankBlockDescriptions.js +0 -69
  322. package/src/rules/noBlankBlocks.js +0 -53
  323. package/src/rules/noDefaults.js +0 -85
  324. package/src/rules/noMissingSyntax.js +0 -195
  325. package/src/rules/noMultiAsterisks.js +0 -134
  326. package/src/rules/noRestrictedSyntax.js +0 -91
  327. package/src/rules/noTypes.js +0 -93
  328. package/src/rules/noUndefinedTypes.js +0 -543
  329. package/src/rules/requireAsteriskPrefix.js +0 -190
  330. package/src/rules/requireDescription.js +0 -161
  331. package/src/rules/requireDescriptionCompleteSentence.js +0 -335
  332. package/src/rules/requireExample.js +0 -118
  333. package/src/rules/requireFileOverview.js +0 -154
  334. package/src/rules/requireHyphenBeforeParamDescription.js +0 -176
  335. package/src/rules/requireJsdoc.js +0 -743
  336. package/src/rules/requireParam.js +0 -602
  337. package/src/rules/requireParamDescription.js +0 -89
  338. package/src/rules/requireParamName.js +0 -55
  339. package/src/rules/requireParamType.js +0 -89
  340. package/src/rules/requireProperty.js +0 -48
  341. package/src/rules/requirePropertyDescription.js +0 -25
  342. package/src/rules/requirePropertyName.js +0 -25
  343. package/src/rules/requirePropertyType.js +0 -25
  344. package/src/rules/requireReturns.js +0 -238
  345. package/src/rules/requireReturnsCheck.js +0 -145
  346. package/src/rules/requireReturnsDescription.js +0 -59
  347. package/src/rules/requireReturnsType.js +0 -51
  348. package/src/rules/requireTemplate.js +0 -201
  349. package/src/rules/requireThrows.js +0 -111
  350. package/src/rules/requireYields.js +0 -216
  351. package/src/rules/requireYieldsCheck.js +0 -208
  352. package/src/rules/sortTags.js +0 -558
  353. package/src/rules/tagLines.js +0 -359
  354. package/src/rules/textEscaping.js +0 -154
  355. package/src/rules/validTypes.js +0 -401
  356. package/src/tagNames.js +0 -238
  357. package/src/utils/hasReturnValue.js +0 -572
@@ -1,2518 +0,0 @@
1
- import * as jsdocUtils from './jsdocUtils.js';
2
- import {
3
- commentHandler,
4
- getJSDocComment,
5
- parseComment,
6
- } from '@es-joy/jsdoccomment';
7
- import {
8
- stringify as commentStringify,
9
- util,
10
- } from 'comment-parser';
11
- import esquery from 'esquery';
12
-
13
- /**
14
- * @typedef {number} Integer
15
- */
16
-
17
- /**
18
- * @typedef {import('@es-joy/jsdoccomment').JsdocBlockWithInline} JsdocBlockWithInline
19
- */
20
-
21
- /**
22
- * @typedef {{
23
- * disallowName?: string,
24
- * allowName?: string,
25
- * context?: string,
26
- * comment?: string,
27
- * tags?: string[],
28
- * replacement?: string,
29
- * minimum?: Integer,
30
- * message?: string,
31
- * forceRequireReturn?: boolean
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
- * comment?: string
45
- * }} info
46
- * @param {null|((jsdoc: import('@es-joy/jsdoccomment').JsdocBlockWithInline) => boolean|undefined)} handler
47
- * @param {import('eslint').Rule.Node} node
48
- * @returns {void}
49
- */
50
-
51
- /**
52
- * @callback ForEachPreferredTag
53
- * @param {string} tagName
54
- * @param {(
55
- * matchingJsdocTag: import('@es-joy/jsdoccomment').JsdocTagWithInline,
56
- * targetTagName: string
57
- * ) => void} arrayHandler
58
- * @param {boolean} [skipReportingBlockedTag]
59
- * @returns {void}
60
- */
61
-
62
- /**
63
- * @callback ReportSettings
64
- * @param {string} message
65
- * @returns {void}
66
- */
67
-
68
- /**
69
- * @callback ParseClosureTemplateTag
70
- * @param {import('comment-parser').Spec} tag
71
- * @returns {string[]}
72
- */
73
-
74
- /**
75
- * @callback GetPreferredTagNameObject
76
- * @param {{
77
- * tagName: string
78
- * }} cfg
79
- * @returns {string|false|{
80
- * message: string;
81
- * replacement?: string|undefined
82
- * }|{
83
- * blocked: true,
84
- * tagName: string
85
- * }}
86
- */
87
-
88
- /**
89
- * @typedef {{
90
- * forEachPreferredTag: ForEachPreferredTag,
91
- * reportSettings: ReportSettings,
92
- * parseClosureTemplateTag: ParseClosureTemplateTag,
93
- * getPreferredTagNameObject: GetPreferredTagNameObject,
94
- * pathDoesNotBeginWith: import('./jsdocUtils.js').PathDoesNotBeginWith
95
- * }} BasicUtils
96
- */
97
-
98
- /**
99
- * @callback IsIteratingFunction
100
- * @returns {boolean}
101
- */
102
-
103
- /**
104
- * @callback IsVirtualFunction
105
- * @returns {boolean}
106
- */
107
-
108
- /**
109
- * @callback Stringify
110
- * @param {import('comment-parser').Block} tagBlock
111
- * @param {boolean} [specRewire]
112
- * @returns {string}
113
- */
114
-
115
- /**
116
- * @callback ReportJSDoc
117
- * @param {string} msg
118
- * @param {null|import('comment-parser').Spec|{line: Integer, column?: Integer}} [tag]
119
- * @param {(() => void)|null} [handler]
120
- * @param {boolean} [specRewire]
121
- * @param {undefined|{
122
- * [key: string]: string
123
- * }} [data]
124
- */
125
-
126
- /**
127
- * @callback GetRegexFromString
128
- * @param {string} str
129
- * @param {string} [requiredFlags]
130
- * @returns {RegExp}
131
- */
132
-
133
- /**
134
- * @callback GetTagDescription
135
- * @param {import('comment-parser').Spec} tg
136
- * @param {boolean} [returnArray]
137
- * @returns {string[]|string}
138
- */
139
-
140
- /**
141
- * @callback SetTagDescription
142
- * @param {import('comment-parser').Spec} tg
143
- * @param {RegExp} matcher
144
- * @param {(description: string) => string} setter
145
- * @returns {Integer}
146
- */
147
-
148
- /**
149
- * @callback GetDescription
150
- * @returns {{
151
- * description: string,
152
- * descriptions: string[],
153
- * lastDescriptionLine: Integer
154
- * }}
155
- */
156
-
157
- /**
158
- * @callback SetBlockDescription
159
- * @param {(
160
- * info: {
161
- * delimiter: string,
162
- * postDelimiter: string,
163
- * start: string
164
- * },
165
- * seedTokens: (
166
- * tokens?: Partial<import('comment-parser').Tokens>
167
- * ) => import('comment-parser').Tokens,
168
- * descLines: string[]
169
- * ) => import('comment-parser').Line[]} setter
170
- * @returns {void}
171
- */
172
-
173
- /**
174
- * @callback SetDescriptionLines
175
- * @param {RegExp} matcher
176
- * @param {(description: string) => string} setter
177
- * @returns {Integer}
178
- */
179
-
180
- /**
181
- * @callback ChangeTag
182
- * @param {import('comment-parser').Spec} tag
183
- * @param {...Partial<import('comment-parser').Tokens>} tokens
184
- * @returns {void}
185
- */
186
-
187
- /**
188
- * @callback SetTag
189
- * @param {import('comment-parser').Spec & {
190
- * line: Integer
191
- * }} tag
192
- * @param {Partial<import('comment-parser').Tokens>} [tokens]
193
- * @returns {void}
194
- */
195
-
196
- /**
197
- * @callback RemoveTag
198
- * @param {Integer} tagIndex
199
- * @param {{
200
- * removeEmptyBlock?: boolean,
201
- * tagSourceOffset?: Integer
202
- * }} [cfg]
203
- * @returns {void}
204
- */
205
-
206
- /**
207
- * @callback AddTag
208
- * @param {string} targetTagName
209
- * @param {Integer} [number]
210
- * @param {import('comment-parser').Tokens|{}} [tokens]
211
- * @returns {void}
212
- */
213
-
214
- /**
215
- * @callback GetFirstLine
216
- * @returns {Integer|undefined}
217
- */
218
-
219
- /**
220
- * @typedef {(
221
- * tokens?: Partial<import('comment-parser').Tokens> | undefined
222
- * ) => import('comment-parser').Tokens} SeedTokens
223
- */
224
-
225
- /**
226
- * Sets tokens to empty string.
227
- * @callback EmptyTokens
228
- * @param {import('comment-parser').Tokens} tokens
229
- * @returns {void}
230
- */
231
-
232
- /**
233
- * @callback AddLine
234
- * @param {Integer} sourceIndex
235
- * @param {Partial<import('comment-parser').Tokens>} tokens
236
- * @returns {void}
237
- */
238
-
239
- /**
240
- * @callback AddLines
241
- * @param {Integer} tagIndex
242
- * @param {Integer} tagSourceOffset
243
- * @param {Integer} numLines
244
- * @returns {void}
245
- */
246
-
247
- /**
248
- * @callback MakeMultiline
249
- * @returns {void}
250
- */
251
-
252
- /**
253
- * @callback GetFunctionParameterNames
254
- * @param {boolean} [useDefaultObjectProperties]
255
- * @returns {import('./jsdocUtils.js').ParamNameInfo[]}
256
- */
257
-
258
- /**
259
- * @callback HasParams
260
- * @returns {Integer}
261
- */
262
-
263
- /**
264
- * @callback IsGenerator
265
- * @returns {boolean}
266
- */
267
-
268
- /**
269
- * @callback IsConstructor
270
- * @returns {boolean}
271
- */
272
-
273
- /**
274
- * @callback GetJsdocTagsDeep
275
- * @param {string} tagName
276
- * @returns {false|{
277
- * idx: Integer,
278
- * name: string,
279
- * type: string
280
- * }[]}
281
- */
282
-
283
- /**
284
- * @callback GetPreferredTagName
285
- * @param {{
286
- * tagName: string,
287
- * skipReportingBlockedTag?: boolean,
288
- * allowObjectReturn?: boolean,
289
- * defaultMessage?: string
290
- * }} cfg
291
- * @returns {string|undefined|false|{
292
- * message: string;
293
- * replacement?: string|undefined;
294
- * }|{
295
- * blocked: true,
296
- * tagName: string
297
- * }}
298
- */
299
-
300
- /**
301
- * @callback IsValidTag
302
- * @param {string} name
303
- * @param {string[]} definedTags
304
- * @returns {boolean}
305
- */
306
-
307
- /**
308
- * @callback HasATag
309
- * @param {string[]} names
310
- * @returns {boolean}
311
- */
312
-
313
- /**
314
- * @callback HasTag
315
- * @param {string} name
316
- * @returns {boolean}
317
- */
318
-
319
- /**
320
- * @callback ComparePaths
321
- * @param {string} name
322
- * @returns {(otherPathName: string) => boolean}
323
- */
324
-
325
- /**
326
- * @callback DropPathSegmentQuotes
327
- * @param {string} name
328
- * @returns {string}
329
- */
330
-
331
- /**
332
- * @callback AvoidDocs
333
- * @returns {boolean}
334
- */
335
-
336
- /**
337
- * @callback TagMightHaveNamePositionTypePosition
338
- * @param {string} tagName
339
- * @param {import('./getDefaultTagStructureForMode.js').
340
- * TagStructure[]} [otherModeMaps]
341
- * @returns {boolean|{otherMode: true}}
342
- */
343
-
344
- /**
345
- * @callback TagMustHave
346
- * @param {string} tagName
347
- * @param {import('./getDefaultTagStructureForMode.js').
348
- * TagStructure[]} otherModeMaps
349
- * @returns {boolean|{
350
- * otherMode: false
351
- * }}
352
- */
353
-
354
- /**
355
- * @callback TagMissingRequiredTypeOrNamepath
356
- * @param {import('comment-parser').Spec} tag
357
- * @param {import('./getDefaultTagStructureForMode.js').
358
- * TagStructure[]} otherModeMaps
359
- * @returns {boolean|{
360
- * otherMode: false
361
- * }}
362
- */
363
-
364
- /**
365
- * @callback IsNamepathX
366
- * @param {string} tagName
367
- * @returns {boolean}
368
- */
369
-
370
- /**
371
- * @callback GetTagStructureForMode
372
- * @param {import('./jsdocUtils.js').ParserMode} mde
373
- * @returns {import('./getDefaultTagStructureForMode.js').TagStructure}
374
- */
375
-
376
- /**
377
- * @callback MayBeUndefinedTypeTag
378
- * @param {import('comment-parser').Spec} tag
379
- * @returns {boolean}
380
- */
381
-
382
- /**
383
- * @callback HasValueOrExecutorHasNonEmptyResolveValue
384
- * @param {boolean} anyPromiseAsReturn
385
- * @param {boolean} [allBranches]
386
- * @returns {boolean}
387
- */
388
-
389
- /**
390
- * @callback HasYieldValue
391
- * @returns {boolean}
392
- */
393
-
394
- /**
395
- * @callback HasYieldReturnValue
396
- * @returns {boolean}
397
- */
398
-
399
- /**
400
- * @callback HasThrowValue
401
- * @returns {boolean}
402
- */
403
-
404
- /**
405
- * @callback IsAsync
406
- * @returns {boolean|undefined}
407
- */
408
-
409
- /**
410
- * @callback GetTags
411
- * @param {string} tagName
412
- * @returns {import('comment-parser').Spec[]}
413
- */
414
-
415
- /**
416
- * @callback GetPresentTags
417
- * @param {string[]} tagList
418
- * @returns {import('@es-joy/jsdoccomment').JsdocTagWithInline[]}
419
- */
420
-
421
- /**
422
- * @callback FilterTags
423
- * @param {(tag: import('@es-joy/jsdoccomment').JsdocTagWithInline) => boolean} filter
424
- * @returns {import('@es-joy/jsdoccomment').JsdocTagWithInline[]}
425
- */
426
-
427
- /**
428
- * @callback FilterAllTags
429
- * @param {(tag: (import('comment-parser').Spec|
430
- * import('@es-joy/jsdoccomment').JsdocInlineTagNoType)) => boolean} filter
431
- * @returns {(import('comment-parser').Spec|
432
- * import('@es-joy/jsdoccomment').JsdocInlineTagNoType)[]}
433
- */
434
-
435
- /**
436
- * @callback GetTagsByType
437
- * @param {import('comment-parser').Spec[]} tags
438
- * @returns {{
439
- * tagsWithNames: import('comment-parser').Spec[],
440
- * tagsWithoutNames: import('comment-parser').Spec[]
441
- * }}
442
- */
443
-
444
- /**
445
- * @callback HasOptionTag
446
- * @param {string} tagName
447
- * @returns {boolean}
448
- */
449
-
450
- /**
451
- * @callback GetClassNode
452
- * @returns {Node|null}
453
- */
454
-
455
- /**
456
- * @callback GetClassJsdoc
457
- * @returns {null|JsdocBlockWithInline}
458
- */
459
-
460
- /**
461
- * @callback ClassHasTag
462
- * @param {string} tagName
463
- * @returns {boolean}
464
- */
465
-
466
- /**
467
- * @callback FindContext
468
- * @param {Context[]} contexts
469
- * @param {string|undefined} comment
470
- * @returns {{
471
- * foundContext: Context|undefined,
472
- * contextStr: string
473
- * }}
474
- */
475
-
476
- /**
477
- * @typedef {BasicUtils & {
478
- * isIteratingFunction: IsIteratingFunction,
479
- * isVirtualFunction: IsVirtualFunction,
480
- * stringify: Stringify,
481
- * reportJSDoc: ReportJSDoc,
482
- * getRegexFromString: GetRegexFromString,
483
- * getTagDescription: GetTagDescription,
484
- * setTagDescription: SetTagDescription,
485
- * getDescription: GetDescription,
486
- * setBlockDescription: SetBlockDescription,
487
- * setDescriptionLines: SetDescriptionLines,
488
- * changeTag: ChangeTag,
489
- * setTag: SetTag,
490
- * removeTag: RemoveTag,
491
- * addTag: AddTag,
492
- * getFirstLine: GetFirstLine,
493
- * seedTokens: SeedTokens,
494
- * emptyTokens: EmptyTokens,
495
- * addLine: AddLine,
496
- * addLines: AddLines,
497
- * makeMultiline: MakeMultiline,
498
- * flattenRoots: import('./jsdocUtils.js').FlattenRoots,
499
- * getFunctionParameterNames: GetFunctionParameterNames,
500
- * hasParams: HasParams,
501
- * isGenerator: IsGenerator,
502
- * isConstructor: IsConstructor,
503
- * getJsdocTagsDeep: GetJsdocTagsDeep,
504
- * getPreferredTagName: GetPreferredTagName,
505
- * isValidTag: IsValidTag,
506
- * hasATag: HasATag,
507
- * hasTag: HasTag,
508
- * comparePaths: ComparePaths,
509
- * dropPathSegmentQuotes: DropPathSegmentQuotes,
510
- * avoidDocs: AvoidDocs,
511
- * tagMightHaveNamePosition: TagMightHaveNamePositionTypePosition,
512
- * tagMightHaveTypePosition: TagMightHaveNamePositionTypePosition,
513
- * tagMustHaveNamePosition: TagMustHave,
514
- * tagMustHaveTypePosition: TagMustHave,
515
- * tagMissingRequiredTypeOrNamepath: TagMissingRequiredTypeOrNamepath,
516
- * isNamepathDefiningTag: IsNamepathX,
517
- * isNamepathReferencingTag: IsNamepathX,
518
- * isNamepathOrUrlReferencingTag: IsNamepathX,
519
- * tagMightHaveNamepath: IsNamepathX,
520
- * getTagStructureForMode: GetTagStructureForMode,
521
- * mayBeUndefinedTypeTag: MayBeUndefinedTypeTag,
522
- * hasValueOrExecutorHasNonEmptyResolveValue: HasValueOrExecutorHasNonEmptyResolveValue,
523
- * hasYieldValue: HasYieldValue,
524
- * hasYieldReturnValue: HasYieldReturnValue,
525
- * hasThrowValue: HasThrowValue,
526
- * isAsync: IsAsync,
527
- * getTags: GetTags,
528
- * getPresentTags: GetPresentTags,
529
- * filterTags: FilterTags,
530
- * filterAllTags: FilterAllTags,
531
- * getTagsByType: GetTagsByType,
532
- * hasOptionTag: HasOptionTag,
533
- * getClassNode: GetClassNode,
534
- * getClassJsdoc: GetClassJsdoc,
535
- * classHasTag: ClassHasTag,
536
- * findContext: FindContext
537
- * }} Utils
538
- */
539
-
540
- const {
541
- rewireSpecs,
542
- seedTokens,
543
- } = util;
544
-
545
- // todo: Change these `any` types once importing types properly.
546
-
547
- /**
548
- * Should use ESLint rule's typing.
549
- * @typedef {import('eslint').Rule.RuleMetaData} EslintRuleMeta
550
- */
551
-
552
- /**
553
- * A plain object for tracking state as needed by rules across iterations.
554
- * @typedef {{
555
- * globalTags: {},
556
- * hasDuplicates: {
557
- * [key: string]: boolean
558
- * },
559
- * selectorMap: {
560
- * [selector: string]: {
561
- * [comment: string]: Integer
562
- * }
563
- * },
564
- * hasTag: {
565
- * [key: string]: boolean
566
- * },
567
- * hasNonComment: number,
568
- * hasNonCommentBeforeTag: {
569
- * [key: string]: boolean|number
570
- * }
571
- * }} StateObject
572
- */
573
-
574
- /**
575
- * The Node AST as supplied by the parser.
576
- * @typedef {import('eslint').Rule.Node} Node
577
- */
578
-
579
- /*
580
- const {
581
- align as commentAlign,
582
- flow: commentFlow,
583
- indent: commentIndent,
584
- } = transforms;
585
- */
586
-
587
- const globalState = new Map();
588
- /**
589
- * @param {import('eslint').Rule.RuleContext} context
590
- * @param {{
591
- * tagNamePreference?: import('./jsdocUtils.js').TagNamePreference,
592
- * mode?: import('./jsdocUtils.js').ParserMode
593
- * }} cfg
594
- * @returns {BasicUtils}
595
- */
596
- const getBasicUtils = (context, {
597
- mode,
598
- tagNamePreference,
599
- }) => {
600
- /** @type {BasicUtils} */
601
- const utils = {};
602
-
603
- /** @type {ReportSettings} */
604
- utils.reportSettings = (message) => {
605
- context.report({
606
- loc: {
607
- end: {
608
- column: 1,
609
- line: 1,
610
- },
611
- start: {
612
- column: 1,
613
- line: 1,
614
- },
615
- },
616
- message,
617
- });
618
- };
619
-
620
- /** @type {ParseClosureTemplateTag} */
621
- utils.parseClosureTemplateTag = (tag) => {
622
- return jsdocUtils.parseClosureTemplateTag(tag);
623
- };
624
-
625
- utils.pathDoesNotBeginWith = jsdocUtils.pathDoesNotBeginWith;
626
-
627
- /** @type {GetPreferredTagNameObject} */
628
- utils.getPreferredTagNameObject = ({
629
- tagName,
630
- }) => {
631
- const ret = jsdocUtils.getPreferredTagNameSimple(
632
- tagName,
633
- /** @type {import('./jsdocUtils.js').ParserMode} */ (mode),
634
- tagNamePreference,
635
- context,
636
- );
637
- const isObject = ret && typeof ret === 'object';
638
- if (ret === false || (isObject && !ret.replacement)) {
639
- return {
640
- blocked: true,
641
- tagName,
642
- };
643
- }
644
-
645
- return ret;
646
- };
647
-
648
- return utils;
649
- };
650
-
651
- /**
652
- * @callback Report
653
- * @param {string} message
654
- * @param {import('eslint').Rule.ReportFixer|null} [fix]
655
- * @param {null|
656
- * {line?: Integer, column?: Integer}|
657
- * import('comment-parser').Spec & {line?: Integer}
658
- * } [jsdocLoc]
659
- * @param {undefined|{
660
- * [key: string]: string
661
- * }} [data]
662
- * @returns {void}
663
- */
664
-
665
- /**
666
- * @param {Node|null} node
667
- * @param {JsdocBlockWithInline} jsdoc
668
- * @param {import('eslint').AST.Token} jsdocNode
669
- * @param {Settings} settings
670
- * @param {Report} report
671
- * @param {import('eslint').Rule.RuleContext} context
672
- * @param {import('eslint').SourceCode} sc
673
- * @param {boolean|undefined} iteratingAll
674
- * @param {RuleConfig} ruleConfig
675
- * @param {string} indent
676
- * @returns {Utils}
677
- */
678
- const getUtils = (
679
- node,
680
- jsdoc,
681
- jsdocNode,
682
- settings,
683
- report,
684
- context,
685
- sc,
686
- iteratingAll,
687
- ruleConfig,
688
- indent,
689
- ) => {
690
- const ancestors = /** @type {import('eslint').Rule.Node[]} */ (node ?
691
- (sc.getAncestors ?
692
- (
693
- sc.getAncestors(node)
694
- /* c8 ignore next 4 */
695
- ) :
696
- (
697
- context.getAncestors()
698
- )) :
699
- []);
700
-
701
- /* c8 ignore next -- Fallback to deprecated method */
702
- const {
703
- sourceCode = context.getSourceCode(),
704
- } = context;
705
-
706
- const utils = /** @type {Utils} */ (getBasicUtils(context, settings));
707
-
708
- const {
709
- augmentsExtendsReplacesDocs,
710
- ignoreReplacesDocs,
711
- implementsReplacesDocs,
712
- maxLines,
713
- minLines,
714
- mode,
715
- overrideReplacesDocs,
716
- tagNamePreference,
717
- } = settings;
718
-
719
- /** @type {IsIteratingFunction} */
720
- utils.isIteratingFunction = () => {
721
- return !iteratingAll || [
722
- 'ArrowFunctionExpression',
723
- 'FunctionDeclaration',
724
- 'FunctionExpression',
725
- 'MethodDefinition',
726
- ].includes(String(node && node.type));
727
- };
728
-
729
- /** @type {IsVirtualFunction} */
730
- utils.isVirtualFunction = () => {
731
- return Boolean(iteratingAll) && utils.hasATag([
732
- 'callback', 'function', 'func', 'method',
733
- ]);
734
- };
735
-
736
- /** @type {Stringify} */
737
- utils.stringify = (tagBlock, specRewire) => {
738
- let block;
739
- if (specRewire) {
740
- block = rewireSpecs(tagBlock);
741
- }
742
-
743
- return commentStringify(/** @type {import('comment-parser').Block} */ (
744
- specRewire ? block : tagBlock));
745
- };
746
-
747
- /** @type {ReportJSDoc} */
748
- utils.reportJSDoc = (msg, tag, handler, specRewire, data) => {
749
- report(msg, handler ? /** @type {import('eslint').Rule.ReportFixer} */ (
750
- fixer,
751
- ) => {
752
- handler();
753
- const replacement = utils.stringify(jsdoc, specRewire);
754
-
755
- if (!replacement) {
756
- const text = sourceCode.getText();
757
- const lastLineBreakPos = text.slice(
758
- 0, jsdocNode.range[0],
759
- ).search(/\n[ \t]*$/v);
760
- if (lastLineBreakPos > -1) {
761
- return fixer.removeRange([
762
- lastLineBreakPos, jsdocNode.range[1],
763
- ]);
764
- }
765
-
766
- return fixer.removeRange(
767
- (/\s/v).test(text.charAt(jsdocNode.range[1])) ?
768
- [
769
- jsdocNode.range[0], jsdocNode.range[1] + 1,
770
- ] :
771
- jsdocNode.range,
772
- );
773
- }
774
-
775
- return fixer.replaceText(jsdocNode, replacement);
776
- } : null, tag, data);
777
- };
778
-
779
- /** @type {GetRegexFromString} */
780
- utils.getRegexFromString = (str, requiredFlags) => {
781
- return jsdocUtils.getRegexFromString(str, requiredFlags);
782
- };
783
-
784
- /** @type {GetTagDescription} */
785
- utils.getTagDescription = (tg, returnArray) => {
786
- return jsdocUtils.getTagDescription(tg, returnArray);
787
- };
788
-
789
- /** @type {SetTagDescription} */
790
- utils.setTagDescription = (tg, matcher, setter) => {
791
- let finalIdx = 0;
792
- tg.source.some(({
793
- tokens: {
794
- description,
795
- },
796
- }, idx) => {
797
- if (description && matcher.test(description)) {
798
- tg.source[idx].tokens.description = setter(description);
799
- finalIdx = idx;
800
- return true;
801
- }
802
-
803
- return false;
804
- });
805
-
806
- return finalIdx;
807
- };
808
-
809
- /** @type {GetDescription} */
810
- utils.getDescription = () => {
811
- /** @type {string[]} */
812
- const descriptions = [];
813
- let lastDescriptionLine = 0;
814
- let tagsBegun = false;
815
- jsdoc.source.some(({
816
- tokens: {
817
- description,
818
- end,
819
- tag,
820
- },
821
- }, idx) => {
822
- if (tag) {
823
- tagsBegun = true;
824
- }
825
-
826
- if (idx && (tag || end)) {
827
- lastDescriptionLine = idx - 1;
828
- if (!tagsBegun && description) {
829
- descriptions.push(description);
830
- }
831
-
832
- return true;
833
- }
834
-
835
- if (!tagsBegun && (idx || description)) {
836
- descriptions.push(description || (descriptions.length ? '' : '\n'));
837
- }
838
-
839
- return false;
840
- });
841
-
842
- return {
843
- description: descriptions.join('\n'),
844
- descriptions,
845
- lastDescriptionLine,
846
- };
847
- };
848
-
849
- /** @type {SetBlockDescription} */
850
- utils.setBlockDescription = (setter) => {
851
- /** @type {string[]} */
852
- const descLines = [];
853
- /**
854
- * @type {undefined|Integer}
855
- */
856
- let startIdx;
857
- /**
858
- * @type {undefined|Integer}
859
- */
860
- let endIdx;
861
-
862
- /**
863
- * @type {undefined|{
864
- * delimiter: string,
865
- * postDelimiter: string,
866
- * start: string
867
- * }}
868
- */
869
- let info;
870
-
871
- jsdoc.source.some(({
872
- tokens: {
873
- delimiter,
874
- description,
875
- end,
876
- postDelimiter,
877
- start,
878
- tag,
879
- },
880
- }, idx) => {
881
- if (delimiter === '/**') {
882
- return false;
883
- }
884
-
885
- if (startIdx === undefined) {
886
- startIdx = idx;
887
- info = {
888
- delimiter,
889
- postDelimiter,
890
- start,
891
- };
892
- }
893
-
894
- if (tag || end) {
895
- endIdx = idx;
896
- return true;
897
- }
898
-
899
- descLines.push(description);
900
- return false;
901
- });
902
-
903
- /* c8 ignore else -- Won't be called if missing */
904
- if (descLines.length) {
905
- jsdoc.source.splice(
906
- /** @type {Integer} */ (startIdx),
907
- /** @type {Integer} */ (endIdx) - /** @type {Integer} */ (startIdx),
908
- ...setter(
909
- /**
910
- * @type {{
911
- * delimiter: string,
912
- * postDelimiter: string,
913
- * start: string
914
- * }}
915
- */
916
- (info),
917
- seedTokens,
918
- descLines,
919
- ),
920
- );
921
- }
922
- };
923
-
924
- /** @type {SetDescriptionLines} */
925
- utils.setDescriptionLines = (matcher, setter) => {
926
- let finalIdx = 0;
927
- jsdoc.source.some(({
928
- tokens: {
929
- description,
930
- end,
931
- tag,
932
- },
933
- }, idx) => {
934
- /* c8 ignore next 3 -- Already checked */
935
- if (idx && (tag || end)) {
936
- return true;
937
- }
938
-
939
- if (description && matcher.test(description)) {
940
- jsdoc.source[idx].tokens.description = setter(description);
941
- finalIdx = idx;
942
- return true;
943
- }
944
-
945
- return false;
946
- });
947
-
948
- return finalIdx;
949
- };
950
-
951
- /** @type {ChangeTag} */
952
- utils.changeTag = (tag, ...tokens) => {
953
- for (const [
954
- idx,
955
- src,
956
- ] of tag.source.entries()) {
957
- src.tokens = {
958
- ...src.tokens,
959
- ...tokens[idx],
960
- };
961
- }
962
- };
963
-
964
- /** @type {SetTag} */
965
- utils.setTag = (tag, tokens) => {
966
- tag.source = [
967
- {
968
- number: tag.line,
969
- // Or tag.source[0].number?
970
- source: '',
971
- tokens: seedTokens({
972
- delimiter: '*',
973
- postDelimiter: ' ',
974
- start: indent + ' ',
975
- tag: '@' + tag.tag,
976
- ...tokens,
977
- }),
978
- },
979
- ];
980
- };
981
-
982
- /** @type {RemoveTag} */
983
- utils.removeTag = (tagIndex, {
984
- removeEmptyBlock = false,
985
- tagSourceOffset = 0,
986
- } = {}) => {
987
- const {
988
- source: tagSource,
989
- } = jsdoc.tags[tagIndex];
990
- /** @type {Integer|undefined} */
991
- let lastIndex;
992
- const firstNumber = jsdoc.source[0].number;
993
- tagSource.some(({
994
- number,
995
- }, tagIdx) => {
996
- const sourceIndex = jsdoc.source.findIndex(({
997
- number: srcNumber,
998
- }) => {
999
- return number === srcNumber;
1000
- });
1001
- // c8 ignore else
1002
- if (sourceIndex > -1) {
1003
- let spliceCount = 1;
1004
- tagSource.slice(tagIdx + 1).some(({
1005
- tokens: {
1006
- end: ending,
1007
- tag,
1008
- },
1009
- }) => {
1010
- if (!tag && !ending) {
1011
- spliceCount++;
1012
-
1013
- return false;
1014
- }
1015
-
1016
- return true;
1017
- });
1018
-
1019
- const spliceIdx = sourceIndex + tagSourceOffset;
1020
-
1021
- const {
1022
- delimiter,
1023
- end,
1024
- } = jsdoc.source[spliceIdx].tokens;
1025
-
1026
- if (
1027
- spliceIdx === 0 && jsdoc.tags.length >= 2 ||
1028
- !removeEmptyBlock && (end || delimiter === '/**')
1029
- ) {
1030
- const {
1031
- tokens,
1032
- } = jsdoc.source[spliceIdx];
1033
- for (const item of [
1034
- 'postDelimiter',
1035
- 'tag',
1036
- 'postTag',
1037
- 'type',
1038
- 'postType',
1039
- 'name',
1040
- 'postName',
1041
- 'description',
1042
- ]) {
1043
- tokens[
1044
- /**
1045
- * @type {"postDelimiter"|"tag"|"type"|"postType"|
1046
- * "postTag"|"name"|"postName"|"description"}
1047
- */ (
1048
- item
1049
- )
1050
- ] = '';
1051
- }
1052
- } else {
1053
- jsdoc.source.splice(spliceIdx, spliceCount - tagSourceOffset + (spliceIdx ? 0 : jsdoc.source.length));
1054
- tagSource.splice(tagIdx + tagSourceOffset, spliceCount - tagSourceOffset + (spliceIdx ? 0 : jsdoc.source.length));
1055
- }
1056
-
1057
- lastIndex = sourceIndex;
1058
-
1059
- return true;
1060
- }
1061
- /* c8 ignore next 2 */
1062
- // eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
1063
- return false;
1064
- });
1065
- for (const [
1066
- idx,
1067
- src,
1068
- ] of jsdoc.source.slice(lastIndex).entries()) {
1069
- src.number = firstNumber + /** @type {Integer} */ (lastIndex) + idx;
1070
- }
1071
-
1072
- // Todo: Once rewiring of tags may be fixed in comment-parser to reflect
1073
- // missing tags, this step should be added here (so that, e.g.,
1074
- // if accessing `jsdoc.tags`, such as to add a new tag, the
1075
- // correct information will be available)
1076
- };
1077
-
1078
- /** @type {AddTag} */
1079
- utils.addTag = (
1080
- targetTagName,
1081
- number = (jsdoc.tags[jsdoc.tags.length - 1]?.source[0]?.number ?? jsdoc.source.findIndex(({
1082
- tokens: {
1083
- tag,
1084
- },
1085
- }) => {
1086
- return tag;
1087
- }) - 1) + 1,
1088
- tokens = {},
1089
- ) => {
1090
- jsdoc.source.splice(number, 0, {
1091
- number,
1092
- source: '',
1093
- tokens: seedTokens({
1094
- delimiter: '*',
1095
- postDelimiter: ' ',
1096
- start: indent + ' ',
1097
- tag: `@${targetTagName}`,
1098
- ...tokens,
1099
- }),
1100
- });
1101
- for (const src of jsdoc.source.slice(number + 1)) {
1102
- src.number++;
1103
- }
1104
- };
1105
-
1106
- /** @type {GetFirstLine} */
1107
- utils.getFirstLine = () => {
1108
- let firstLine;
1109
- for (const {
1110
- number,
1111
- tokens: {
1112
- tag,
1113
- },
1114
- } of jsdoc.source) {
1115
- if (tag) {
1116
- firstLine = number;
1117
- break;
1118
- }
1119
- }
1120
-
1121
- return firstLine;
1122
- };
1123
-
1124
- /** @type {SeedTokens} */
1125
- utils.seedTokens = seedTokens;
1126
-
1127
- /** @type {EmptyTokens} */
1128
- utils.emptyTokens = (tokens) => {
1129
- for (const prop of [
1130
- 'start',
1131
- 'postDelimiter',
1132
- 'tag',
1133
- 'type',
1134
- 'postType',
1135
- 'postTag',
1136
- 'name',
1137
- 'postName',
1138
- 'description',
1139
- 'end',
1140
- 'lineEnd',
1141
- ]) {
1142
- tokens[
1143
- /**
1144
- * @type {"start"|"postDelimiter"|"tag"|"type"|"postType"|
1145
- * "postTag"|"name"|"postName"|"description"|"end"|"lineEnd"}
1146
- */ (
1147
- prop
1148
- )
1149
- ] = '';
1150
- }
1151
- };
1152
-
1153
- /** @type {AddLine} */
1154
- utils.addLine = (sourceIndex, tokens) => {
1155
- const number = (jsdoc.source[sourceIndex - 1]?.number || 0) + 1;
1156
- jsdoc.source.splice(sourceIndex, 0, {
1157
- number,
1158
- source: '',
1159
- tokens: seedTokens(tokens),
1160
- });
1161
-
1162
- for (const src of jsdoc.source.slice(number + 1)) {
1163
- src.number++;
1164
- }
1165
- // If necessary, we can rewire the tags (misnamed method)
1166
- // rewireSource(jsdoc);
1167
- };
1168
-
1169
- /** @type {AddLines} */
1170
- utils.addLines = (tagIndex, tagSourceOffset, numLines) => {
1171
- const {
1172
- source: tagSource,
1173
- } = jsdoc.tags[tagIndex];
1174
- /** @type {Integer|undefined} */
1175
- let lastIndex;
1176
- const firstNumber = jsdoc.source[0].number;
1177
- tagSource.some(({
1178
- number,
1179
- }) => {
1180
- const makeLine = () => {
1181
- return {
1182
- number,
1183
- source: '',
1184
- tokens: seedTokens({
1185
- delimiter: '*',
1186
- start: indent + ' ',
1187
- }),
1188
- };
1189
- };
1190
-
1191
- const makeLines = () => {
1192
- return Array.from({
1193
- length: numLines,
1194
- }, makeLine);
1195
- };
1196
-
1197
- const sourceIndex = jsdoc.source.findIndex(({
1198
- number: srcNumber,
1199
- tokens: {
1200
- end,
1201
- },
1202
- }) => {
1203
- return number === srcNumber && !end;
1204
- });
1205
- // c8 ignore else
1206
- if (sourceIndex > -1) {
1207
- const lines = makeLines();
1208
- jsdoc.source.splice(sourceIndex + tagSourceOffset, 0, ...lines);
1209
-
1210
- // tagSource.splice(tagIdx + 1, 0, ...makeLines());
1211
- lastIndex = sourceIndex;
1212
-
1213
- return true;
1214
- }
1215
- /* c8 ignore next 2 */
1216
- // eslint-disable-next-line @stylistic/padding-line-between-statements -- c8
1217
- return false;
1218
- });
1219
-
1220
- for (const [
1221
- idx,
1222
- src,
1223
- ] of jsdoc.source.slice(lastIndex).entries()) {
1224
- src.number = firstNumber + /** @type {Integer} */ (lastIndex) + idx;
1225
- }
1226
- };
1227
-
1228
- /** @type {MakeMultiline} */
1229
- utils.makeMultiline = () => {
1230
- const {
1231
- source: [
1232
- {
1233
- tokens,
1234
- },
1235
- ],
1236
- } = jsdoc;
1237
- const {
1238
- description,
1239
- lineEnd,
1240
- name,
1241
- postDelimiter,
1242
- tag,
1243
- type,
1244
- } = tokens;
1245
-
1246
- let {
1247
- tokens: {
1248
- postName,
1249
- postTag,
1250
- postType,
1251
- },
1252
- } = jsdoc.source[0];
1253
-
1254
- // Strip trailing leftovers from single line ending
1255
- if (!description) {
1256
- if (postName) {
1257
- postName = '';
1258
- } else if (postType) {
1259
- postType = '';
1260
- } else /* c8 ignore else -- `comment-parser` prevents empty blocks currently per https://github.com/syavorsky/comment-parser/issues/128 */ if (postTag) {
1261
- postTag = '';
1262
- }
1263
- }
1264
-
1265
- utils.emptyTokens(tokens);
1266
-
1267
- utils.addLine(1, {
1268
- delimiter: '*',
1269
-
1270
- // If a description were present, it may have whitespace attached
1271
- // due to being at the end of the single line
1272
- description: description.trimEnd(),
1273
- name,
1274
- postDelimiter,
1275
- postName,
1276
- postTag,
1277
- postType,
1278
- start: indent + ' ',
1279
- tag,
1280
- type,
1281
- });
1282
- utils.addLine(2, {
1283
- end: '*/',
1284
- lineEnd,
1285
- start: indent + ' ',
1286
- });
1287
- };
1288
-
1289
- /**
1290
- * @type {import('./jsdocUtils.js').FlattenRoots}
1291
- */
1292
- utils.flattenRoots = jsdocUtils.flattenRoots;
1293
-
1294
- /** @type {GetFunctionParameterNames} */
1295
- utils.getFunctionParameterNames = (useDefaultObjectProperties) => {
1296
- return jsdocUtils.getFunctionParameterNames(node, useDefaultObjectProperties);
1297
- };
1298
-
1299
- /** @type {HasParams} */
1300
- utils.hasParams = () => {
1301
- return jsdocUtils.hasParams(/** @type {Node} */ (node));
1302
- };
1303
-
1304
- /** @type {IsGenerator} */
1305
- utils.isGenerator = () => {
1306
- return node !== null && Boolean(
1307
- /**
1308
- * @type {import('estree').FunctionDeclaration|
1309
- * import('estree').FunctionExpression}
1310
- */ (node).generator ||
1311
- node.type === 'MethodDefinition' && node.value.generator ||
1312
- [
1313
- 'ExportDefaultDeclaration', 'ExportNamedDeclaration',
1314
- ].includes(node.type) &&
1315
- /** @type {import('estree').FunctionDeclaration} */
1316
- (
1317
- /**
1318
- * @type {import('estree').ExportNamedDeclaration|
1319
- * import('estree').ExportDefaultDeclaration}
1320
- */ (node).declaration
1321
- )?.generator,
1322
- );
1323
- };
1324
-
1325
- /** @type {IsConstructor} */
1326
- utils.isConstructor = () => {
1327
- return jsdocUtils.isConstructor(/** @type {Node} */ (node));
1328
- };
1329
-
1330
- /** @type {GetJsdocTagsDeep} */
1331
- utils.getJsdocTagsDeep = (tagName) => {
1332
- const name = /** @type {string|false} */ (utils.getPreferredTagName({
1333
- tagName,
1334
- }));
1335
- if (!name) {
1336
- return false;
1337
- }
1338
-
1339
- return jsdocUtils.getJsdocTagsDeep(jsdoc, name);
1340
- };
1341
-
1342
- /** @type {GetPreferredTagName} */
1343
- utils.getPreferredTagName = (args) => {
1344
- return jsdocUtils.getPreferredTagName(
1345
- jsdoc, {
1346
- ...args,
1347
- context,
1348
- mode,
1349
- report,
1350
- tagNamePreference,
1351
- },
1352
- );
1353
- };
1354
-
1355
- /** @type {IsValidTag} */
1356
- utils.isValidTag = (name, definedTags) => {
1357
- return jsdocUtils.isValidTag(context, mode, name, definedTags);
1358
- };
1359
-
1360
- /** @type {HasATag} */
1361
- utils.hasATag = (names) => {
1362
- return jsdocUtils.hasATag(jsdoc, names);
1363
- };
1364
-
1365
- /** @type {HasTag} */
1366
- utils.hasTag = (name) => {
1367
- return jsdocUtils.hasTag(jsdoc, name);
1368
- };
1369
-
1370
- /** @type {ComparePaths} */
1371
- utils.comparePaths = (name) => {
1372
- return jsdocUtils.comparePaths(name);
1373
- };
1374
-
1375
- /** @type {DropPathSegmentQuotes} */
1376
- utils.dropPathSegmentQuotes = (name) => {
1377
- return jsdocUtils.dropPathSegmentQuotes(name);
1378
- };
1379
-
1380
- /** @type {AvoidDocs} */
1381
- utils.avoidDocs = () => {
1382
- if (
1383
- ignoreReplacesDocs !== false &&
1384
- (utils.hasTag('ignore') || utils.classHasTag('ignore')) ||
1385
- overrideReplacesDocs !== false &&
1386
- (utils.hasTag('override') || utils.classHasTag('override')) ||
1387
- implementsReplacesDocs !== false &&
1388
- (utils.hasTag('implements') || utils.classHasTag('implements')) ||
1389
-
1390
- augmentsExtendsReplacesDocs &&
1391
- (utils.hasATag([
1392
- 'augments', 'extends',
1393
- ]) ||
1394
- utils.classHasTag('augments') ||
1395
- utils.classHasTag('extends'))) {
1396
- return true;
1397
- }
1398
-
1399
- if (jsdocUtils.exemptSpeciaMethods(
1400
- jsdoc,
1401
- node,
1402
- context,
1403
- /** @type {import('json-schema').JSONSchema4|import('json-schema').JSONSchema4[]} */ (
1404
- ruleConfig.meta.schema
1405
- ),
1406
- )) {
1407
- return true;
1408
- }
1409
-
1410
- const exemptedBy = context.options[0]?.exemptedBy ?? [
1411
- 'inheritDoc',
1412
- ...mode === 'closure' ? [] : [
1413
- 'inheritdoc',
1414
- ],
1415
- ];
1416
- if (exemptedBy.length && utils.getPresentTags(exemptedBy).length) {
1417
- return true;
1418
- }
1419
-
1420
- return false;
1421
- };
1422
-
1423
- for (const method of [
1424
- 'tagMightHaveNamePosition',
1425
- 'tagMightHaveTypePosition',
1426
- ]) {
1427
- /** @type {TagMightHaveNamePositionTypePosition} */
1428
- utils[
1429
- /** @type {"tagMightHaveNamePosition"|"tagMightHaveTypePosition"} */ (
1430
- method
1431
- )
1432
- ] = (tagName, otherModeMaps) => {
1433
- const result = jsdocUtils[
1434
- /** @type {"tagMightHaveNamePosition"|"tagMightHaveTypePosition"} */
1435
- (method)
1436
- ](tagName);
1437
- if (result) {
1438
- return true;
1439
- }
1440
-
1441
- if (!otherModeMaps) {
1442
- return false;
1443
- }
1444
-
1445
- const otherResult = otherModeMaps.some((otherModeMap) => {
1446
- return jsdocUtils[
1447
- /** @type {"tagMightHaveNamePosition"|"tagMightHaveTypePosition"} */
1448
- (method)
1449
- ](tagName, otherModeMap);
1450
- });
1451
-
1452
- return otherResult ? {
1453
- otherMode: true,
1454
- } : false;
1455
- };
1456
- }
1457
-
1458
- /** @type {TagMissingRequiredTypeOrNamepath} */
1459
- utils.tagMissingRequiredTypeOrNamepath = (tagName, otherModeMaps) => {
1460
- const result = jsdocUtils.tagMissingRequiredTypeOrNamepath(tagName);
1461
- if (!result) {
1462
- return false;
1463
- }
1464
-
1465
- const otherResult = otherModeMaps.every((otherModeMap) => {
1466
- return jsdocUtils.tagMissingRequiredTypeOrNamepath(tagName, otherModeMap);
1467
- });
1468
-
1469
- return otherResult ? true : {
1470
- otherMode: false,
1471
- };
1472
- };
1473
-
1474
- for (const method of [
1475
- 'tagMustHaveNamePosition',
1476
- 'tagMustHaveTypePosition',
1477
- ]) {
1478
- /** @type {TagMustHave} */
1479
- utils[
1480
- /** @type {"tagMustHaveNamePosition"|"tagMustHaveTypePosition"} */
1481
- (method)
1482
- ] = (tagName, otherModeMaps) => {
1483
- const result = jsdocUtils[
1484
- /** @type {"tagMustHaveNamePosition"|"tagMustHaveTypePosition"} */
1485
- (method)
1486
- ](tagName);
1487
- if (!result) {
1488
- return false;
1489
- }
1490
-
1491
- // if (!otherModeMaps) { return true; }
1492
-
1493
- const otherResult = otherModeMaps.every((otherModeMap) => {
1494
- return jsdocUtils[
1495
- /** @type {"tagMustHaveNamePosition"|"tagMustHaveTypePosition"} */
1496
- (method)
1497
- ](tagName, otherModeMap);
1498
- });
1499
-
1500
- return otherResult ? true : {
1501
- otherMode: false,
1502
- };
1503
- };
1504
- }
1505
-
1506
- for (const method of [
1507
- 'isNamepathDefiningTag',
1508
- 'isNamepathReferencingTag',
1509
- 'isNamepathOrUrlReferencingTag',
1510
- 'tagMightHaveNamepath',
1511
- ]) {
1512
- /** @type {IsNamepathX} */
1513
- utils[
1514
- /** @type {"isNamepathDefiningTag"|"isNamepathReferencingTag"|"isNamepathOrUrlReferencingTag"|"tagMightHaveNamepath"} */ (
1515
- method
1516
- )] = (tagName) => {
1517
- return jsdocUtils[
1518
- /** @type {"isNamepathDefiningTag"|"isNamepathReferencingTag"|"isNamepathOrUrlReferencingTag"|"tagMightHaveNamepath"} */
1519
- (method)
1520
- ](tagName);
1521
- };
1522
- }
1523
-
1524
- /** @type {GetTagStructureForMode} */
1525
- utils.getTagStructureForMode = (mde) => {
1526
- return jsdocUtils.getTagStructureForMode(mde, settings.structuredTags);
1527
- };
1528
-
1529
- /** @type {MayBeUndefinedTypeTag} */
1530
- utils.mayBeUndefinedTypeTag = (tag) => {
1531
- return jsdocUtils.mayBeUndefinedTypeTag(tag, settings.mode);
1532
- };
1533
-
1534
- /** @type {HasValueOrExecutorHasNonEmptyResolveValue} */
1535
- utils.hasValueOrExecutorHasNonEmptyResolveValue = (anyPromiseAsReturn, allBranches) => {
1536
- return jsdocUtils.hasValueOrExecutorHasNonEmptyResolveValue(
1537
- /** @type {Node} */ (node), anyPromiseAsReturn, allBranches,
1538
- );
1539
- };
1540
-
1541
- /** @type {HasYieldValue} */
1542
- utils.hasYieldValue = () => {
1543
- if ([
1544
- 'ExportDefaultDeclaration', 'ExportNamedDeclaration',
1545
- ].includes(/** @type {Node} */ (node).type)) {
1546
- return jsdocUtils.hasYieldValue(
1547
- /** @type {import('estree').Declaration|import('estree').Expression} */ (
1548
- /** @type {import('estree').ExportNamedDeclaration|import('estree').ExportDefaultDeclaration} */
1549
- (node).declaration
1550
- ),
1551
- );
1552
- }
1553
-
1554
- return jsdocUtils.hasYieldValue(/** @type {Node} */ (node));
1555
- };
1556
-
1557
- /** @type {HasYieldReturnValue} */
1558
- utils.hasYieldReturnValue = () => {
1559
- return jsdocUtils.hasYieldValue(/** @type {Node} */ (node), true);
1560
- };
1561
-
1562
- /** @type {HasThrowValue} */
1563
- utils.hasThrowValue = () => {
1564
- return jsdocUtils.hasThrowValue(node);
1565
- };
1566
-
1567
- /** @type {IsAsync} */
1568
- utils.isAsync = () => {
1569
- return Boolean(node && 'async' in node && node.async);
1570
- };
1571
-
1572
- /** @type {GetTags} */
1573
- utils.getTags = (tagName) => {
1574
- return jsdocUtils.getTags(jsdoc, tagName);
1575
- };
1576
-
1577
- /** @type {GetPresentTags} */
1578
- utils.getPresentTags = (tagList) => {
1579
- return jsdocUtils.filterTags(jsdoc, (tag) => {
1580
- return tagList.includes(tag.tag);
1581
- });
1582
- };
1583
-
1584
- /** @type {FilterTags} */
1585
- utils.filterTags = (filter) => {
1586
- return jsdocUtils.filterTags(jsdoc, (tag) => {
1587
- return filter(tag);
1588
- });
1589
- };
1590
-
1591
- /** @type {FilterAllTags} */
1592
- utils.filterAllTags = (filter) => {
1593
- const tags = jsdocUtils.getAllTags(jsdoc);
1594
- return tags.filter((tag) => {
1595
- return filter(tag);
1596
- });
1597
- };
1598
-
1599
- /** @type {GetTagsByType} */
1600
- utils.getTagsByType = (tags) => {
1601
- return jsdocUtils.getTagsByType(context, mode, tags);
1602
- };
1603
-
1604
- /** @type {HasOptionTag} */
1605
- utils.hasOptionTag = (tagName) => {
1606
- const {
1607
- tags,
1608
- } = context.options[0] ?? {};
1609
-
1610
- return Boolean(tags && tags.includes(tagName));
1611
- };
1612
-
1613
- /** @type {GetClassNode} */
1614
- utils.getClassNode = () => {
1615
- return [
1616
- ...ancestors, node,
1617
- ].reverse().find((parent) => {
1618
- return parent && [
1619
- 'ClassDeclaration', 'ClassExpression',
1620
- ].includes(parent.type);
1621
- }) ?? null;
1622
- };
1623
-
1624
- /** @type {GetClassJsdoc} */
1625
- utils.getClassJsdoc = () => {
1626
- const classNode = utils.getClassNode();
1627
-
1628
- if (!classNode) {
1629
- return null;
1630
- }
1631
-
1632
- const classJsdocNode = getJSDocComment(sourceCode, classNode, {
1633
- maxLines,
1634
- minLines,
1635
- });
1636
-
1637
- if (classJsdocNode) {
1638
- return parseComment(classJsdocNode, '');
1639
- }
1640
-
1641
- return null;
1642
- };
1643
-
1644
- /** @type {ClassHasTag} */
1645
- utils.classHasTag = (tagName) => {
1646
- const classJsdoc = utils.getClassJsdoc();
1647
-
1648
- return classJsdoc !== null && jsdocUtils.hasTag(classJsdoc, tagName);
1649
- };
1650
-
1651
- /** @type {ForEachPreferredTag} */
1652
- utils.forEachPreferredTag = (tagName, arrayHandler, skipReportingBlockedTag) => {
1653
- return jsdocUtils.forEachPreferredTag(
1654
- jsdoc, tagName, arrayHandler, {
1655
- context,
1656
- mode,
1657
- report,
1658
- skipReportingBlockedTag,
1659
- tagNamePreference,
1660
- },
1661
- );
1662
- };
1663
-
1664
- /** @type {FindContext} */
1665
- utils.findContext = (contexts, comment) => {
1666
- const foundContext = contexts.find((cntxt) => {
1667
- return typeof cntxt === 'string' ?
1668
- esquery.matches(
1669
- /** @type {Node} */ (node),
1670
- esquery.parse(cntxt),
1671
- undefined,
1672
- {
1673
- visitorKeys: sourceCode.visitorKeys,
1674
- },
1675
- ) :
1676
- (!cntxt.context || cntxt.context === 'any' ||
1677
- esquery.matches(
1678
- /** @type {Node} */ (node),
1679
- esquery.parse(cntxt.context),
1680
- undefined,
1681
- {
1682
- visitorKeys: sourceCode.visitorKeys,
1683
- },
1684
- )) && comment === cntxt.comment;
1685
- });
1686
-
1687
- const contextStr = typeof foundContext === 'object' ?
1688
- foundContext.context ?? 'any' :
1689
- String(foundContext);
1690
-
1691
- return {
1692
- contextStr,
1693
- foundContext,
1694
- };
1695
- };
1696
-
1697
- return utils;
1698
- };
1699
-
1700
- /**
1701
- * @typedef {{
1702
- * [key: string]: false|string|{
1703
- * message: string,
1704
- * replacement?: false|string
1705
- * skipRootChecking?: boolean
1706
- * }
1707
- * }} PreferredTypes
1708
- */
1709
- /**
1710
- * @typedef {{
1711
- * [key: string]: {
1712
- * name?: "text"|"namepath-defining"|"namepath-referencing"|false,
1713
- * type?: boolean|string[],
1714
- * required?: ("name"|"type"|"typeOrNameRequired")[]
1715
- * }
1716
- * }} StructuredTags
1717
- */
1718
- /**
1719
- * Settings from ESLint types.
1720
- * @typedef {{
1721
- * maxLines: Integer,
1722
- * minLines: Integer,
1723
- * tagNamePreference: import('./jsdocUtils.js').TagNamePreference,
1724
- * mode: import('./jsdocUtils.js').ParserMode,
1725
- * preferredTypes: PreferredTypes,
1726
- * structuredTags: StructuredTags,
1727
- * [name: string]: any,
1728
- * contexts?: Context[]
1729
- * }} Settings
1730
- */
1731
-
1732
- /**
1733
- * @typedef {{
1734
- * settings?: {
1735
- * jsdoc?: {
1736
- * ignorePrivate: boolean,
1737
- * ignoreInternal: boolean,
1738
- * maxLines: Integer,
1739
- * minLines: Integer,
1740
- * tagNamePreference: import('./jsdocUtils.js').TagNamePreference,
1741
- * preferredTypes: PreferredTypes,
1742
- * structuredTags: StructuredTags,
1743
- * overrideReplacesDocs: boolean,
1744
- * ignoreReplacesDocs: boolean,
1745
- * implementsReplacesDocs: boolean,
1746
- * augmentsExtendsReplacesDocs: boolean,
1747
- * exemptDestructuredRootsFromChecks: boolean,
1748
- * mode: import('./jsdocUtils.js').ParserMode,
1749
- * contexts: Context[],
1750
- * }
1751
- * }
1752
- * }} JSDocSettings
1753
- */
1754
-
1755
- /**
1756
- * @param {import('eslint').Rule.RuleContext & JSDocSettings} context
1757
- * @returns {Settings|false}
1758
- */
1759
- const getSettings = (context) => {
1760
- /* eslint-disable perfectionist/sort-objects */
1761
- const settings = {
1762
- // All rules
1763
- ignorePrivate: Boolean(context.settings.jsdoc?.ignorePrivate),
1764
- ignoreInternal: Boolean(context.settings.jsdoc?.ignoreInternal),
1765
- maxLines: Number(context.settings.jsdoc?.maxLines ?? 1),
1766
- minLines: Number(context.settings.jsdoc?.minLines ?? 0),
1767
-
1768
- // `check-tag-names` and many returns/param rules
1769
- tagNamePreference: context.settings.jsdoc?.tagNamePreference ?? {},
1770
-
1771
- // `check-types` and `no-undefined-types`
1772
- preferredTypes: context.settings.jsdoc?.preferredTypes ?? {},
1773
-
1774
- // `check-types`, `no-undefined-types`, `valid-types`
1775
- structuredTags: context.settings.jsdoc?.structuredTags ?? {},
1776
-
1777
- // `require-param`, `require-description`, `require-example`,
1778
- // `require-returns`, `require-throw`, `require-yields`
1779
- overrideReplacesDocs: context.settings.jsdoc?.overrideReplacesDocs,
1780
- ignoreReplacesDocs: context.settings.jsdoc?.ignoreReplacesDocs,
1781
- implementsReplacesDocs: context.settings.jsdoc?.implementsReplacesDocs,
1782
- augmentsExtendsReplacesDocs: context.settings.jsdoc?.augmentsExtendsReplacesDocs,
1783
-
1784
- // `require-param-type`, `require-param-description`
1785
- exemptDestructuredRootsFromChecks: context.settings.jsdoc?.exemptDestructuredRootsFromChecks,
1786
-
1787
- // Many rules, e.g., `check-tag-names`
1788
- mode: context.settings.jsdoc?.mode ?? 'typescript',
1789
-
1790
- // Many rules
1791
- contexts: context.settings.jsdoc?.contexts,
1792
- };
1793
- /* eslint-enable perfectionist/sort-objects */
1794
-
1795
- jsdocUtils.setTagStructure(settings.mode);
1796
- try {
1797
- jsdocUtils.overrideTagStructure(settings.structuredTags);
1798
- } catch (error) {
1799
- context.report({
1800
- loc: {
1801
- end: {
1802
- column: 1,
1803
- line: 1,
1804
- },
1805
- start: {
1806
- column: 1,
1807
- line: 1,
1808
- },
1809
- },
1810
- message: /** @type {Error} */ (error).message,
1811
- });
1812
-
1813
- return false;
1814
- }
1815
-
1816
- return settings;
1817
- };
1818
-
1819
- /**
1820
- * Create the report function
1821
- * @callback MakeReport
1822
- * @param {import('eslint').Rule.RuleContext} context
1823
- * @param {import('estree').Node} commentNode
1824
- * @returns {Report}
1825
- */
1826
-
1827
- /** @type {MakeReport} */
1828
- const makeReport = (context, commentNode) => {
1829
- /** @type {Report} */
1830
- const report = (message, fix = null, jsdocLoc = null, data = undefined) => {
1831
- let loc;
1832
-
1833
- if (jsdocLoc) {
1834
- if (!('line' in jsdocLoc)) {
1835
- jsdocLoc.line = /** @type {import('comment-parser').Spec & {line?: Integer}} */ (
1836
- jsdocLoc
1837
- ).source[0].number;
1838
- }
1839
-
1840
- const lineNumber = /** @type {import('eslint').AST.SourceLocation} */ (
1841
- commentNode.loc
1842
- ).start.line +
1843
- /** @type {Integer} */ (jsdocLoc.line);
1844
-
1845
- loc = {
1846
- end: {
1847
- column: 0,
1848
- line: lineNumber,
1849
- },
1850
- start: {
1851
- column: 0,
1852
- line: lineNumber,
1853
- },
1854
- };
1855
-
1856
- if ('column' in jsdocLoc && typeof jsdocLoc.column === 'number') {
1857
- const colNumber = /** @type {import('eslint').AST.SourceLocation} */ (
1858
- commentNode.loc
1859
- ).start.column + jsdocLoc.column;
1860
-
1861
- loc.end.column = colNumber;
1862
- loc.start.column = colNumber;
1863
- }
1864
- }
1865
-
1866
- context.report({
1867
- data,
1868
- fix,
1869
- loc,
1870
- message,
1871
- node: commentNode,
1872
- });
1873
- };
1874
-
1875
- return report;
1876
- };
1877
-
1878
- /**
1879
- * @typedef {(
1880
- * arg: {
1881
- * context: import('eslint').Rule.RuleContext,
1882
- * sourceCode: import('eslint').SourceCode,
1883
- * indent?: string,
1884
- * info?: {
1885
- * comment?: string|undefined,
1886
- * lastIndex?: Integer|undefined
1887
- * },
1888
- * state?: StateObject,
1889
- * globalState?: Map<string, Map<string, string>>,
1890
- * jsdoc?: JsdocBlockWithInline,
1891
- * jsdocNode?: import('eslint').Rule.Node & {
1892
- * range: [number, number]
1893
- * },
1894
- * node?: Node,
1895
- * allComments?: import('estree').Node[]
1896
- * report?: Report,
1897
- * makeReport?: MakeReport,
1898
- * settings: Settings,
1899
- * utils: BasicUtils,
1900
- * }
1901
- * ) => any } JsdocVisitorBasic
1902
- */
1903
- /**
1904
- * @typedef {(
1905
- * arg: {
1906
- * context: import('eslint').Rule.RuleContext,
1907
- * sourceCode: import('eslint').SourceCode,
1908
- * indent: string,
1909
- * info: {
1910
- * comment?: string|undefined,
1911
- * lastIndex?: Integer|undefined
1912
- * },
1913
- * state: StateObject,
1914
- * globalState: Map<string, Map<string, string>>,
1915
- * jsdoc: JsdocBlockWithInline,
1916
- * jsdocNode: import('eslint').Rule.Node & {
1917
- * range: [number, number]
1918
- * },
1919
- * node: Node|null,
1920
- * allComments?: import('estree').Node[]
1921
- * report: Report,
1922
- * makeReport?: MakeReport,
1923
- * settings: Settings,
1924
- * utils: Utils,
1925
- * }
1926
- * ) => any } JsdocVisitor
1927
- */
1928
-
1929
- /**
1930
- * @param {{
1931
- * comment?: string,
1932
- * lastIndex?: Integer,
1933
- * selector?: string,
1934
- * isFunctionContext?: boolean,
1935
- * }} info
1936
- * @param {string} indent
1937
- * @param {JsdocBlockWithInline} jsdoc
1938
- * @param {RuleConfig} ruleConfig
1939
- * @param {import('eslint').Rule.RuleContext} context
1940
- * @param {import('@es-joy/jsdoccomment').Token} jsdocNode
1941
- * @param {Node|null} node
1942
- * @param {Settings} settings
1943
- * @param {import('eslint').SourceCode} sourceCode
1944
- * @param {JsdocVisitor} iterator
1945
- * @param {StateObject} state
1946
- * @param {boolean} [iteratingAll]
1947
- * @returns {void}
1948
- */
1949
- const iterate = (
1950
- info,
1951
- indent, jsdoc,
1952
- ruleConfig, context, jsdocNode, node, settings,
1953
- sourceCode, iterator, state, iteratingAll,
1954
- ) => {
1955
- const jsdocNde = /** @type {unknown} */ (jsdocNode);
1956
- const report = makeReport(
1957
- context,
1958
- /** @type {import('estree').Node} */
1959
- (jsdocNde),
1960
- );
1961
-
1962
- const utils = getUtils(
1963
- node,
1964
- jsdoc,
1965
- /** @type {import('eslint').AST.Token} */
1966
- (jsdocNode),
1967
- settings,
1968
- report,
1969
- context,
1970
- sourceCode,
1971
- iteratingAll,
1972
- ruleConfig,
1973
- indent,
1974
- );
1975
-
1976
- if (
1977
- !ruleConfig.checkInternal && settings.ignoreInternal &&
1978
- utils.hasTag('internal')
1979
- ) {
1980
- return;
1981
- }
1982
-
1983
- if (
1984
- !ruleConfig.checkPrivate && settings.ignorePrivate &&
1985
- (
1986
- utils.hasTag('private') ||
1987
- jsdocUtils
1988
- .filterTags(jsdoc, ({
1989
- tag,
1990
- }) => {
1991
- return tag === 'access';
1992
- })
1993
- .some(({
1994
- description,
1995
- }) => {
1996
- return description === 'private';
1997
- })
1998
- )
1999
- ) {
2000
- return;
2001
- }
2002
-
2003
- iterator({
2004
- context,
2005
- globalState,
2006
- indent,
2007
- info,
2008
- jsdoc,
2009
- jsdocNode: /**
2010
- * @type {import('eslint').Rule.Node & {
2011
- * range: [number, number];}}
2012
- */ (jsdocNde),
2013
- node,
2014
- report,
2015
- settings,
2016
- sourceCode,
2017
- state,
2018
- utils,
2019
- });
2020
- };
2021
-
2022
- /**
2023
- * @param {string[]} lines
2024
- * @param {import('estree').Comment} jsdocNode
2025
- * @returns {[indent: string, jsdoc: JsdocBlockWithInline]}
2026
- */
2027
- const getIndentAndJSDoc = function (lines, jsdocNode) {
2028
- const sourceLine = lines[
2029
- /** @type {import('estree').SourceLocation} */
2030
- (jsdocNode.loc).start.line - 1
2031
- ];
2032
-
2033
- let indentChar = sourceLine.charAt(0);
2034
- if (indentChar !== ' ' && indentChar !== '\t') {
2035
- indentChar = ' ';
2036
- }
2037
-
2038
- const indnt = indentChar.repeat(
2039
- /** @type {import('estree').SourceLocation} */
2040
- (jsdocNode.loc).start.column,
2041
- );
2042
-
2043
- const jsdc = parseComment(jsdocNode, '');
2044
-
2045
- return [
2046
- indnt, jsdc,
2047
- ];
2048
- };
2049
-
2050
- /**
2051
- *
2052
- * @typedef {{node: Node & {
2053
- * range: [number, number]
2054
- * }, state: StateObject}} NonCommentArgs
2055
- */
2056
-
2057
- /**
2058
- * @typedef {object} RuleConfig
2059
- * @property {EslintRuleMeta} meta ESLint rule meta
2060
- * @property {import('./jsdocUtils.js').DefaultContexts} [contextDefaults] Any default contexts
2061
- * @property {true} [contextSelected] Whether to force a `contexts` check
2062
- * @property {true} [iterateAllJsdocs] Whether to iterate all JSDoc blocks by default
2063
- * regardless of context
2064
- * @property {true} [checkPrivate] Whether to check `@private` blocks (normally exempted)
2065
- * @property {true} [checkInternal] Whether to check `@internal` blocks (normally exempted)
2066
- * @property {true} [checkFile] Whether to iterates over all JSDoc blocks regardless of attachment
2067
- * @property {true} [nonGlobalSettings] Whether to avoid relying on settings for global contexts
2068
- * @property {true} [noTracking] Whether to disable the tracking of visited comment nodes (as
2069
- * non-tracked may conduct further actions)
2070
- * @property {true} [matchContext] Whether the rule expects contexts to be based on a match option
2071
- * @property {(args: {
2072
- * context: import('eslint').Rule.RuleContext,
2073
- * state: StateObject,
2074
- * settings: Settings,
2075
- * utils: BasicUtils
2076
- * }) => void} [exit] Handler to be executed upon exiting iteration of program AST
2077
- * @property {(nca: NonCommentArgs) => void} [nonComment] Handler to be executed if rule wishes
2078
- * to be supplied nodes without comments
2079
- */
2080
-
2081
- /**
2082
- * Create an eslint rule that iterates over all JSDocs, regardless of whether
2083
- * they are attached to a function-like node.
2084
- * @param {JsdocVisitor} iterator
2085
- * @param {RuleConfig} ruleConfig The rule's configuration
2086
- * @param {ContextObject[]|null} [contexts] The `contexts` containing relevant `comment` info.
2087
- * @param {boolean} [additiveCommentContexts] If true, will have a separate
2088
- * iteration for each matching comment context. Otherwise, will iterate
2089
- * once if there is a single matching comment context.
2090
- * @returns {import('eslint').Rule.RuleModule}
2091
- */
2092
- const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContexts) => {
2093
- const trackedJsdocs = new Set();
2094
-
2095
- /** @type {import('@es-joy/jsdoccomment').CommentHandler} */
2096
- let handler;
2097
-
2098
- /** @type {Settings|false} */
2099
- let settings;
2100
-
2101
- /**
2102
- * @param {import('eslint').Rule.RuleContext} context
2103
- * @param {Node|null} node
2104
- * @param {import('estree').Comment[]} jsdocNodes
2105
- * @param {StateObject} state
2106
- * @param {boolean} [lastCall]
2107
- * @returns {void}
2108
- */
2109
- const callIterator = (context, node, jsdocNodes, state, lastCall) => {
2110
- /* c8 ignore next -- Fallback to deprecated method */
2111
- const {
2112
- sourceCode = context.getSourceCode(),
2113
- } = context;
2114
- const {
2115
- lines,
2116
- } = sourceCode;
2117
-
2118
- const utils = getBasicUtils(context, /** @type {Settings} */ (settings));
2119
- for (const jsdocNode of jsdocNodes) {
2120
- const jsdocNde = /** @type {unknown} */ (jsdocNode);
2121
- if (!(/^\/\*\*\s/v).test(sourceCode.getText(
2122
- /** @type {import('estree').Node} */
2123
- (jsdocNde),
2124
- ))) {
2125
- continue;
2126
- }
2127
-
2128
- const [
2129
- indent,
2130
- jsdoc,
2131
- ] = getIndentAndJSDoc(
2132
- lines, jsdocNode,
2133
- );
2134
-
2135
- if (additiveCommentContexts) {
2136
- for (const [
2137
- idx,
2138
- {
2139
- comment,
2140
- },
2141
- ] of /** @type {ContextObject[]} */ (contexts).entries()) {
2142
- if (comment && handler(comment, jsdoc) === false) {
2143
- continue;
2144
- }
2145
-
2146
- iterate(
2147
- {
2148
- comment,
2149
- lastIndex: idx,
2150
- selector: node?.type,
2151
- },
2152
- indent,
2153
- jsdoc,
2154
- ruleConfig,
2155
- context,
2156
- jsdocNode,
2157
- /** @type {Node} */
2158
- (node),
2159
- /** @type {Settings} */
2160
- (settings),
2161
- sourceCode,
2162
- iterator,
2163
- state,
2164
- true,
2165
- );
2166
- }
2167
-
2168
- continue;
2169
- }
2170
-
2171
- let lastComment;
2172
- let lastIndex;
2173
- // eslint-disable-next-line no-loop-func
2174
- if (contexts && contexts.every(({
2175
- comment,
2176
- }, idx) => {
2177
- lastComment = comment;
2178
- lastIndex = idx;
2179
-
2180
- return comment && handler(comment, jsdoc) === false;
2181
- })) {
2182
- continue;
2183
- }
2184
-
2185
- iterate(
2186
- lastComment ? {
2187
- comment: lastComment,
2188
- lastIndex,
2189
- selector: node?.type,
2190
- } : {
2191
- lastIndex,
2192
- selector: node?.type,
2193
- },
2194
- indent,
2195
- jsdoc,
2196
- ruleConfig,
2197
- context,
2198
- jsdocNode,
2199
- node,
2200
- /** @type {Settings} */
2201
- (settings),
2202
- sourceCode,
2203
- iterator,
2204
- state,
2205
- true,
2206
- );
2207
- }
2208
-
2209
- const settngs = /** @type {Settings} */ (settings);
2210
-
2211
- if (lastCall && ruleConfig.exit) {
2212
- ruleConfig.exit({
2213
- context,
2214
- settings: settngs,
2215
- state,
2216
- utils,
2217
- });
2218
- }
2219
- };
2220
-
2221
- return {
2222
- create (context) {
2223
- /* c8 ignore next -- Fallback to deprecated method */
2224
- const {
2225
- sourceCode = context.getSourceCode(),
2226
- } = context;
2227
- settings = getSettings(context);
2228
- if (!settings) {
2229
- return {};
2230
- }
2231
-
2232
- if (contexts) {
2233
- handler = commentHandler(settings);
2234
- }
2235
-
2236
- const state = {};
2237
-
2238
- return {
2239
- /**
2240
- * @param {import('eslint').Rule.Node & {
2241
- * range: [Integer, Integer];
2242
- * }} node
2243
- * @returns {void}
2244
- */
2245
- '*:not(Program)' (node) {
2246
- const commentNode = getJSDocComment(
2247
- sourceCode, node, /** @type {Settings} */ (settings),
2248
- );
2249
- if (!ruleConfig.noTracking && trackedJsdocs.has(commentNode)) {
2250
- return;
2251
- }
2252
-
2253
- if (!commentNode) {
2254
- if (ruleConfig.nonComment) {
2255
- const ste = /** @type {StateObject} */ (state);
2256
- ruleConfig.nonComment({
2257
- node,
2258
- state: ste,
2259
- });
2260
- }
2261
-
2262
- return;
2263
- }
2264
-
2265
- trackedJsdocs.add(commentNode);
2266
- callIterator(context, node, [
2267
- /** @type {import('estree').Comment} */
2268
- (commentNode),
2269
- ], /** @type {StateObject} */ (state));
2270
- },
2271
- 'Program:exit' () {
2272
- const allComments = sourceCode.getAllComments();
2273
- const untrackedJSdoc = allComments.filter((node) => {
2274
- return !trackedJsdocs.has(node);
2275
- });
2276
-
2277
- callIterator(
2278
- context,
2279
- null,
2280
- untrackedJSdoc,
2281
- /** @type {StateObject} */
2282
- (state),
2283
- true,
2284
- );
2285
- },
2286
- };
2287
- },
2288
- meta: ruleConfig.meta,
2289
- };
2290
- };
2291
-
2292
- /**
2293
- * Create an eslint rule that iterates over all JSDocs, regardless of whether
2294
- * they are attached to a function-like node.
2295
- * @param {JsdocVisitorBasic} iterator
2296
- * @param {RuleConfig} ruleConfig
2297
- * @returns {import('eslint').Rule.RuleModule}
2298
- */
2299
- const checkFile = (iterator, ruleConfig) => {
2300
- return {
2301
- create (context) {
2302
- /* c8 ignore next -- Fallback to deprecated method */
2303
- const {
2304
- sourceCode = context.getSourceCode(),
2305
- } = context;
2306
- const settings = getSettings(context);
2307
- if (!settings) {
2308
- return {};
2309
- }
2310
-
2311
- return {
2312
- 'Program:exit' () {
2313
- const allComms = /** @type {unknown} */ (sourceCode.getAllComments());
2314
- const utils = getBasicUtils(context, settings);
2315
-
2316
- iterator({
2317
- allComments: /** @type {import('estree').Node[]} */ (allComms),
2318
- context,
2319
- makeReport,
2320
- settings,
2321
- sourceCode,
2322
- utils,
2323
- });
2324
- },
2325
- };
2326
- },
2327
- meta: ruleConfig.meta,
2328
- };
2329
- };
2330
-
2331
- export {
2332
- getSettings,
2333
- // dslint-disable-next-line unicorn/prefer-export-from -- Avoid experimental parser
2334
-
2335
- };
2336
-
2337
- /**
2338
- * @param {JsdocVisitor} iterator
2339
- * @param {RuleConfig} ruleConfig
2340
- * @returns {import('eslint').Rule.RuleModule}
2341
- */
2342
- export default function iterateJsdoc (iterator, ruleConfig) {
2343
- const metaType = ruleConfig?.meta?.type;
2344
- if (!metaType || ![
2345
- 'layout', 'problem', 'suggestion',
2346
- ].includes(metaType)) {
2347
- throw new TypeError('Rule must include `meta.type` option (with value "problem", "suggestion", or "layout")');
2348
- }
2349
-
2350
- if (typeof iterator !== 'function') {
2351
- throw new TypeError('The iterator argument must be a function.');
2352
- }
2353
-
2354
- if (ruleConfig.checkFile) {
2355
- return checkFile(
2356
- /** @type {JsdocVisitorBasic} */ (iterator),
2357
- ruleConfig,
2358
- );
2359
- }
2360
-
2361
- if (ruleConfig.iterateAllJsdocs) {
2362
- return iterateAllJsdocs(iterator, ruleConfig);
2363
- }
2364
-
2365
- /** @type {import('eslint').Rule.RuleModule} */
2366
- return {
2367
- /**
2368
- * The entrypoint for the JSDoc rule.
2369
- * @param {import('eslint').Rule.RuleContext} context
2370
- * a reference to the context which hold all important information
2371
- * like settings and the sourcecode to check.
2372
- * @returns {import('eslint').Rule.RuleListener}
2373
- * a listener with parser callback function.
2374
- */
2375
- create (context) {
2376
- const settings = getSettings(context);
2377
- if (!settings) {
2378
- return {};
2379
- }
2380
-
2381
- /**
2382
- * @type {Context[]|undefined}
2383
- */
2384
- let contexts;
2385
- if (ruleConfig.contextDefaults || ruleConfig.contextSelected || ruleConfig.matchContext) {
2386
- contexts = ruleConfig.matchContext && context.options[0]?.match ?
2387
- context.options[0].match :
2388
- jsdocUtils.enforcedContexts(context, ruleConfig.contextDefaults, ruleConfig.nonGlobalSettings ? {} : settings);
2389
-
2390
- if (contexts) {
2391
- contexts = contexts.map((obj) => {
2392
- if (typeof obj === 'object' && !obj.context) {
2393
- return {
2394
- ...obj,
2395
- context: 'any',
2396
- };
2397
- }
2398
-
2399
- return obj;
2400
- });
2401
- }
2402
-
2403
- const hasPlainAny = contexts?.includes('any');
2404
- const hasObjectAny = !hasPlainAny && contexts?.find((ctxt) => {
2405
- if (typeof ctxt === 'string') {
2406
- return false;
2407
- }
2408
-
2409
- return ctxt?.context === 'any';
2410
- });
2411
- if (hasPlainAny || hasObjectAny) {
2412
- return iterateAllJsdocs(
2413
- iterator,
2414
- ruleConfig,
2415
- hasObjectAny ? /** @type {ContextObject[]} */ (contexts) : null,
2416
- ruleConfig.matchContext,
2417
- ).create(context);
2418
- }
2419
- }
2420
-
2421
- /* c8 ignore next -- Fallback to deprecated method */
2422
- const {
2423
- sourceCode = context.getSourceCode(),
2424
- } = context;
2425
- const {
2426
- lines,
2427
- } = sourceCode;
2428
-
2429
- /** @type {Partial<StateObject>} */
2430
- const state = {};
2431
-
2432
- /** @type {CheckJsdoc} */
2433
- const checkJsdoc = (info, handler, node) => {
2434
- const jsdocNode = getJSDocComment(sourceCode, node, settings);
2435
- if (!jsdocNode) {
2436
- return;
2437
- }
2438
-
2439
- const [
2440
- indent,
2441
- jsdoc,
2442
- ] = getIndentAndJSDoc(
2443
- lines,
2444
- /** @type {import('estree').Comment} */
2445
- (jsdocNode),
2446
- );
2447
-
2448
- if (
2449
- // Note, `handler` should already be bound in its first argument
2450
- // with these only to be called after the value of
2451
- // `comment`
2452
- handler && handler(jsdoc) === false
2453
- ) {
2454
- return;
2455
- }
2456
-
2457
- iterate(
2458
- info,
2459
- indent,
2460
- jsdoc,
2461
- ruleConfig,
2462
- context,
2463
- jsdocNode,
2464
- node,
2465
- settings,
2466
- sourceCode,
2467
- iterator,
2468
- /** @type {StateObject} */
2469
- (state),
2470
- );
2471
- };
2472
-
2473
- /** @type {import('eslint').Rule.RuleListener} */
2474
- let contextObject = {};
2475
-
2476
- if (contexts && (
2477
- ruleConfig.contextDefaults || ruleConfig.contextSelected || ruleConfig.matchContext
2478
- )) {
2479
- contextObject = jsdocUtils.getContextObject(
2480
- contexts,
2481
- checkJsdoc,
2482
- commentHandler(settings),
2483
- );
2484
- } else {
2485
- for (const prop of [
2486
- 'ArrowFunctionExpression',
2487
- 'FunctionDeclaration',
2488
- 'FunctionExpression',
2489
- 'TSDeclareFunction',
2490
- ]) {
2491
- contextObject[prop] = checkJsdoc.bind(null, {
2492
- selector: prop,
2493
- }, null);
2494
- }
2495
- }
2496
-
2497
- if (typeof ruleConfig.exit === 'function') {
2498
- contextObject['Program:exit'] = () => {
2499
- const ste = /** @type {StateObject} */ (state);
2500
-
2501
- // @ts-expect-error `utils` not needed at this point
2502
- /** @type {Required<RuleConfig>} */ (ruleConfig).exit({
2503
- context,
2504
- settings,
2505
- state: ste,
2506
- });
2507
- };
2508
- }
2509
-
2510
- return contextObject;
2511
- },
2512
- meta: ruleConfig.meta,
2513
- };
2514
- }
2515
-
2516
- export {
2517
- parseComment,
2518
- } from '@es-joy/jsdoccomment';