eslint-plugin-jsdoc 53.0.1 → 54.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (359) hide show
  1. package/dist/WarnSettings.cjs +35 -18
  2. package/dist/WarnSettings.cjs.map +1 -1
  3. package/dist/alignTransform.cjs +305 -224
  4. package/dist/alignTransform.cjs.map +1 -1
  5. package/dist/defaultTagOrder.cjs +43 -132
  6. package/dist/defaultTagOrder.cjs.map +1 -1
  7. package/dist/exportParser.cjs +696 -478
  8. package/dist/exportParser.cjs.map +1 -1
  9. package/dist/generateRule.cjs +242 -0
  10. package/dist/generateRule.cjs.map +1 -0
  11. package/dist/getDefaultTagStructureForMode.cjs +288 -184
  12. package/dist/getDefaultTagStructureForMode.cjs.map +1 -1
  13. package/dist/getJsdocProcessorPlugin.cjs +550 -364
  14. package/dist/getJsdocProcessorPlugin.cjs.map +1 -1
  15. package/dist/getJsdocProcessorPlugin.d.ts +65 -68
  16. package/dist/getJsdocProcessorPlugin.d.ts.map +1 -1
  17. package/dist/index.cjs +410 -2
  18. package/dist/index.cjs.map +1 -0
  19. package/dist/index.d.ts +17 -2
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/iterateJsdoc.cjs +2005 -1539
  22. package/dist/iterateJsdoc.cjs.map +1 -1
  23. package/dist/iterateJsdoc.d.ts +350 -359
  24. package/dist/iterateJsdoc.d.ts.map +1 -1
  25. package/dist/jsdocUtils.cjs +1376 -1009
  26. package/dist/jsdocUtils.cjs.map +1 -1
  27. package/dist/rules/checkAccess.cjs +36 -29
  28. package/dist/rules/checkAccess.cjs.map +1 -1
  29. package/dist/rules/checkAlignment.cjs +54 -41
  30. package/dist/rules/checkAlignment.cjs.map +1 -1
  31. package/dist/rules/checkExamples.cjs +484 -327
  32. package/dist/rules/checkExamples.cjs.map +1 -1
  33. package/dist/rules/checkIndentation.cjs +65 -50
  34. package/dist/rules/checkIndentation.cjs.map +1 -1
  35. package/dist/rules/checkLineAlignment.cjs +311 -220
  36. package/dist/rules/checkLineAlignment.cjs.map +1 -1
  37. package/dist/rules/checkParamNames.cjs +335 -227
  38. package/dist/rules/checkParamNames.cjs.map +1 -1
  39. package/dist/rules/checkPropertyNames.cjs +106 -78
  40. package/dist/rules/checkPropertyNames.cjs.map +1 -1
  41. package/dist/rules/checkSyntax.cjs +34 -21
  42. package/dist/rules/checkSyntax.cjs.map +1 -1
  43. package/dist/rules/checkTagNames.cjs +210 -188
  44. package/dist/rules/checkTagNames.cjs.map +1 -1
  45. package/dist/rules/checkTemplateNames.cjs +178 -121
  46. package/dist/rules/checkTemplateNames.cjs.map +1 -1
  47. package/dist/rules/checkTypes.cjs +385 -291
  48. package/dist/rules/checkTypes.cjs.map +1 -1
  49. package/dist/rules/checkValues.cjs +146 -100
  50. package/dist/rules/checkValues.cjs.map +1 -1
  51. package/dist/rules/convertToJsdocComments.cjs +306 -228
  52. package/dist/rules/convertToJsdocComments.cjs.map +1 -1
  53. package/dist/rules/emptyTags.cjs +72 -62
  54. package/dist/rules/emptyTags.cjs.map +1 -1
  55. package/dist/rules/implementsOnClasses.cjs +56 -36
  56. package/dist/rules/implementsOnClasses.cjs.map +1 -1
  57. package/dist/rules/importsAsDependencies.cjs +99 -62
  58. package/dist/rules/importsAsDependencies.cjs.map +1 -1
  59. package/dist/rules/informativeDocs.cjs +142 -105
  60. package/dist/rules/informativeDocs.cjs.map +1 -1
  61. package/dist/rules/linesBeforeBlock.cjs +105 -70
  62. package/dist/rules/linesBeforeBlock.cjs.map +1 -1
  63. package/dist/rules/matchDescription.cjs +222 -160
  64. package/dist/rules/matchDescription.cjs.map +1 -1
  65. package/dist/rules/matchName.cjs +128 -73
  66. package/dist/rules/matchName.cjs.map +1 -1
  67. package/dist/rules/multilineBlocks.cjs +352 -235
  68. package/dist/rules/multilineBlocks.cjs.map +1 -1
  69. package/dist/rules/noBadBlocks.cjs +86 -63
  70. package/dist/rules/noBadBlocks.cjs.map +1 -1
  71. package/dist/rules/noBlankBlockDescriptions.cjs +57 -35
  72. package/dist/rules/noBlankBlockDescriptions.cjs.map +1 -1
  73. package/dist/rules/noBlankBlocks.cjs +48 -26
  74. package/dist/rules/noBlankBlocks.cjs.map +1 -1
  75. package/dist/rules/noDefaults.cjs +79 -52
  76. package/dist/rules/noDefaults.cjs.map +1 -1
  77. package/dist/rules/noMissingSyntax.cjs +165 -115
  78. package/dist/rules/noMissingSyntax.cjs.map +1 -1
  79. package/dist/rules/noMultiAsterisks.cjs +89 -48
  80. package/dist/rules/noMultiAsterisks.cjs.map +1 -1
  81. package/dist/rules/noRestrictedSyntax.cjs +79 -45
  82. package/dist/rules/noRestrictedSyntax.cjs.map +1 -1
  83. package/dist/rules/noTypes.cjs +80 -59
  84. package/dist/rules/noTypes.cjs.map +1 -1
  85. package/dist/rules/noUndefinedTypes.cjs +388 -297
  86. package/dist/rules/noUndefinedTypes.cjs.map +1 -1
  87. package/dist/rules/requireAsteriskPrefix.cjs +159 -108
  88. package/dist/rules/requireAsteriskPrefix.cjs.map +1 -1
  89. package/dist/rules/requireDescription.cjs +129 -89
  90. package/dist/rules/requireDescription.cjs.map +1 -1
  91. package/dist/rules/requireDescriptionCompleteSentence.cjs +262 -201
  92. package/dist/rules/requireDescriptionCompleteSentence.cjs.map +1 -1
  93. package/dist/rules/requireExample.cjs +104 -73
  94. package/dist/rules/requireExample.cjs.map +1 -1
  95. package/dist/rules/requireFileOverview.cjs +129 -75
  96. package/dist/rules/requireFileOverview.cjs.map +1 -1
  97. package/dist/rules/requireHyphenBeforeParamDescription.cjs +133 -85
  98. package/dist/rules/requireHyphenBeforeParamDescription.cjs.map +1 -1
  99. package/dist/rules/requireJsdoc.cjs +557 -384
  100. package/dist/rules/requireJsdoc.cjs.map +1 -1
  101. package/dist/rules/requireParam.cjs +526 -336
  102. package/dist/rules/requireParam.cjs.map +1 -1
  103. package/dist/rules/requireParamDescription.cjs +80 -55
  104. package/dist/rules/requireParamDescription.cjs.map +1 -1
  105. package/dist/rules/requireParamName.cjs +50 -32
  106. package/dist/rules/requireParamName.cjs.map +1 -1
  107. package/dist/rules/requireParamType.cjs +80 -55
  108. package/dist/rules/requireParamType.cjs.map +1 -1
  109. package/dist/rules/requireProperty.cjs +42 -31
  110. package/dist/rules/requireProperty.cjs.map +1 -1
  111. package/dist/rules/requirePropertyDescription.cjs +25 -17
  112. package/dist/rules/requirePropertyDescription.cjs.map +1 -1
  113. package/dist/rules/requirePropertyName.cjs +25 -17
  114. package/dist/rules/requirePropertyName.cjs.map +1 -1
  115. package/dist/rules/requirePropertyType.cjs +25 -17
  116. package/dist/rules/requirePropertyType.cjs.map +1 -1
  117. package/dist/rules/requireReturns.cjs +203 -125
  118. package/dist/rules/requireReturns.cjs.map +1 -1
  119. package/dist/rules/requireReturnsCheck.cjs +103 -60
  120. package/dist/rules/requireReturnsCheck.cjs.map +1 -1
  121. package/dist/rules/requireReturnsDescription.cjs +54 -39
  122. package/dist/rules/requireReturnsDescription.cjs.map +1 -1
  123. package/dist/rules/requireReturnsType.cjs +50 -32
  124. package/dist/rules/requireReturnsType.cjs.map +1 -1
  125. package/dist/rules/requireTemplate.cjs +178 -119
  126. package/dist/rules/requireTemplate.cjs.map +1 -1
  127. package/dist/rules/requireThrows.cjs +95 -61
  128. package/dist/rules/requireThrows.cjs.map +1 -1
  129. package/dist/rules/requireYields.cjs +166 -106
  130. package/dist/rules/requireYields.cjs.map +1 -1
  131. package/dist/rules/requireYieldsCheck.cjs +152 -96
  132. package/dist/rules/requireYieldsCheck.cjs.map +1 -1
  133. package/dist/rules/sortTags.cjs +444 -258
  134. package/dist/rules/sortTags.cjs.map +1 -1
  135. package/dist/rules/tagLines.cjs +266 -179
  136. package/dist/rules/tagLines.cjs.map +1 -1
  137. package/dist/rules/textEscaping.cjs +127 -92
  138. package/dist/rules/textEscaping.cjs.map +1 -1
  139. package/dist/rules/validTypes.cjs +265 -252
  140. package/dist/rules/validTypes.cjs.map +1 -1
  141. package/dist/tagNames.cjs +170 -134
  142. package/dist/tagNames.cjs.map +1 -1
  143. package/dist/utils/hasReturnValue.cjs +474 -246
  144. package/dist/utils/hasReturnValue.cjs.map +1 -1
  145. package/package.json +24 -40
  146. package/src/WarnSettings.js +34 -0
  147. package/src/alignTransform.js +358 -0
  148. package/src/defaultTagOrder.js +169 -0
  149. package/src/exportParser.js +978 -0
  150. package/src/getDefaultTagStructureForMode.js +969 -0
  151. package/src/getJsdocProcessorPlugin.js +672 -0
  152. package/src/index.js +530 -0
  153. package/src/iterateJsdoc.js +2541 -0
  154. package/src/jsdocUtils.js +1896 -0
  155. package/src/rules/checkAccess.js +45 -0
  156. package/src/rules/checkAlignment.js +63 -0
  157. package/src/rules/checkExamples.js +589 -0
  158. package/src/rules/checkIndentation.js +75 -0
  159. package/src/rules/checkLineAlignment.js +372 -0
  160. package/src/rules/checkParamNames.js +474 -0
  161. package/src/rules/checkPropertyNames.js +152 -0
  162. package/src/rules/checkSyntax.js +30 -0
  163. package/src/rules/checkTagNames.js +314 -0
  164. package/src/rules/checkTemplateNames.js +204 -0
  165. package/src/rules/checkTypes.js +535 -0
  166. package/src/rules/checkValues.js +248 -0
  167. package/src/rules/convertToJsdocComments.js +398 -0
  168. package/src/rules/emptyTags.js +98 -0
  169. package/src/rules/implementsOnClasses.js +64 -0
  170. package/src/rules/importsAsDependencies.js +133 -0
  171. package/src/rules/informativeDocs.js +189 -0
  172. package/src/rules/linesBeforeBlock.js +134 -0
  173. package/src/rules/matchDescription.js +286 -0
  174. package/src/rules/matchName.js +151 -0
  175. package/src/rules/multilineBlocks.js +493 -0
  176. package/src/rules/noBadBlocks.js +119 -0
  177. package/src/rules/noBlankBlockDescriptions.js +69 -0
  178. package/src/rules/noBlankBlocks.js +53 -0
  179. package/src/rules/noDefaults.js +85 -0
  180. package/src/rules/noMissingSyntax.js +195 -0
  181. package/src/rules/noMultiAsterisks.js +134 -0
  182. package/src/rules/noRestrictedSyntax.js +91 -0
  183. package/src/rules/noTypes.js +93 -0
  184. package/src/rules/noUndefinedTypes.js +543 -0
  185. package/src/rules/requireAsteriskPrefix.js +190 -0
  186. package/src/rules/requireDescription.js +161 -0
  187. package/src/rules/requireDescriptionCompleteSentence.js +335 -0
  188. package/src/rules/requireExample.js +118 -0
  189. package/src/rules/requireFileOverview.js +154 -0
  190. package/src/rules/requireHyphenBeforeParamDescription.js +176 -0
  191. package/src/rules/requireJsdoc.js +743 -0
  192. package/src/rules/requireParam.js +602 -0
  193. package/src/rules/requireParamDescription.js +89 -0
  194. package/src/rules/requireParamName.js +55 -0
  195. package/src/rules/requireParamType.js +89 -0
  196. package/src/rules/requireProperty.js +48 -0
  197. package/src/rules/requirePropertyDescription.js +25 -0
  198. package/src/rules/requirePropertyName.js +25 -0
  199. package/src/rules/requirePropertyType.js +25 -0
  200. package/src/rules/requireReturns.js +238 -0
  201. package/src/rules/requireReturnsCheck.js +145 -0
  202. package/src/rules/requireReturnsDescription.js +59 -0
  203. package/src/rules/requireReturnsType.js +51 -0
  204. package/src/rules/requireTemplate.js +201 -0
  205. package/src/rules/requireThrows.js +111 -0
  206. package/src/rules/requireYields.js +216 -0
  207. package/src/rules/requireYieldsCheck.js +208 -0
  208. package/src/rules/sortTags.js +558 -0
  209. package/src/rules/tagLines.js +359 -0
  210. package/src/rules/textEscaping.js +154 -0
  211. package/src/rules/validTypes.js +401 -0
  212. package/src/tagNames.js +238 -0
  213. package/src/utils/hasReturnValue.js +572 -0
  214. package/dist/WarnSettings.js +0 -20
  215. package/dist/WarnSettings.js.map +0 -1
  216. package/dist/_virtual/rolldown_runtime.cjs +0 -32
  217. package/dist/_virtual/rolldown_runtime.js +0 -11
  218. package/dist/alignTransform.js +0 -241
  219. package/dist/alignTransform.js.map +0 -1
  220. package/dist/defaultTagOrder.js +0 -134
  221. package/dist/defaultTagOrder.js.map +0 -1
  222. package/dist/exportParser.js +0 -518
  223. package/dist/exportParser.js.map +0 -1
  224. package/dist/getDefaultTagStructureForMode.js +0 -188
  225. package/dist/getDefaultTagStructureForMode.js.map +0 -1
  226. package/dist/getJsdocProcessorPlugin.d.cts +0 -70
  227. package/dist/getJsdocProcessorPlugin.d.cts.map +0 -1
  228. package/dist/getJsdocProcessorPlugin.js +0 -383
  229. package/dist/getJsdocProcessorPlugin.js.map +0 -1
  230. package/dist/index.d.cts +0 -2
  231. package/dist/index.js +0 -3
  232. package/dist/iterateJsdoc.d.cts +0 -472
  233. package/dist/iterateJsdoc.d.cts.map +0 -1
  234. package/dist/iterateJsdoc.js +0 -1628
  235. package/dist/iterateJsdoc.js.map +0 -1
  236. package/dist/jsdocUtils.js +0 -1123
  237. package/dist/jsdocUtils.js.map +0 -1
  238. package/dist/plugin.cjs +0 -427
  239. package/dist/plugin.cjs.map +0 -1
  240. package/dist/plugin.js +0 -427
  241. package/dist/plugin.js.map +0 -1
  242. package/dist/rules/checkAccess.js +0 -33
  243. package/dist/rules/checkAccess.js.map +0 -1
  244. package/dist/rules/checkAlignment.js +0 -47
  245. package/dist/rules/checkAlignment.js.map +0 -1
  246. package/dist/rules/checkExamples.js +0 -348
  247. package/dist/rules/checkExamples.js.map +0 -1
  248. package/dist/rules/checkIndentation.js +0 -59
  249. package/dist/rules/checkIndentation.js.map +0 -1
  250. package/dist/rules/checkLineAlignment.js +0 -229
  251. package/dist/rules/checkLineAlignment.js.map +0 -1
  252. package/dist/rules/checkParamNames.js +0 -237
  253. package/dist/rules/checkParamNames.js.map +0 -1
  254. package/dist/rules/checkPropertyNames.js +0 -88
  255. package/dist/rules/checkPropertyNames.js.map +0 -1
  256. package/dist/rules/checkSyntax.js +0 -25
  257. package/dist/rules/checkSyntax.js.map +0 -1
  258. package/dist/rules/checkTagNames.js +0 -191
  259. package/dist/rules/checkTagNames.js.map +0 -1
  260. package/dist/rules/checkTemplateNames.js +0 -124
  261. package/dist/rules/checkTemplateNames.js.map +0 -1
  262. package/dist/rules/checkTypes.js +0 -299
  263. package/dist/rules/checkTypes.js.map +0 -1
  264. package/dist/rules/checkValues.js +0 -103
  265. package/dist/rules/checkValues.js.map +0 -1
  266. package/dist/rules/convertToJsdocComments.js +0 -231
  267. package/dist/rules/convertToJsdocComments.js.map +0 -1
  268. package/dist/rules/emptyTags.js +0 -67
  269. package/dist/rules/emptyTags.js.map +0 -1
  270. package/dist/rules/implementsOnClasses.js +0 -40
  271. package/dist/rules/implementsOnClasses.js.map +0 -1
  272. package/dist/rules/importsAsDependencies.js +0 -68
  273. package/dist/rules/importsAsDependencies.js.map +0 -1
  274. package/dist/rules/informativeDocs.js +0 -110
  275. package/dist/rules/informativeDocs.js.map +0 -1
  276. package/dist/rules/linesBeforeBlock.js +0 -75
  277. package/dist/rules/linesBeforeBlock.js.map +0 -1
  278. package/dist/rules/matchDescription.js +0 -167
  279. package/dist/rules/matchDescription.js.map +0 -1
  280. package/dist/rules/matchName.js +0 -77
  281. package/dist/rules/matchName.js.map +0 -1
  282. package/dist/rules/multilineBlocks.js +0 -245
  283. package/dist/rules/multilineBlocks.js.map +0 -1
  284. package/dist/rules/noBadBlocks.js +0 -68
  285. package/dist/rules/noBadBlocks.js.map +0 -1
  286. package/dist/rules/noBlankBlockDescriptions.js +0 -41
  287. package/dist/rules/noBlankBlockDescriptions.js.map +0 -1
  288. package/dist/rules/noBlankBlocks.js +0 -30
  289. package/dist/rules/noBlankBlocks.js.map +0 -1
  290. package/dist/rules/noDefaults.js +0 -56
  291. package/dist/rules/noDefaults.js.map +0 -1
  292. package/dist/rules/noMissingSyntax.js +0 -126
  293. package/dist/rules/noMissingSyntax.js.map +0 -1
  294. package/dist/rules/noMultiAsterisks.js +0 -58
  295. package/dist/rules/noMultiAsterisks.js.map +0 -1
  296. package/dist/rules/noRestrictedSyntax.js +0 -49
  297. package/dist/rules/noRestrictedSyntax.js.map +0 -1
  298. package/dist/rules/noTypes.js +0 -65
  299. package/dist/rules/noTypes.js.map +0 -1
  300. package/dist/rules/noUndefinedTypes.js +0 -303
  301. package/dist/rules/noUndefinedTypes.js.map +0 -1
  302. package/dist/rules/requireAsteriskPrefix.js +0 -112
  303. package/dist/rules/requireAsteriskPrefix.js.map +0 -1
  304. package/dist/rules/requireDescription.js +0 -95
  305. package/dist/rules/requireDescription.js.map +0 -1
  306. package/dist/rules/requireDescriptionCompleteSentence.js +0 -220
  307. package/dist/rules/requireDescriptionCompleteSentence.js.map +0 -1
  308. package/dist/rules/requireExample.js +0 -77
  309. package/dist/rules/requireExample.js.map +0 -1
  310. package/dist/rules/requireFileOverview.js +0 -81
  311. package/dist/rules/requireFileOverview.js.map +0 -1
  312. package/dist/rules/requireHyphenBeforeParamDescription.js +0 -89
  313. package/dist/rules/requireHyphenBeforeParamDescription.js.map +0 -1
  314. package/dist/rules/requireJsdoc.js +0 -404
  315. package/dist/rules/requireJsdoc.js.map +0 -1
  316. package/dist/rules/requireParam.js +0 -344
  317. package/dist/rules/requireParam.js.map +0 -1
  318. package/dist/rules/requireParamDescription.js +0 -59
  319. package/dist/rules/requireParamDescription.js.map +0 -1
  320. package/dist/rules/requireParamName.js +0 -36
  321. package/dist/rules/requireParamName.js.map +0 -1
  322. package/dist/rules/requireParamType.js +0 -59
  323. package/dist/rules/requireParamType.js.map +0 -1
  324. package/dist/rules/requireProperty.js +0 -35
  325. package/dist/rules/requireProperty.js.map +0 -1
  326. package/dist/rules/requirePropertyDescription.js +0 -21
  327. package/dist/rules/requirePropertyDescription.js.map +0 -1
  328. package/dist/rules/requirePropertyName.js +0 -21
  329. package/dist/rules/requirePropertyName.js.map +0 -1
  330. package/dist/rules/requirePropertyType.js +0 -21
  331. package/dist/rules/requirePropertyType.js.map +0 -1
  332. package/dist/rules/requireReturns.js +0 -131
  333. package/dist/rules/requireReturns.js.map +0 -1
  334. package/dist/rules/requireReturnsCheck.js +0 -66
  335. package/dist/rules/requireReturnsCheck.js.map +0 -1
  336. package/dist/rules/requireReturnsDescription.js +0 -43
  337. package/dist/rules/requireReturnsDescription.js.map +0 -1
  338. package/dist/rules/requireReturnsType.js +0 -36
  339. package/dist/rules/requireReturnsType.js.map +0 -1
  340. package/dist/rules/requireTemplate.js +0 -122
  341. package/dist/rules/requireTemplate.js.map +0 -1
  342. package/dist/rules/requireThrows.js +0 -67
  343. package/dist/rules/requireThrows.js.map +0 -1
  344. package/dist/rules/requireYields.js +0 -115
  345. package/dist/rules/requireYields.js.map +0 -1
  346. package/dist/rules/requireYieldsCheck.js +0 -105
  347. package/dist/rules/requireYieldsCheck.js.map +0 -1
  348. package/dist/rules/sortTags.js +0 -262
  349. package/dist/rules/sortTags.js.map +0 -1
  350. package/dist/rules/tagLines.js +0 -183
  351. package/dist/rules/tagLines.js.map +0 -1
  352. package/dist/rules/textEscaping.js +0 -102
  353. package/dist/rules/textEscaping.js.map +0 -1
  354. package/dist/rules/validTypes.js +0 -259
  355. package/dist/rules/validTypes.js.map +0 -1
  356. package/dist/tagNames.js +0 -144
  357. package/dist/tagNames.js.map +0 -1
  358. package/dist/utils/hasReturnValue.js +0 -265
  359. package/dist/utils/hasReturnValue.js.map +0 -1
@@ -1,1628 +0,0 @@
1
- import { hasValueOrExecutorHasNonEmptyResolveValue } from "./utils/hasReturnValue.js";
2
- import { comparePaths, dropPathSegmentQuotes, enforcedContexts, exemptSpeciaMethods, filterTags, flattenRoots, forEachPreferredTag, getAllTags, getContextObject, getFunctionParameterNames, getJsdocTagsDeep, getPreferredTagName, getPreferredTagNameSimple, getRegexFromString, getTagDescription, getTagStructureForMode, getTags, getTagsByType, hasATag, hasParams, hasTag, hasThrowValue, hasYieldValue, isConstructor, isValidTag, jsdocUtils_exports, mayBeUndefinedTypeTag, overrideTagStructure, parseClosureTemplateTag, pathDoesNotBeginWith, setTagStructure, tagMissingRequiredTypeOrNamepath } from "./jsdocUtils.js";
3
- import { commentHandler, getJSDocComment, parseComment, parseComment as parseComment$1 } from "@es-joy/jsdoccomment";
4
- import { stringify as stringify$1, util } from "comment-parser";
5
- import esquery from "esquery";
6
-
7
- //#region src/iterateJsdoc.js
8
- /**
9
- * @typedef {number} Integer
10
- */
11
- /**
12
- * @typedef {import('@es-joy/jsdoccomment').JsdocBlockWithInline} JsdocBlockWithInline
13
- */
14
- /**
15
- * @typedef {{
16
- * disallowName?: string,
17
- * allowName?: string,
18
- * context?: string,
19
- * comment?: string,
20
- * tags?: string[],
21
- * replacement?: string,
22
- * minimum?: Integer,
23
- * message?: string,
24
- * forceRequireReturn?: boolean
25
- * }} ContextObject
26
- */
27
- /**
28
- * @typedef {string|ContextObject} Context
29
- */
30
- /**
31
- * @callback CheckJsdoc
32
- * @param {{
33
- * lastIndex?: Integer,
34
- * isFunctionContext?: boolean,
35
- * selector?: string,
36
- * comment?: string
37
- * }} info
38
- * @param {null|((jsdoc: import('@es-joy/jsdoccomment').JsdocBlockWithInline) => boolean|undefined)} handler
39
- * @param {import('eslint').Rule.Node} node
40
- * @returns {void}
41
- */
42
- /**
43
- * @callback ForEachPreferredTag
44
- * @param {string} tagName
45
- * @param {(
46
- * matchingJsdocTag: import('@es-joy/jsdoccomment').JsdocTagWithInline,
47
- * targetTagName: string
48
- * ) => void} arrayHandler
49
- * @param {boolean} [skipReportingBlockedTag]
50
- * @returns {void}
51
- */
52
- /**
53
- * @callback ReportSettings
54
- * @param {string} message
55
- * @returns {void}
56
- */
57
- /**
58
- * @callback ParseClosureTemplateTag
59
- * @param {import('comment-parser').Spec} tag
60
- * @returns {string[]}
61
- */
62
- /**
63
- * @callback GetPreferredTagNameObject
64
- * @param {{
65
- * tagName: string
66
- * }} cfg
67
- * @returns {string|false|{
68
- * message: string;
69
- * replacement?: string|undefined
70
- * }|{
71
- * blocked: true,
72
- * tagName: string
73
- * }}
74
- */
75
- /**
76
- * @typedef {{
77
- * forEachPreferredTag: ForEachPreferredTag,
78
- * reportSettings: ReportSettings,
79
- * parseClosureTemplateTag: ParseClosureTemplateTag,
80
- * getPreferredTagNameObject: GetPreferredTagNameObject,
81
- * pathDoesNotBeginWith: import('./jsdocUtils.js').PathDoesNotBeginWith
82
- * }} BasicUtils
83
- */
84
- /**
85
- * @callback IsIteratingFunction
86
- * @returns {boolean}
87
- */
88
- /**
89
- * @callback IsVirtualFunction
90
- * @returns {boolean}
91
- */
92
- /**
93
- * @callback Stringify
94
- * @param {import('comment-parser').Block} tagBlock
95
- * @param {boolean} [specRewire]
96
- * @returns {string}
97
- */
98
- /**
99
- * @callback ReportJSDoc
100
- * @param {string} msg
101
- * @param {null|import('comment-parser').Spec|{line: Integer, column?: Integer}} [tag]
102
- * @param {(() => void)|null} [handler]
103
- * @param {boolean} [specRewire]
104
- * @param {undefined|{
105
- * [key: string]: string
106
- * }} [data]
107
- */
108
- /**
109
- * @callback GetRegexFromString
110
- * @param {string} str
111
- * @param {string} [requiredFlags]
112
- * @returns {RegExp}
113
- */
114
- /**
115
- * @callback GetTagDescription
116
- * @param {import('comment-parser').Spec} tg
117
- * @param {boolean} [returnArray]
118
- * @returns {string[]|string}
119
- */
120
- /**
121
- * @callback SetTagDescription
122
- * @param {import('comment-parser').Spec} tg
123
- * @param {RegExp} matcher
124
- * @param {(description: string) => string} setter
125
- * @returns {Integer}
126
- */
127
- /**
128
- * @callback GetDescription
129
- * @returns {{
130
- * description: string,
131
- * descriptions: string[],
132
- * lastDescriptionLine: Integer
133
- * }}
134
- */
135
- /**
136
- * @callback SetBlockDescription
137
- * @param {(
138
- * info: {
139
- * delimiter: string,
140
- * postDelimiter: string,
141
- * start: string
142
- * },
143
- * seedTokens: (
144
- * tokens?: Partial<import('comment-parser').Tokens>
145
- * ) => import('comment-parser').Tokens,
146
- * descLines: string[]
147
- * ) => import('comment-parser').Line[]} setter
148
- * @returns {void}
149
- */
150
- /**
151
- * @callback SetDescriptionLines
152
- * @param {RegExp} matcher
153
- * @param {(description: string) => string} setter
154
- * @returns {Integer}
155
- */
156
- /**
157
- * @callback ChangeTag
158
- * @param {import('comment-parser').Spec} tag
159
- * @param {...Partial<import('comment-parser').Tokens>} tokens
160
- * @returns {void}
161
- */
162
- /**
163
- * @callback SetTag
164
- * @param {import('comment-parser').Spec & {
165
- * line: Integer
166
- * }} tag
167
- * @param {Partial<import('comment-parser').Tokens>} [tokens]
168
- * @returns {void}
169
- */
170
- /**
171
- * @callback RemoveTag
172
- * @param {Integer} tagIndex
173
- * @param {{
174
- * removeEmptyBlock?: boolean,
175
- * tagSourceOffset?: Integer
176
- * }} [cfg]
177
- * @returns {void}
178
- */
179
- /**
180
- * @callback AddTag
181
- * @param {string} targetTagName
182
- * @param {Integer} [number]
183
- * @param {import('comment-parser').Tokens|{}} [tokens]
184
- * @returns {void}
185
- */
186
- /**
187
- * @callback GetFirstLine
188
- * @returns {Integer|undefined}
189
- */
190
- /**
191
- * @typedef {(
192
- * tokens?: Partial<import('comment-parser').Tokens> | undefined
193
- * ) => import('comment-parser').Tokens} SeedTokens
194
- */
195
- /**
196
- * Sets tokens to empty string.
197
- * @callback EmptyTokens
198
- * @param {import('comment-parser').Tokens} tokens
199
- * @returns {void}
200
- */
201
- /**
202
- * @callback AddLine
203
- * @param {Integer} sourceIndex
204
- * @param {Partial<import('comment-parser').Tokens>} tokens
205
- * @returns {void}
206
- */
207
- /**
208
- * @callback AddLines
209
- * @param {Integer} tagIndex
210
- * @param {Integer} tagSourceOffset
211
- * @param {Integer} numLines
212
- * @returns {void}
213
- */
214
- /**
215
- * @callback MakeMultiline
216
- * @returns {void}
217
- */
218
- /**
219
- * @callback GetFunctionParameterNames
220
- * @param {boolean} [useDefaultObjectProperties]
221
- * @returns {import('./jsdocUtils.js').ParamNameInfo[]}
222
- */
223
- /**
224
- * @callback HasParams
225
- * @returns {Integer}
226
- */
227
- /**
228
- * @callback IsGenerator
229
- * @returns {boolean}
230
- */
231
- /**
232
- * @callback IsConstructor
233
- * @returns {boolean}
234
- */
235
- /**
236
- * @callback GetJsdocTagsDeep
237
- * @param {string} tagName
238
- * @returns {false|{
239
- * idx: Integer,
240
- * name: string,
241
- * type: string
242
- * }[]}
243
- */
244
- /**
245
- * @callback GetPreferredTagName
246
- * @param {{
247
- * tagName: string,
248
- * skipReportingBlockedTag?: boolean,
249
- * allowObjectReturn?: boolean,
250
- * defaultMessage?: string
251
- * }} cfg
252
- * @returns {string|undefined|false|{
253
- * message: string;
254
- * replacement?: string|undefined;
255
- * }|{
256
- * blocked: true,
257
- * tagName: string
258
- * }}
259
- */
260
- /**
261
- * @callback IsValidTag
262
- * @param {string} name
263
- * @param {string[]} definedTags
264
- * @returns {boolean}
265
- */
266
- /**
267
- * @callback HasATag
268
- * @param {string[]} names
269
- * @returns {boolean}
270
- */
271
- /**
272
- * @callback HasTag
273
- * @param {string} name
274
- * @returns {boolean}
275
- */
276
- /**
277
- * @callback ComparePaths
278
- * @param {string} name
279
- * @returns {(otherPathName: string) => boolean}
280
- */
281
- /**
282
- * @callback DropPathSegmentQuotes
283
- * @param {string} name
284
- * @returns {string}
285
- */
286
- /**
287
- * @callback AvoidDocs
288
- * @returns {boolean}
289
- */
290
- /**
291
- * @callback TagMightHaveNamePositionTypePosition
292
- * @param {string} tagName
293
- * @param {import('./getDefaultTagStructureForMode.js').
294
- * TagStructure[]} [otherModeMaps]
295
- * @returns {boolean|{otherMode: true}}
296
- */
297
- /**
298
- * @callback TagMustHave
299
- * @param {string} tagName
300
- * @param {import('./getDefaultTagStructureForMode.js').
301
- * TagStructure[]} otherModeMaps
302
- * @returns {boolean|{
303
- * otherMode: false
304
- * }}
305
- */
306
- /**
307
- * @callback TagMissingRequiredTypeOrNamepath
308
- * @param {import('comment-parser').Spec} tag
309
- * @param {import('./getDefaultTagStructureForMode.js').
310
- * TagStructure[]} otherModeMaps
311
- * @returns {boolean|{
312
- * otherMode: false
313
- * }}
314
- */
315
- /**
316
- * @callback IsNamepathX
317
- * @param {string} tagName
318
- * @returns {boolean}
319
- */
320
- /**
321
- * @callback GetTagStructureForMode
322
- * @param {import('./jsdocUtils.js').ParserMode} mde
323
- * @returns {import('./getDefaultTagStructureForMode.js').TagStructure}
324
- */
325
- /**
326
- * @callback MayBeUndefinedTypeTag
327
- * @param {import('comment-parser').Spec} tag
328
- * @returns {boolean}
329
- */
330
- /**
331
- * @callback HasValueOrExecutorHasNonEmptyResolveValue
332
- * @param {boolean} anyPromiseAsReturn
333
- * @param {boolean} [allBranches]
334
- * @returns {boolean}
335
- */
336
- /**
337
- * @callback HasYieldValue
338
- * @returns {boolean}
339
- */
340
- /**
341
- * @callback HasYieldReturnValue
342
- * @returns {boolean}
343
- */
344
- /**
345
- * @callback HasThrowValue
346
- * @returns {boolean}
347
- */
348
- /**
349
- * @callback IsAsync
350
- * @returns {boolean|undefined}
351
- */
352
- /**
353
- * @callback GetTags
354
- * @param {string} tagName
355
- * @returns {import('comment-parser').Spec[]}
356
- */
357
- /**
358
- * @callback GetPresentTags
359
- * @param {string[]} tagList
360
- * @returns {import('@es-joy/jsdoccomment').JsdocTagWithInline[]}
361
- */
362
- /**
363
- * @callback FilterTags
364
- * @param {(tag: import('@es-joy/jsdoccomment').JsdocTagWithInline) => boolean} filter
365
- * @returns {import('@es-joy/jsdoccomment').JsdocTagWithInline[]}
366
- */
367
- /**
368
- * @callback FilterAllTags
369
- * @param {(tag: (import('comment-parser').Spec|
370
- * import('@es-joy/jsdoccomment').JsdocInlineTagNoType)) => boolean} filter
371
- * @returns {(import('comment-parser').Spec|
372
- * import('@es-joy/jsdoccomment').JsdocInlineTagNoType)[]}
373
- */
374
- /**
375
- * @callback GetTagsByType
376
- * @param {import('comment-parser').Spec[]} tags
377
- * @returns {{
378
- * tagsWithNames: import('comment-parser').Spec[],
379
- * tagsWithoutNames: import('comment-parser').Spec[]
380
- * }}
381
- */
382
- /**
383
- * @callback HasOptionTag
384
- * @param {string} tagName
385
- * @returns {boolean}
386
- */
387
- /**
388
- * @callback GetClassNode
389
- * @returns {Node|null}
390
- */
391
- /**
392
- * @callback GetClassJsdoc
393
- * @returns {null|JsdocBlockWithInline}
394
- */
395
- /**
396
- * @callback ClassHasTag
397
- * @param {string} tagName
398
- * @returns {boolean}
399
- */
400
- /**
401
- * @callback FindContext
402
- * @param {Context[]} contexts
403
- * @param {string|undefined} comment
404
- * @returns {{
405
- * foundContext: Context|undefined,
406
- * contextStr: string
407
- * }}
408
- */
409
- /**
410
- * @typedef {BasicUtils & {
411
- * isIteratingFunction: IsIteratingFunction,
412
- * isIteratingFunctionOrVariable: IsIteratingFunction,
413
- * isVirtualFunction: IsVirtualFunction,
414
- * stringify: Stringify,
415
- * reportJSDoc: ReportJSDoc,
416
- * getRegexFromString: GetRegexFromString,
417
- * getTagDescription: GetTagDescription,
418
- * setTagDescription: SetTagDescription,
419
- * getDescription: GetDescription,
420
- * setBlockDescription: SetBlockDescription,
421
- * setDescriptionLines: SetDescriptionLines,
422
- * changeTag: ChangeTag,
423
- * setTag: SetTag,
424
- * removeTag: RemoveTag,
425
- * addTag: AddTag,
426
- * getFirstLine: GetFirstLine,
427
- * seedTokens: SeedTokens,
428
- * emptyTokens: EmptyTokens,
429
- * addLine: AddLine,
430
- * addLines: AddLines,
431
- * makeMultiline: MakeMultiline,
432
- * flattenRoots: import('./jsdocUtils.js').FlattenRoots,
433
- * getFunctionParameterNames: GetFunctionParameterNames,
434
- * hasParams: HasParams,
435
- * isGenerator: IsGenerator,
436
- * isConstructor: IsConstructor,
437
- * getJsdocTagsDeep: GetJsdocTagsDeep,
438
- * getPreferredTagName: GetPreferredTagName,
439
- * isValidTag: IsValidTag,
440
- * hasATag: HasATag,
441
- * hasTag: HasTag,
442
- * comparePaths: ComparePaths,
443
- * dropPathSegmentQuotes: DropPathSegmentQuotes,
444
- * avoidDocs: AvoidDocs,
445
- * tagMightHaveNamePosition: TagMightHaveNamePositionTypePosition,
446
- * tagMightHaveTypePosition: TagMightHaveNamePositionTypePosition,
447
- * tagMustHaveNamePosition: TagMustHave,
448
- * tagMustHaveTypePosition: TagMustHave,
449
- * tagMissingRequiredTypeOrNamepath: TagMissingRequiredTypeOrNamepath,
450
- * isNamepathDefiningTag: IsNamepathX,
451
- * isNamepathReferencingTag: IsNamepathX,
452
- * isNamepathOrUrlReferencingTag: IsNamepathX,
453
- * tagMightHaveNamepath: IsNamepathX,
454
- * getTagStructureForMode: GetTagStructureForMode,
455
- * mayBeUndefinedTypeTag: MayBeUndefinedTypeTag,
456
- * hasValueOrExecutorHasNonEmptyResolveValue: HasValueOrExecutorHasNonEmptyResolveValue,
457
- * hasYieldValue: HasYieldValue,
458
- * hasYieldReturnValue: HasYieldReturnValue,
459
- * hasThrowValue: HasThrowValue,
460
- * isAsync: IsAsync,
461
- * getTags: GetTags,
462
- * getPresentTags: GetPresentTags,
463
- * filterTags: FilterTags,
464
- * filterAllTags: FilterAllTags,
465
- * getTagsByType: GetTagsByType,
466
- * hasOptionTag: HasOptionTag,
467
- * getClassNode: GetClassNode,
468
- * getClassJsdoc: GetClassJsdoc,
469
- * classHasTag: ClassHasTag,
470
- * findContext: FindContext
471
- * }} Utils
472
- */
473
- const { rewireSpecs, seedTokens } = util;
474
- /**
475
- * Should use ESLint rule's typing.
476
- * @typedef {import('eslint').Rule.RuleMetaData} EslintRuleMeta
477
- */
478
- /**
479
- * A plain object for tracking state as needed by rules across iterations.
480
- * @typedef {{
481
- * globalTags: {},
482
- * hasDuplicates: {
483
- * [key: string]: boolean
484
- * },
485
- * selectorMap: {
486
- * [selector: string]: {
487
- * [comment: string]: Integer
488
- * }
489
- * },
490
- * hasTag: {
491
- * [key: string]: boolean
492
- * },
493
- * hasNonComment: number,
494
- * hasNonCommentBeforeTag: {
495
- * [key: string]: boolean|number
496
- * }
497
- * }} StateObject
498
- */
499
- /**
500
- * The Node AST as supplied by the parser.
501
- * @typedef {import('eslint').Rule.Node} Node
502
- */
503
- const globalState = /* @__PURE__ */ new Map();
504
- /**
505
- * @param {import('eslint').Rule.RuleContext} context
506
- * @param {{
507
- * tagNamePreference?: import('./jsdocUtils.js').TagNamePreference,
508
- * mode?: import('./jsdocUtils.js').ParserMode
509
- * }} cfg
510
- * @returns {BasicUtils}
511
- */
512
- const getBasicUtils = (context, { mode, tagNamePreference }) => {
513
- /** @type {BasicUtils} */
514
- const utils = {};
515
- /** @type {ReportSettings} */
516
- utils.reportSettings = (message) => {
517
- context.report({
518
- loc: {
519
- end: {
520
- column: 1,
521
- line: 1
522
- },
523
- start: {
524
- column: 1,
525
- line: 1
526
- }
527
- },
528
- message
529
- });
530
- };
531
- /** @type {ParseClosureTemplateTag} */
532
- utils.parseClosureTemplateTag = (tag) => {
533
- return parseClosureTemplateTag(tag);
534
- };
535
- utils.pathDoesNotBeginWith = pathDoesNotBeginWith;
536
- /** @type {GetPreferredTagNameObject} */
537
- utils.getPreferredTagNameObject = ({ tagName }) => {
538
- const ret = getPreferredTagNameSimple(tagName, mode, tagNamePreference, context);
539
- const isObject = ret && typeof ret === "object";
540
- if (ret === false || isObject && !ret.replacement) return {
541
- blocked: true,
542
- tagName
543
- };
544
- return ret;
545
- };
546
- return utils;
547
- };
548
- /**
549
- * @callback Report
550
- * @param {string} message
551
- * @param {import('eslint').Rule.ReportFixer|null} [fix]
552
- * @param {null|
553
- * {line?: Integer, column?: Integer}|
554
- * import('comment-parser').Spec & {line?: Integer}
555
- * } [jsdocLoc]
556
- * @param {undefined|{
557
- * [key: string]: string
558
- * }} [data]
559
- * @returns {void}
560
- */
561
- /**
562
- * @param {Node|null} node
563
- * @param {JsdocBlockWithInline} jsdoc
564
- * @param {import('eslint').AST.Token} jsdocNode
565
- * @param {Settings} settings
566
- * @param {Report} report
567
- * @param {import('eslint').Rule.RuleContext} context
568
- * @param {import('eslint').SourceCode} sc
569
- * @param {boolean|undefined} iteratingAll
570
- * @param {RuleConfig} ruleConfig
571
- * @param {string} indent
572
- * @returns {Utils}
573
- */
574
- const getUtils = (node, jsdoc, jsdocNode, settings, report, context, sc, iteratingAll, ruleConfig, indent) => {
575
- const ancestors = node ? sc.getAncestors ? sc.getAncestors(node) : context.getAncestors() : [];
576
- /* c8 ignore next -- Fallback to deprecated method */
577
- const { sourceCode = context.getSourceCode() } = context;
578
- const utils = getBasicUtils(context, settings);
579
- const { augmentsExtendsReplacesDocs, ignoreReplacesDocs, implementsReplacesDocs, maxLines, minLines, mode, overrideReplacesDocs, tagNamePreference } = settings;
580
- const functionTypes = [
581
- "ArrowFunctionExpression",
582
- "FunctionDeclaration",
583
- "FunctionExpression",
584
- "MethodDefinition"
585
- ];
586
- /** @type {IsIteratingFunction} */
587
- utils.isIteratingFunction = () => {
588
- return !iteratingAll || functionTypes.includes(String(node?.type));
589
- };
590
- /** @type {IsIteratingFunction} */
591
- utils.isIteratingFunctionOrVariable = () => {
592
- if (utils.isIteratingFunction()) return true;
593
- /** @type {import('estree').VariableDeclarator[]} */
594
- const declarations = node?.type === "VariableDeclaration" ? node.declarations : node?.type === "ExportNamedDeclaration" && node.declaration?.type === "VariableDeclaration" ? node.declaration.declarations : [];
595
- return declarations.some(({ init }) => {
596
- return functionTypes.includes(String(init?.type));
597
- });
598
- };
599
- /** @type {IsVirtualFunction} */
600
- utils.isVirtualFunction = () => {
601
- return Boolean(iteratingAll) && utils.hasATag([
602
- "callback",
603
- "function",
604
- "func",
605
- "method"
606
- ]);
607
- };
608
- /** @type {Stringify} */
609
- utils.stringify = (tagBlock, specRewire) => {
610
- let block;
611
- if (specRewire) block = rewireSpecs(tagBlock);
612
- return stringify$1(specRewire ? block : tagBlock);
613
- };
614
- /** @type {ReportJSDoc} */
615
- utils.reportJSDoc = (msg, tag, handler, specRewire, data) => {
616
- report(msg, handler ? (fixer) => {
617
- handler();
618
- const replacement = utils.stringify(jsdoc, specRewire);
619
- if (!replacement) {
620
- const text = sourceCode.getText();
621
- const lastLineBreakPos = text.slice(0, jsdocNode.range[0]).search(/\n[ \t]*$/v);
622
- if (lastLineBreakPos > -1) return fixer.removeRange([lastLineBreakPos, jsdocNode.range[1]]);
623
- return fixer.removeRange(/\s/v.test(text.charAt(jsdocNode.range[1])) ? [jsdocNode.range[0], jsdocNode.range[1] + 1] : jsdocNode.range);
624
- }
625
- return fixer.replaceText(jsdocNode, replacement);
626
- } : null, tag, data);
627
- };
628
- /** @type {GetRegexFromString} */
629
- utils.getRegexFromString = (str, requiredFlags) => {
630
- return getRegexFromString(str, requiredFlags);
631
- };
632
- /** @type {GetTagDescription} */
633
- utils.getTagDescription = (tg, returnArray) => {
634
- return getTagDescription(tg, returnArray);
635
- };
636
- /** @type {SetTagDescription} */
637
- utils.setTagDescription = (tg, matcher, setter) => {
638
- let finalIdx = 0;
639
- tg.source.some(({ tokens: { description } }, idx) => {
640
- if (description && matcher.test(description)) {
641
- tg.source[idx].tokens.description = setter(description);
642
- finalIdx = idx;
643
- return true;
644
- }
645
- return false;
646
- });
647
- return finalIdx;
648
- };
649
- /** @type {GetDescription} */
650
- utils.getDescription = () => {
651
- /** @type {string[]} */
652
- const descriptions = [];
653
- let lastDescriptionLine = 0;
654
- let tagsBegun = false;
655
- jsdoc.source.some(({ tokens: { description, end, tag } }, idx) => {
656
- if (tag) tagsBegun = true;
657
- if (idx && (tag || end)) {
658
- lastDescriptionLine = idx - 1;
659
- if (!tagsBegun && description) descriptions.push(description);
660
- return true;
661
- }
662
- if (!tagsBegun && (idx || description)) descriptions.push(description || (descriptions.length ? "" : "\n"));
663
- return false;
664
- });
665
- return {
666
- description: descriptions.join("\n"),
667
- descriptions,
668
- lastDescriptionLine
669
- };
670
- };
671
- /** @type {SetBlockDescription} */
672
- utils.setBlockDescription = (setter) => {
673
- /** @type {string[]} */
674
- const descLines = [];
675
- /**
676
- * @type {undefined|Integer}
677
- */
678
- let startIdx;
679
- /**
680
- * @type {undefined|Integer}
681
- */
682
- let endIdx;
683
- /**
684
- * @type {undefined|{
685
- * delimiter: string,
686
- * postDelimiter: string,
687
- * start: string
688
- * }}
689
- */
690
- let info;
691
- jsdoc.source.some(({ tokens: { delimiter, description, end, postDelimiter, start, tag } }, idx) => {
692
- if (delimiter === "/**") return false;
693
- if (startIdx === void 0) {
694
- startIdx = idx;
695
- info = {
696
- delimiter,
697
- postDelimiter,
698
- start
699
- };
700
- }
701
- if (tag || end) {
702
- endIdx = idx;
703
- return true;
704
- }
705
- descLines.push(description);
706
- return false;
707
- });
708
- /* c8 ignore else -- Won't be called if missing */
709
- if (descLines.length) jsdoc.source.splice(
710
- startIdx,
711
- /** @type {Integer} */
712
- endIdx - startIdx,
713
- ...setter(info, seedTokens, descLines)
714
- );
715
- };
716
- /** @type {SetDescriptionLines} */
717
- utils.setDescriptionLines = (matcher, setter) => {
718
- let finalIdx = 0;
719
- jsdoc.source.some(({ tokens: { description, end, tag } }, idx) => {
720
- /* c8 ignore next 3 -- Already checked */
721
- if (idx && (tag || end)) return true;
722
- if (description && matcher.test(description)) {
723
- jsdoc.source[idx].tokens.description = setter(description);
724
- finalIdx = idx;
725
- return true;
726
- }
727
- return false;
728
- });
729
- return finalIdx;
730
- };
731
- /** @type {ChangeTag} */
732
- utils.changeTag = (tag, ...tokens) => {
733
- for (const [idx, src] of tag.source.entries()) src.tokens = {
734
- ...src.tokens,
735
- ...tokens[idx]
736
- };
737
- };
738
- /** @type {SetTag} */
739
- utils.setTag = (tag, tokens) => {
740
- tag.source = [{
741
- number: tag.line,
742
- source: "",
743
- tokens: seedTokens({
744
- delimiter: "*",
745
- postDelimiter: " ",
746
- start: indent + " ",
747
- tag: "@" + tag.tag,
748
- ...tokens
749
- })
750
- }];
751
- };
752
- /** @type {RemoveTag} */
753
- utils.removeTag = (tagIndex, { removeEmptyBlock = false, tagSourceOffset = 0 } = {}) => {
754
- const { source: tagSource } = jsdoc.tags[tagIndex];
755
- /** @type {Integer|undefined} */
756
- let lastIndex;
757
- const firstNumber = jsdoc.source[0].number;
758
- tagSource.some(({ number }, tagIdx) => {
759
- const sourceIndex = jsdoc.source.findIndex(({ number: srcNumber }) => {
760
- return number === srcNumber;
761
- });
762
- // c8 ignore else
763
- if (sourceIndex > -1) {
764
- let spliceCount = 1;
765
- tagSource.slice(tagIdx + 1).some(({ tokens: { end: ending, tag } }) => {
766
- if (!tag && !ending) {
767
- spliceCount++;
768
- return false;
769
- }
770
- return true;
771
- });
772
- const spliceIdx = sourceIndex + tagSourceOffset;
773
- const { delimiter, end } = jsdoc.source[spliceIdx].tokens;
774
- if (spliceIdx === 0 && jsdoc.tags.length >= 2 || !removeEmptyBlock && (end || delimiter === "/**")) {
775
- const { tokens } = jsdoc.source[spliceIdx];
776
- for (const item of [
777
- "postDelimiter",
778
- "tag",
779
- "postTag",
780
- "type",
781
- "postType",
782
- "name",
783
- "postName",
784
- "description"
785
- ]) tokens[item] = "";
786
- } else {
787
- jsdoc.source.splice(spliceIdx, spliceCount - tagSourceOffset + (spliceIdx ? 0 : jsdoc.source.length));
788
- tagSource.splice(tagIdx + tagSourceOffset, spliceCount - tagSourceOffset + (spliceIdx ? 0 : jsdoc.source.length));
789
- }
790
- lastIndex = sourceIndex;
791
- return true;
792
- }
793
- /* c8 ignore next 2 */
794
- return false;
795
- });
796
- for (const [idx, src] of jsdoc.source.slice(lastIndex).entries()) src.number = firstNumber + lastIndex + idx;
797
- };
798
- /** @type {AddTag} */
799
- utils.addTag = (targetTagName, number = (jsdoc.tags[jsdoc.tags.length - 1]?.source[0]?.number ?? jsdoc.source.findIndex(({ tokens: { tag } }) => {
800
- return tag;
801
- }) - 1) + 1, tokens = {}) => {
802
- jsdoc.source.splice(number, 0, {
803
- number,
804
- source: "",
805
- tokens: seedTokens({
806
- delimiter: "*",
807
- postDelimiter: " ",
808
- start: indent + " ",
809
- tag: `@${targetTagName}`,
810
- ...tokens
811
- })
812
- });
813
- for (const src of jsdoc.source.slice(number + 1)) src.number++;
814
- };
815
- /** @type {GetFirstLine} */
816
- utils.getFirstLine = () => {
817
- let firstLine;
818
- for (const { number, tokens: { tag } } of jsdoc.source) if (tag) {
819
- firstLine = number;
820
- break;
821
- }
822
- return firstLine;
823
- };
824
- /** @type {SeedTokens} */
825
- utils.seedTokens = seedTokens;
826
- /** @type {EmptyTokens} */
827
- utils.emptyTokens = (tokens) => {
828
- for (const prop of [
829
- "start",
830
- "postDelimiter",
831
- "tag",
832
- "type",
833
- "postType",
834
- "postTag",
835
- "name",
836
- "postName",
837
- "description",
838
- "end",
839
- "lineEnd"
840
- ]) tokens[prop] = "";
841
- };
842
- /** @type {AddLine} */
843
- utils.addLine = (sourceIndex, tokens) => {
844
- const number = (jsdoc.source[sourceIndex - 1]?.number || 0) + 1;
845
- jsdoc.source.splice(sourceIndex, 0, {
846
- number,
847
- source: "",
848
- tokens: seedTokens(tokens)
849
- });
850
- for (const src of jsdoc.source.slice(number + 1)) src.number++;
851
- };
852
- /** @type {AddLines} */
853
- utils.addLines = (tagIndex, tagSourceOffset, numLines) => {
854
- const { source: tagSource } = jsdoc.tags[tagIndex];
855
- /** @type {Integer|undefined} */
856
- let lastIndex;
857
- const firstNumber = jsdoc.source[0].number;
858
- tagSource.some(({ number }) => {
859
- const makeLine = () => {
860
- return {
861
- number,
862
- source: "",
863
- tokens: seedTokens({
864
- delimiter: "*",
865
- start: indent + " "
866
- })
867
- };
868
- };
869
- const makeLines = () => {
870
- return Array.from({ length: numLines }, makeLine);
871
- };
872
- const sourceIndex = jsdoc.source.findIndex(({ number: srcNumber, tokens: { end } }) => {
873
- return number === srcNumber && !end;
874
- });
875
- // c8 ignore else
876
- if (sourceIndex > -1) {
877
- const lines = makeLines();
878
- jsdoc.source.splice(sourceIndex + tagSourceOffset, 0, ...lines);
879
- lastIndex = sourceIndex;
880
- return true;
881
- }
882
- /* c8 ignore next 2 */
883
- return false;
884
- });
885
- for (const [idx, src] of jsdoc.source.slice(lastIndex).entries()) src.number = firstNumber + lastIndex + idx;
886
- };
887
- /** @type {MakeMultiline} */
888
- utils.makeMultiline = () => {
889
- const { source: [{ tokens }] } = jsdoc;
890
- const { description, lineEnd, name, postDelimiter, tag, type } = tokens;
891
- let { tokens: { postName, postTag, postType } } = jsdoc.source[0];
892
- if (!description) {
893
- if (postName) postName = "";
894
- else if (postType) postType = "";
895
- else if (postTag) postTag = "";
896
- }
897
- utils.emptyTokens(tokens);
898
- utils.addLine(1, {
899
- delimiter: "*",
900
- description: description.trimEnd(),
901
- name,
902
- postDelimiter,
903
- postName,
904
- postTag,
905
- postType,
906
- start: indent + " ",
907
- tag,
908
- type
909
- });
910
- utils.addLine(2, {
911
- end: "*/",
912
- lineEnd,
913
- start: indent + " "
914
- });
915
- };
916
- /**
917
- * @type {import('./jsdocUtils.js').FlattenRoots}
918
- */
919
- utils.flattenRoots = flattenRoots;
920
- /** @type {GetFunctionParameterNames} */
921
- utils.getFunctionParameterNames = (useDefaultObjectProperties) => {
922
- return getFunctionParameterNames(node, useDefaultObjectProperties);
923
- };
924
- /** @type {HasParams} */
925
- utils.hasParams = () => {
926
- return hasParams(node);
927
- };
928
- /** @type {IsGenerator} */
929
- utils.isGenerator = () => {
930
- return node !== null && Boolean(
931
- /**
932
- * @type {import('estree').FunctionDeclaration|
933
- * import('estree').FunctionExpression}
934
- */
935
- node.generator || node.type === "MethodDefinition" && node.value.generator || ["ExportDefaultDeclaration", "ExportNamedDeclaration"].includes(node.type) && node.declaration?.generator
936
- );
937
- };
938
- /** @type {IsConstructor} */
939
- utils.isConstructor = () => {
940
- return isConstructor(node);
941
- };
942
- /** @type {GetJsdocTagsDeep} */
943
- utils.getJsdocTagsDeep = (tagName) => {
944
- const name = utils.getPreferredTagName({ tagName });
945
- if (!name) return false;
946
- return getJsdocTagsDeep(jsdoc, name);
947
- };
948
- /** @type {GetPreferredTagName} */
949
- utils.getPreferredTagName = (args) => {
950
- return getPreferredTagName(jsdoc, {
951
- ...args,
952
- context,
953
- mode,
954
- report,
955
- tagNamePreference
956
- });
957
- };
958
- /** @type {IsValidTag} */
959
- utils.isValidTag = (name, definedTags) => {
960
- return isValidTag(context, mode, name, definedTags);
961
- };
962
- /** @type {HasATag} */
963
- utils.hasATag = (names) => {
964
- return hasATag(jsdoc, names);
965
- };
966
- /** @type {HasTag} */
967
- utils.hasTag = (name) => {
968
- return hasTag(jsdoc, name);
969
- };
970
- /** @type {ComparePaths} */
971
- utils.comparePaths = (name) => {
972
- return comparePaths(name);
973
- };
974
- /** @type {DropPathSegmentQuotes} */
975
- utils.dropPathSegmentQuotes = (name) => {
976
- return dropPathSegmentQuotes(name);
977
- };
978
- /** @type {AvoidDocs} */
979
- utils.avoidDocs = () => {
980
- 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"))) return true;
981
- if (exemptSpeciaMethods(jsdoc, node, context, ruleConfig.meta.schema)) return true;
982
- const exemptedBy = context.options[0]?.exemptedBy ?? ["inheritDoc", ...mode === "closure" ? [] : ["inheritdoc"]];
983
- if (exemptedBy.length && utils.getPresentTags(exemptedBy).length) return true;
984
- return false;
985
- };
986
- for (const method of ["tagMightHaveNamePosition", "tagMightHaveTypePosition"])
987
- /** @type {TagMightHaveNamePositionTypePosition} */
988
- utils[method] = (tagName, otherModeMaps) => {
989
- const result = jsdocUtils_exports[method](tagName);
990
- if (result) return true;
991
- if (!otherModeMaps) return false;
992
- const otherResult = otherModeMaps.some((otherModeMap) => {
993
- return jsdocUtils_exports[method](tagName, otherModeMap);
994
- });
995
- return otherResult ? { otherMode: true } : false;
996
- };
997
- /** @type {TagMissingRequiredTypeOrNamepath} */
998
- utils.tagMissingRequiredTypeOrNamepath = (tagName, otherModeMaps) => {
999
- const result = tagMissingRequiredTypeOrNamepath(tagName);
1000
- if (!result) return false;
1001
- const otherResult = otherModeMaps.every((otherModeMap) => {
1002
- return tagMissingRequiredTypeOrNamepath(tagName, otherModeMap);
1003
- });
1004
- return otherResult ? true : { otherMode: false };
1005
- };
1006
- for (const method of ["tagMustHaveNamePosition", "tagMustHaveTypePosition"])
1007
- /** @type {TagMustHave} */
1008
- utils[method] = (tagName, otherModeMaps) => {
1009
- const result = jsdocUtils_exports[method](tagName);
1010
- if (!result) return false;
1011
- const otherResult = otherModeMaps.every((otherModeMap) => {
1012
- return jsdocUtils_exports[method](tagName, otherModeMap);
1013
- });
1014
- return otherResult ? true : { otherMode: false };
1015
- };
1016
- for (const method of [
1017
- "isNamepathDefiningTag",
1018
- "isNamepathReferencingTag",
1019
- "isNamepathOrUrlReferencingTag",
1020
- "tagMightHaveNamepath"
1021
- ])
1022
- /** @type {IsNamepathX} */
1023
- utils[method] = (tagName) => {
1024
- return jsdocUtils_exports[method](tagName);
1025
- };
1026
- /** @type {GetTagStructureForMode} */
1027
- utils.getTagStructureForMode = (mde) => {
1028
- return getTagStructureForMode(mde, settings.structuredTags);
1029
- };
1030
- /** @type {MayBeUndefinedTypeTag} */
1031
- utils.mayBeUndefinedTypeTag = (tag) => {
1032
- return mayBeUndefinedTypeTag(tag, settings.mode);
1033
- };
1034
- /** @type {HasValueOrExecutorHasNonEmptyResolveValue} */
1035
- utils.hasValueOrExecutorHasNonEmptyResolveValue = (anyPromiseAsReturn, allBranches) => {
1036
- return hasValueOrExecutorHasNonEmptyResolveValue(node, anyPromiseAsReturn, allBranches);
1037
- };
1038
- /** @type {HasYieldValue} */
1039
- utils.hasYieldValue = () => {
1040
- if (["ExportDefaultDeclaration", "ExportNamedDeclaration"].includes(
1041
- /** @type {Node} */
1042
- node.type
1043
- )) return hasYieldValue(
1044
- /** @type {import('estree').ExportNamedDeclaration|import('estree').ExportDefaultDeclaration} */
1045
- node.declaration
1046
- );
1047
- return hasYieldValue(node);
1048
- };
1049
- /** @type {HasYieldReturnValue} */
1050
- utils.hasYieldReturnValue = () => {
1051
- return hasYieldValue(node, true);
1052
- };
1053
- /** @type {HasThrowValue} */
1054
- utils.hasThrowValue = () => {
1055
- return hasThrowValue(node);
1056
- };
1057
- /** @type {IsAsync} */
1058
- utils.isAsync = () => {
1059
- return Boolean(node && "async" in node && node.async);
1060
- };
1061
- /** @type {GetTags} */
1062
- utils.getTags = (tagName) => {
1063
- return getTags(jsdoc, tagName);
1064
- };
1065
- /** @type {GetPresentTags} */
1066
- utils.getPresentTags = (tagList) => {
1067
- return filterTags(jsdoc, (tag) => {
1068
- return tagList.includes(tag.tag);
1069
- });
1070
- };
1071
- /** @type {FilterTags} */
1072
- utils.filterTags = (filter) => {
1073
- return filterTags(jsdoc, (tag) => {
1074
- return filter(tag);
1075
- });
1076
- };
1077
- /** @type {FilterAllTags} */
1078
- utils.filterAllTags = (filter) => {
1079
- const tags = getAllTags(jsdoc);
1080
- return tags.filter((tag) => {
1081
- return filter(tag);
1082
- });
1083
- };
1084
- /** @type {GetTagsByType} */
1085
- utils.getTagsByType = (tags) => {
1086
- return getTagsByType(context, mode, tags);
1087
- };
1088
- /** @type {HasOptionTag} */
1089
- utils.hasOptionTag = (tagName) => {
1090
- const { tags } = context.options[0] ?? {};
1091
- return Boolean(tags && tags.includes(tagName));
1092
- };
1093
- /** @type {GetClassNode} */
1094
- utils.getClassNode = () => {
1095
- return [...ancestors, node].reverse().find((parent) => {
1096
- return parent && ["ClassDeclaration", "ClassExpression"].includes(parent.type);
1097
- }) ?? null;
1098
- };
1099
- /** @type {GetClassJsdoc} */
1100
- utils.getClassJsdoc = () => {
1101
- const classNode = utils.getClassNode();
1102
- if (!classNode) return null;
1103
- const classJsdocNode = getJSDocComment(sourceCode, classNode, {
1104
- maxLines,
1105
- minLines
1106
- });
1107
- if (classJsdocNode) return parseComment$1(classJsdocNode, "");
1108
- return null;
1109
- };
1110
- /** @type {ClassHasTag} */
1111
- utils.classHasTag = (tagName) => {
1112
- const classJsdoc = utils.getClassJsdoc();
1113
- return classJsdoc !== null && hasTag(classJsdoc, tagName);
1114
- };
1115
- /** @type {ForEachPreferredTag} */
1116
- utils.forEachPreferredTag = (tagName, arrayHandler, skipReportingBlockedTag) => {
1117
- return forEachPreferredTag(jsdoc, tagName, arrayHandler, {
1118
- context,
1119
- mode,
1120
- report,
1121
- skipReportingBlockedTag,
1122
- tagNamePreference
1123
- });
1124
- };
1125
- /** @type {FindContext} */
1126
- utils.findContext = (contexts, comment) => {
1127
- const foundContext = contexts.find((cntxt) => {
1128
- return typeof cntxt === "string" ? esquery.matches(node, esquery.parse(cntxt), void 0, { visitorKeys: sourceCode.visitorKeys }) : (!cntxt.context || cntxt.context === "any" || esquery.matches(node, esquery.parse(cntxt.context), void 0, { visitorKeys: sourceCode.visitorKeys })) && comment === cntxt.comment;
1129
- });
1130
- const contextStr = typeof foundContext === "object" ? foundContext.context ?? "any" : String(foundContext);
1131
- return {
1132
- contextStr,
1133
- foundContext
1134
- };
1135
- };
1136
- return utils;
1137
- };
1138
- /**
1139
- * @typedef {{
1140
- * [key: string]: false|string|{
1141
- * message: string,
1142
- * replacement?: false|string
1143
- * skipRootChecking?: boolean
1144
- * }
1145
- * }} PreferredTypes
1146
- */
1147
- /**
1148
- * @typedef {{
1149
- * [key: string]: {
1150
- * name?: "text"|"namepath-defining"|"namepath-referencing"|false,
1151
- * type?: boolean|string[],
1152
- * required?: ("name"|"type"|"typeOrNameRequired")[]
1153
- * }
1154
- * }} StructuredTags
1155
- */
1156
- /**
1157
- * Settings from ESLint types.
1158
- * @typedef {{
1159
- * maxLines: Integer,
1160
- * minLines: Integer,
1161
- * tagNamePreference: import('./jsdocUtils.js').TagNamePreference,
1162
- * mode: import('./jsdocUtils.js').ParserMode,
1163
- * preferredTypes: PreferredTypes,
1164
- * structuredTags: StructuredTags,
1165
- * [name: string]: any,
1166
- * contexts?: Context[]
1167
- * }} Settings
1168
- */
1169
- /**
1170
- * @typedef {{
1171
- * settings?: {
1172
- * jsdoc?: {
1173
- * ignorePrivate: boolean,
1174
- * ignoreInternal: boolean,
1175
- * maxLines: Integer,
1176
- * minLines: Integer,
1177
- * tagNamePreference: import('./jsdocUtils.js').TagNamePreference,
1178
- * preferredTypes: PreferredTypes,
1179
- * structuredTags: StructuredTags,
1180
- * overrideReplacesDocs: boolean,
1181
- * ignoreReplacesDocs: boolean,
1182
- * implementsReplacesDocs: boolean,
1183
- * augmentsExtendsReplacesDocs: boolean,
1184
- * exemptDestructuredRootsFromChecks: boolean,
1185
- * mode: import('./jsdocUtils.js').ParserMode,
1186
- * contexts: Context[],
1187
- * }
1188
- * }
1189
- * }} JSDocSettings
1190
- */
1191
- /**
1192
- * @param {import('eslint').Rule.RuleContext & JSDocSettings} context
1193
- * @returns {Settings|false}
1194
- */
1195
- const getSettings = (context) => {
1196
- const settings = {
1197
- ignorePrivate: Boolean(context.settings.jsdoc?.ignorePrivate),
1198
- ignoreInternal: Boolean(context.settings.jsdoc?.ignoreInternal),
1199
- maxLines: Number(context.settings.jsdoc?.maxLines ?? 1),
1200
- minLines: Number(context.settings.jsdoc?.minLines ?? 0),
1201
- tagNamePreference: context.settings.jsdoc?.tagNamePreference ?? {},
1202
- preferredTypes: context.settings.jsdoc?.preferredTypes ?? {},
1203
- structuredTags: context.settings.jsdoc?.structuredTags ?? {},
1204
- overrideReplacesDocs: context.settings.jsdoc?.overrideReplacesDocs,
1205
- ignoreReplacesDocs: context.settings.jsdoc?.ignoreReplacesDocs,
1206
- implementsReplacesDocs: context.settings.jsdoc?.implementsReplacesDocs,
1207
- augmentsExtendsReplacesDocs: context.settings.jsdoc?.augmentsExtendsReplacesDocs,
1208
- exemptDestructuredRootsFromChecks: context.settings.jsdoc?.exemptDestructuredRootsFromChecks,
1209
- mode: context.settings.jsdoc?.mode ?? "typescript",
1210
- contexts: context.settings.jsdoc?.contexts
1211
- };
1212
- setTagStructure(settings.mode);
1213
- try {
1214
- overrideTagStructure(settings.structuredTags);
1215
- } catch (error) {
1216
- context.report({
1217
- loc: {
1218
- end: {
1219
- column: 1,
1220
- line: 1
1221
- },
1222
- start: {
1223
- column: 1,
1224
- line: 1
1225
- }
1226
- },
1227
- message: error.message
1228
- });
1229
- return false;
1230
- }
1231
- return settings;
1232
- };
1233
- /**
1234
- * Create the report function
1235
- * @callback MakeReport
1236
- * @param {import('eslint').Rule.RuleContext} context
1237
- * @param {import('estree').Node} commentNode
1238
- * @returns {Report}
1239
- */
1240
- /** @type {MakeReport} */
1241
- const makeReport = (context, commentNode) => {
1242
- /** @type {Report} */
1243
- const report = (message, fix = null, jsdocLoc = null, data = void 0) => {
1244
- let loc;
1245
- if (jsdocLoc) {
1246
- if (!("line" in jsdocLoc)) jsdocLoc.line = jsdocLoc.source[0].number;
1247
- const lineNumber = commentNode.loc.start.line + jsdocLoc.line;
1248
- loc = {
1249
- end: {
1250
- column: 0,
1251
- line: lineNumber
1252
- },
1253
- start: {
1254
- column: 0,
1255
- line: lineNumber
1256
- }
1257
- };
1258
- if ("column" in jsdocLoc && typeof jsdocLoc.column === "number") {
1259
- const colNumber = commentNode.loc.start.column + jsdocLoc.column;
1260
- loc.end.column = colNumber;
1261
- loc.start.column = colNumber;
1262
- }
1263
- }
1264
- context.report({
1265
- data,
1266
- fix,
1267
- loc,
1268
- message,
1269
- node: commentNode
1270
- });
1271
- };
1272
- return report;
1273
- };
1274
- /**
1275
- * @typedef {(
1276
- * arg: {
1277
- * context: import('eslint').Rule.RuleContext,
1278
- * sourceCode: import('eslint').SourceCode,
1279
- * indent?: string,
1280
- * info?: {
1281
- * comment?: string|undefined,
1282
- * lastIndex?: Integer|undefined
1283
- * },
1284
- * state?: StateObject,
1285
- * globalState?: Map<string, Map<string, string>>,
1286
- * jsdoc?: JsdocBlockWithInline,
1287
- * jsdocNode?: import('eslint').Rule.Node & {
1288
- * range: [number, number]
1289
- * },
1290
- * node?: Node,
1291
- * allComments?: import('estree').Node[]
1292
- * report?: Report,
1293
- * makeReport?: MakeReport,
1294
- * settings: Settings,
1295
- * utils: BasicUtils,
1296
- * }
1297
- * ) => any } JsdocVisitorBasic
1298
- */
1299
- /**
1300
- * @typedef {(
1301
- * arg: {
1302
- * context: import('eslint').Rule.RuleContext,
1303
- * sourceCode: import('eslint').SourceCode,
1304
- * indent: string,
1305
- * info: {
1306
- * comment?: string|undefined,
1307
- * lastIndex?: Integer|undefined
1308
- * },
1309
- * state: StateObject,
1310
- * globalState: Map<string, Map<string, string>>,
1311
- * jsdoc: JsdocBlockWithInline,
1312
- * jsdocNode: import('eslint').Rule.Node & {
1313
- * range: [number, number]
1314
- * },
1315
- * node: Node|null,
1316
- * allComments?: import('estree').Node[]
1317
- * report: Report,
1318
- * makeReport?: MakeReport,
1319
- * settings: Settings,
1320
- * utils: Utils,
1321
- * }
1322
- * ) => any } JsdocVisitor
1323
- */
1324
- /**
1325
- * @param {{
1326
- * comment?: string,
1327
- * lastIndex?: Integer,
1328
- * selector?: string,
1329
- * isFunctionContext?: boolean,
1330
- * }} info
1331
- * @param {string} indent
1332
- * @param {JsdocBlockWithInline} jsdoc
1333
- * @param {RuleConfig} ruleConfig
1334
- * @param {import('eslint').Rule.RuleContext} context
1335
- * @param {import('@es-joy/jsdoccomment').Token} jsdocNode
1336
- * @param {Node|null} node
1337
- * @param {Settings} settings
1338
- * @param {import('eslint').SourceCode} sourceCode
1339
- * @param {JsdocVisitor} iterator
1340
- * @param {StateObject} state
1341
- * @param {boolean} [iteratingAll]
1342
- * @returns {void}
1343
- */
1344
- const iterate = (info, indent, jsdoc, ruleConfig, context, jsdocNode, node, settings, sourceCode, iterator, state, iteratingAll) => {
1345
- const jsdocNde = jsdocNode;
1346
- const report = makeReport(context, jsdocNde);
1347
- const utils = getUtils(node, jsdoc, jsdocNode, settings, report, context, sourceCode, iteratingAll, ruleConfig, indent);
1348
- if (!ruleConfig.checkInternal && settings.ignoreInternal && utils.hasTag("internal")) return;
1349
- if (!ruleConfig.checkPrivate && settings.ignorePrivate && (utils.hasTag("private") || filterTags(jsdoc, ({ tag }) => {
1350
- return tag === "access";
1351
- }).some(({ description }) => {
1352
- return description === "private";
1353
- }))) return;
1354
- iterator({
1355
- context,
1356
- globalState,
1357
- indent,
1358
- info,
1359
- jsdoc,
1360
- jsdocNode: jsdocNde,
1361
- node,
1362
- report,
1363
- settings,
1364
- sourceCode,
1365
- state,
1366
- utils
1367
- });
1368
- };
1369
- /**
1370
- * @param {string[]} lines
1371
- * @param {import('estree').Comment} jsdocNode
1372
- * @returns {[indent: string, jsdoc: JsdocBlockWithInline]}
1373
- */
1374
- const getIndentAndJSDoc = function(lines, jsdocNode) {
1375
- const sourceLine = lines[jsdocNode.loc.start.line - 1];
1376
- let indentChar = sourceLine.charAt(0);
1377
- if (indentChar !== " " && indentChar !== " ") indentChar = " ";
1378
- const indnt = indentChar.repeat(
1379
- /** @type {import('estree').SourceLocation} */
1380
- jsdocNode.loc.start.column
1381
- );
1382
- const jsdc = parseComment$1(jsdocNode, "");
1383
- return [indnt, jsdc];
1384
- };
1385
- /**
1386
- *
1387
- * @typedef {{node: Node & {
1388
- * range: [number, number]
1389
- * }, state: StateObject}} NonCommentArgs
1390
- */
1391
- /**
1392
- * @typedef {object} RuleConfig
1393
- * @property {EslintRuleMeta} meta ESLint rule meta
1394
- * @property {import('./jsdocUtils.js').DefaultContexts} [contextDefaults] Any default contexts
1395
- * @property {true} [contextSelected] Whether to force a `contexts` check
1396
- * @property {true} [iterateAllJsdocs] Whether to iterate all JSDoc blocks by default
1397
- * regardless of context
1398
- * @property {true} [checkPrivate] Whether to check `@private` blocks (normally exempted)
1399
- * @property {true} [checkInternal] Whether to check `@internal` blocks (normally exempted)
1400
- * @property {true} [checkFile] Whether to iterates over all JSDoc blocks regardless of attachment
1401
- * @property {true} [nonGlobalSettings] Whether to avoid relying on settings for global contexts
1402
- * @property {true} [noTracking] Whether to disable the tracking of visited comment nodes (as
1403
- * non-tracked may conduct further actions)
1404
- * @property {true} [matchContext] Whether the rule expects contexts to be based on a match option
1405
- * @property {(args: {
1406
- * context: import('eslint').Rule.RuleContext,
1407
- * state: StateObject,
1408
- * settings: Settings,
1409
- * utils: BasicUtils
1410
- * }) => void} [exit] Handler to be executed upon exiting iteration of program AST
1411
- * @property {(nca: NonCommentArgs) => void} [nonComment] Handler to be executed if rule wishes
1412
- * to be supplied nodes without comments
1413
- */
1414
- /**
1415
- * Create an eslint rule that iterates over all JSDocs, regardless of whether
1416
- * they are attached to a function-like node.
1417
- * @param {JsdocVisitor} iterator
1418
- * @param {RuleConfig} ruleConfig The rule's configuration
1419
- * @param {ContextObject[]|null} [contexts] The `contexts` containing relevant `comment` info.
1420
- * @param {boolean} [additiveCommentContexts] If true, will have a separate
1421
- * iteration for each matching comment context. Otherwise, will iterate
1422
- * once if there is a single matching comment context.
1423
- * @returns {import('eslint').Rule.RuleModule}
1424
- */
1425
- const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContexts) => {
1426
- const trackedJsdocs = /* @__PURE__ */ new Set();
1427
- /** @type {import('@es-joy/jsdoccomment').CommentHandler} */
1428
- let handler;
1429
- /** @type {Settings|false} */
1430
- let settings;
1431
- /**
1432
- * @param {import('eslint').Rule.RuleContext} context
1433
- * @param {Node|null} node
1434
- * @param {import('estree').Comment[]} jsdocNodes
1435
- * @param {StateObject} state
1436
- * @param {boolean} [lastCall]
1437
- * @returns {void}
1438
- */
1439
- const callIterator = (context, node, jsdocNodes, state, lastCall) => {
1440
- /* c8 ignore next -- Fallback to deprecated method */
1441
- const { sourceCode = context.getSourceCode() } = context;
1442
- const { lines } = sourceCode;
1443
- const utils = getBasicUtils(context, settings);
1444
- for (const jsdocNode of jsdocNodes) {
1445
- const jsdocNde = jsdocNode;
1446
- if (!/^\/\*\*\s/v.test(sourceCode.getText(jsdocNde))) continue;
1447
- const [indent, jsdoc] = getIndentAndJSDoc(lines, jsdocNode);
1448
- if (additiveCommentContexts) {
1449
- for (const [idx, { comment }] of contexts.entries()) {
1450
- if (comment && handler(comment, jsdoc) === false) continue;
1451
- iterate({
1452
- comment,
1453
- lastIndex: idx,
1454
- selector: node?.type
1455
- }, indent, jsdoc, ruleConfig, context, jsdocNode, node, settings, sourceCode, iterator, state, true);
1456
- }
1457
- continue;
1458
- }
1459
- let lastComment;
1460
- let lastIndex;
1461
- if (contexts && contexts.every(({ comment }, idx) => {
1462
- lastComment = comment;
1463
- lastIndex = idx;
1464
- return comment && handler(comment, jsdoc) === false;
1465
- })) continue;
1466
- iterate(lastComment ? {
1467
- comment: lastComment,
1468
- lastIndex,
1469
- selector: node?.type
1470
- } : {
1471
- lastIndex,
1472
- selector: node?.type
1473
- }, indent, jsdoc, ruleConfig, context, jsdocNode, node, settings, sourceCode, iterator, state, true);
1474
- }
1475
- const settngs = settings;
1476
- if (lastCall && ruleConfig.exit) ruleConfig.exit({
1477
- context,
1478
- settings: settngs,
1479
- state,
1480
- utils
1481
- });
1482
- };
1483
- return {
1484
- create(context) {
1485
- /* c8 ignore next -- Fallback to deprecated method */
1486
- const { sourceCode = context.getSourceCode() } = context;
1487
- settings = getSettings(context);
1488
- if (!settings) return {};
1489
- if (contexts) handler = commentHandler(settings);
1490
- const state = {};
1491
- return {
1492
- "*:not(Program)"(node) {
1493
- const commentNode = getJSDocComment(sourceCode, node, settings);
1494
- if (!ruleConfig.noTracking && trackedJsdocs.has(commentNode)) return;
1495
- if (!commentNode) {
1496
- if (ruleConfig.nonComment) {
1497
- const ste = state;
1498
- ruleConfig.nonComment({
1499
- node,
1500
- state: ste
1501
- });
1502
- }
1503
- return;
1504
- }
1505
- trackedJsdocs.add(commentNode);
1506
- callIterator(context, node, [commentNode], state);
1507
- },
1508
- "Program:exit"() {
1509
- const allComments = sourceCode.getAllComments();
1510
- const untrackedJSdoc = allComments.filter((node) => {
1511
- return !trackedJsdocs.has(node);
1512
- });
1513
- callIterator(context, null, untrackedJSdoc, state, true);
1514
- }
1515
- };
1516
- },
1517
- meta: ruleConfig.meta
1518
- };
1519
- };
1520
- /**
1521
- * Create an eslint rule that iterates over all JSDocs, regardless of whether
1522
- * they are attached to a function-like node.
1523
- * @param {JsdocVisitorBasic} iterator
1524
- * @param {RuleConfig} ruleConfig
1525
- * @returns {import('eslint').Rule.RuleModule}
1526
- */
1527
- const checkFile = (iterator, ruleConfig) => {
1528
- return {
1529
- create(context) {
1530
- /* c8 ignore next -- Fallback to deprecated method */
1531
- const { sourceCode = context.getSourceCode() } = context;
1532
- const settings = getSettings(context);
1533
- if (!settings) return {};
1534
- return { "Program:exit"() {
1535
- const allComms = sourceCode.getAllComments();
1536
- const utils = getBasicUtils(context, settings);
1537
- iterator({
1538
- allComments: allComms,
1539
- context,
1540
- makeReport,
1541
- settings,
1542
- sourceCode,
1543
- utils
1544
- });
1545
- } };
1546
- },
1547
- meta: ruleConfig.meta
1548
- };
1549
- };
1550
- /**
1551
- * @param {JsdocVisitor} iterator
1552
- * @param {RuleConfig} ruleConfig
1553
- * @returns {import('eslint').Rule.RuleModule}
1554
- */
1555
- function iterateJsdoc(iterator, ruleConfig) {
1556
- const metaType = ruleConfig?.meta?.type;
1557
- if (!metaType || ![
1558
- "layout",
1559
- "problem",
1560
- "suggestion"
1561
- ].includes(metaType)) throw new TypeError("Rule must include `meta.type` option (with value \"problem\", \"suggestion\", or \"layout\")");
1562
- if (typeof iterator !== "function") throw new TypeError("The iterator argument must be a function.");
1563
- if (ruleConfig.checkFile) return checkFile(iterator, ruleConfig);
1564
- if (ruleConfig.iterateAllJsdocs) return iterateAllJsdocs(iterator, ruleConfig);
1565
- /** @type {import('eslint').Rule.RuleModule} */
1566
- return {
1567
- create(context) {
1568
- const settings = getSettings(context);
1569
- if (!settings) return {};
1570
- /**
1571
- * @type {Context[]|undefined}
1572
- */
1573
- let contexts;
1574
- if (ruleConfig.contextDefaults || ruleConfig.contextSelected || ruleConfig.matchContext) {
1575
- contexts = ruleConfig.matchContext && context.options[0]?.match ? context.options[0].match : enforcedContexts(context, ruleConfig.contextDefaults, ruleConfig.nonGlobalSettings ? {} : settings);
1576
- if (contexts) contexts = contexts.map((obj) => {
1577
- if (typeof obj === "object" && !obj.context) return {
1578
- ...obj,
1579
- context: "any"
1580
- };
1581
- return obj;
1582
- });
1583
- const hasPlainAny = contexts?.includes("any");
1584
- const hasObjectAny = !hasPlainAny && contexts?.find((ctxt) => {
1585
- if (typeof ctxt === "string") return false;
1586
- return ctxt?.context === "any";
1587
- });
1588
- if (hasPlainAny || hasObjectAny) return iterateAllJsdocs(iterator, ruleConfig, hasObjectAny ? contexts : null, ruleConfig.matchContext).create(context);
1589
- }
1590
- /* c8 ignore next -- Fallback to deprecated method */
1591
- const { sourceCode = context.getSourceCode() } = context;
1592
- const { lines } = sourceCode;
1593
- /** @type {Partial<StateObject>} */
1594
- const state = {};
1595
- /** @type {CheckJsdoc} */
1596
- const checkJsdoc = (info, handler, node) => {
1597
- const jsdocNode = getJSDocComment(sourceCode, node, settings);
1598
- if (!jsdocNode) return;
1599
- const [indent, jsdoc] = getIndentAndJSDoc(lines, jsdocNode);
1600
- if (handler && handler(jsdoc) === false) return;
1601
- iterate(info, indent, jsdoc, ruleConfig, context, jsdocNode, node, settings, sourceCode, iterator, state);
1602
- };
1603
- /** @type {import('eslint').Rule.RuleListener} */
1604
- let contextObject = {};
1605
- if (contexts && (ruleConfig.contextDefaults || ruleConfig.contextSelected || ruleConfig.matchContext)) contextObject = getContextObject(contexts, checkJsdoc, commentHandler(settings));
1606
- else for (const prop of [
1607
- "ArrowFunctionExpression",
1608
- "FunctionDeclaration",
1609
- "FunctionExpression",
1610
- "TSDeclareFunction"
1611
- ]) contextObject[prop] = checkJsdoc.bind(null, { selector: prop }, null);
1612
- if (typeof ruleConfig.exit === "function") contextObject["Program:exit"] = () => {
1613
- const ste = state;
1614
- /** @type {Required<RuleConfig>} */ ruleConfig.exit({
1615
- context,
1616
- settings,
1617
- state: ste
1618
- });
1619
- };
1620
- return contextObject;
1621
- },
1622
- meta: ruleConfig.meta
1623
- };
1624
- }
1625
-
1626
- //#endregion
1627
- export { iterateJsdoc as default, getSettings, parseComment };
1628
- //# sourceMappingURL=iterateJsdoc.js.map