@md-code/follow-architecture 0.1.1 → 0.3.2

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 (487) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE +202 -0
  3. package/README.md +1420 -139
  4. package/dist/aliases.d.ts +3 -0
  5. package/dist/aliases.js +12 -0
  6. package/dist/args.d.ts +18 -0
  7. package/dist/args.js +94 -0
  8. package/dist/bin/follow-architecture.d.ts +2 -0
  9. package/dist/bin/follow-architecture.js +23 -0
  10. package/dist/closure-project.d.ts +4 -0
  11. package/dist/closure-project.js +132 -0
  12. package/dist/code-entities/classify.d.ts +11 -0
  13. package/dist/code-entities/classify.js +45 -0
  14. package/dist/code-entities/connector.d.ts +8 -0
  15. package/dist/code-entities/connector.js +119 -0
  16. package/dist/code-entities/entities.d.ts +9 -0
  17. package/dist/code-entities/entities.js +227 -0
  18. package/dist/code-entities/project.d.ts +21 -0
  19. package/dist/code-entities/project.js +259 -0
  20. package/dist/code-entities/walk.d.ts +31 -0
  21. package/dist/code-entities/walk.js +105 -0
  22. package/dist/config-options.d.ts +76 -0
  23. package/dist/config-options.js +52 -0
  24. package/dist/config-project.d.ts +4 -0
  25. package/dist/config-project.js +92 -0
  26. package/dist/config-report.d.ts +19 -0
  27. package/dist/config-report.js +161 -0
  28. package/dist/config-rule.d.ts +95 -0
  29. package/dist/config-rule.js +211 -0
  30. package/dist/config-state.d.ts +25 -0
  31. package/dist/config-state.js +269 -0
  32. package/dist/config.d.ts +107 -0
  33. package/dist/config.js +38 -0
  34. package/dist/css/index.d.ts +31 -0
  35. package/dist/css/index.js +251 -0
  36. package/dist/css/syntax/css/gate.d.ts +2 -0
  37. package/dist/css/syntax/css/gate.js +69 -0
  38. package/dist/css/syntax/css/index.d.ts +7 -0
  39. package/dist/css/syntax/css/index.js +51 -0
  40. package/dist/css/syntax/css/reference.d.ts +3 -0
  41. package/dist/css/syntax/css/reference.js +36 -0
  42. package/dist/css/syntax/language.d.ts +25 -0
  43. package/dist/css/syntax/language.js +81 -0
  44. package/dist/css/syntax/scss/index.d.ts +25 -0
  45. package/dist/css/syntax/scss/index.js +95 -0
  46. package/dist/css/syntax/scss/reference.d.ts +3 -0
  47. package/dist/css/syntax/scss/reference.js +17 -0
  48. package/dist/css/syntax/styled/document.d.ts +68 -0
  49. package/dist/css/syntax/styled/document.js +261 -0
  50. package/dist/css/syntax/styled/markup.d.ts +6 -0
  51. package/dist/css/syntax/styled/markup.js +84 -0
  52. package/dist/css/syntax/styled/tags.d.ts +2 -0
  53. package/dist/css/syntax/styled/tags.js +22 -0
  54. package/dist/css/syntax/styled/template.d.ts +23 -0
  55. package/dist/css/syntax/styled/template.js +67 -0
  56. package/dist/css/syntax/tailwind/tailwind-engine.d.ts +23 -0
  57. package/dist/css/syntax/tailwind/tailwind-engine.js +37 -0
  58. package/dist/css/syntax/tailwind/tailwind.d.ts +26 -0
  59. package/dist/css/syntax/tailwind/tailwind.js +118 -0
  60. package/dist/css/value/check.d.ts +86 -0
  61. package/dist/css/value/check.js +122 -0
  62. package/dist/css/value/expression/arithmetic.d.ts +7 -0
  63. package/dist/css/value/expression/arithmetic.js +73 -0
  64. package/dist/css/value/expression/block.d.ts +9 -0
  65. package/dist/css/value/expression/block.js +92 -0
  66. package/dist/css/value/expression/conditional.d.ts +8 -0
  67. package/dist/css/value/expression/conditional.js +53 -0
  68. package/dist/css/value/expression/index.d.ts +5 -0
  69. package/dist/css/value/expression/index.js +73 -0
  70. package/dist/css/value/expression/map.d.ts +7 -0
  71. package/dist/css/value/expression/map.js +113 -0
  72. package/dist/css/value/object/index.d.ts +5 -0
  73. package/dist/css/value/object/index.js +113 -0
  74. package/dist/css/value/object/members.d.ts +7 -0
  75. package/dist/css/value/object/members.js +103 -0
  76. package/dist/css/value/object/node.d.ts +8 -0
  77. package/dist/css/value/object/node.js +134 -0
  78. package/dist/css/value/object/path.d.ts +10 -0
  79. package/dist/css/value/object/path.js +152 -0
  80. package/dist/css/value/pieces.d.ts +61 -0
  81. package/dist/css/value/pieces.js +65 -0
  82. package/dist/css/value/resolve.d.ts +33 -0
  83. package/dist/css/value/resolve.js +104 -0
  84. package/dist/css/value/scope.d.ts +28 -0
  85. package/dist/css/value/scope.js +205 -0
  86. package/dist/css/value/substitute.d.ts +10 -0
  87. package/dist/css/value/substitute.js +145 -0
  88. package/dist/css/value/values.d.ts +23 -0
  89. package/dist/css/value/values.js +131 -0
  90. package/dist/entities/architecture.d.ts +165 -0
  91. package/dist/entities/architecture.js +2 -0
  92. package/dist/entities/ast/assignments-nodes.d.ts +10 -0
  93. package/dist/entities/ast/assignments-nodes.js +64 -0
  94. package/dist/entities/ast/assignments-raw.d.ts +6 -0
  95. package/dist/entities/ast/assignments-raw.js +139 -0
  96. package/dist/entities/ast/assignments-tagged.d.ts +5 -0
  97. package/dist/entities/ast/assignments-tagged.js +195 -0
  98. package/dist/entities/ast/assignments.d.ts +9 -0
  99. package/dist/entities/ast/assignments.js +80 -0
  100. package/dist/entities/ast/branches.d.ts +4 -0
  101. package/dist/entities/ast/branches.js +32 -0
  102. package/dist/entities/ast/calls.d.ts +6 -0
  103. package/dist/entities/ast/calls.js +150 -0
  104. package/dist/entities/ast/classes.d.ts +5 -0
  105. package/dist/entities/ast/classes.js +61 -0
  106. package/dist/entities/ast/climb.d.ts +12 -0
  107. package/dist/entities/ast/climb.js +17 -0
  108. package/dist/entities/ast/comments.d.ts +5 -0
  109. package/dist/entities/ast/comments.js +130 -0
  110. package/dist/entities/ast/declaration.d.ts +4 -0
  111. package/dist/entities/ast/declaration.js +26 -0
  112. package/dist/entities/ast/depth.d.ts +17 -0
  113. package/dist/entities/ast/depth.js +166 -0
  114. package/dist/entities/ast/enums.d.ts +6 -0
  115. package/dist/entities/ast/enums.js +17 -0
  116. package/dist/entities/ast/export-chain.d.ts +15 -0
  117. package/dist/entities/ast/export-chain.js +171 -0
  118. package/dist/entities/ast/file-exports.d.ts +7 -0
  119. package/dist/entities/ast/file-exports.js +101 -0
  120. package/dist/entities/ast/file-facts.d.ts +16 -0
  121. package/dist/entities/ast/file-facts.js +64 -0
  122. package/dist/entities/ast/file-imports.d.ts +5 -0
  123. package/dist/entities/ast/file-imports.js +100 -0
  124. package/dist/entities/ast/file.d.ts +5 -0
  125. package/dist/entities/ast/file.js +23 -0
  126. package/dist/entities/ast/functions.d.ts +8 -0
  127. package/dist/entities/ast/functions.js +111 -0
  128. package/dist/entities/ast/heritage.d.ts +4 -0
  129. package/dist/entities/ast/heritage.js +44 -0
  130. package/dist/entities/ast/index.d.ts +9 -0
  131. package/dist/entities/ast/index.js +181 -0
  132. package/dist/entities/ast/kind.d.ts +5 -0
  133. package/dist/entities/ast/kind.js +34 -0
  134. package/dist/entities/ast/loose.d.ts +37 -0
  135. package/dist/entities/ast/loose.js +2 -0
  136. package/dist/entities/ast/modifiers.d.ts +5 -0
  137. package/dist/entities/ast/modifiers.js +32 -0
  138. package/dist/entities/ast/project.d.ts +9 -0
  139. package/dist/entities/ast/project.js +106 -0
  140. package/dist/entities/ast/properties.d.ts +11 -0
  141. package/dist/entities/ast/properties.js +176 -0
  142. package/dist/entities/ast/resolve.d.ts +16 -0
  143. package/dist/entities/ast/resolve.js +317 -0
  144. package/dist/entities/ast/tree.d.ts +31 -0
  145. package/dist/entities/ast/tree.js +518 -0
  146. package/dist/entities/ast/types.d.ts +6 -0
  147. package/dist/entities/ast/types.js +46 -0
  148. package/dist/entities/ast/usage.d.ts +11 -0
  149. package/dist/entities/ast/usage.js +81 -0
  150. package/dist/entities/ast/variables.d.ts +8 -0
  151. package/dist/entities/ast/variables.js +91 -0
  152. package/dist/entities/context.d.ts +29 -0
  153. package/dist/entities/context.js +2 -0
  154. package/dist/entities/facts.d.ts +284 -0
  155. package/dist/entities/facts.js +2 -0
  156. package/dist/entities/findings.d.ts +19 -0
  157. package/dist/entities/findings.js +2 -0
  158. package/dist/entities/kinds.d.ts +40 -0
  159. package/dist/entities/kinds.js +332 -0
  160. package/dist/entities/location/homes.d.ts +28 -0
  161. package/dist/entities/location/homes.js +195 -0
  162. package/dist/entities/location/place.d.ts +10 -0
  163. package/dist/entities/location/place.js +63 -0
  164. package/dist/entities/location/where.d.ts +19 -0
  165. package/dist/entities/location/where.js +277 -0
  166. package/dist/entities/location.d.ts +16 -0
  167. package/dist/entities/location.js +140 -0
  168. package/dist/entities/operators.d.ts +14 -0
  169. package/dist/entities/operators.js +30 -0
  170. package/dist/entities/overview/data.d.ts +43 -0
  171. package/dist/entities/overview/data.js +2 -0
  172. package/dist/entities/overview/decision.d.ts +60 -0
  173. package/dist/entities/overview/decision.js +2 -0
  174. package/dist/entities/overview/file-tree.d.ts +10 -0
  175. package/dist/entities/overview/file-tree.js +2 -0
  176. package/dist/entities/overview/finding.d.ts +58 -0
  177. package/dist/entities/overview/finding.js +2 -0
  178. package/dist/entities/overview/graph.d.ts +82 -0
  179. package/dist/entities/overview/graph.js +2 -0
  180. package/dist/entities/overview/input.d.ts +15 -0
  181. package/dist/entities/overview/input.js +2 -0
  182. package/dist/entities/overview/summaries.d.ts +81 -0
  183. package/dist/entities/overview/summaries.js +2 -0
  184. package/dist/entities/place.d.ts +5 -0
  185. package/dist/entities/place.js +2 -0
  186. package/dist/entities/queries.d.ts +9 -0
  187. package/dist/entities/queries.js +375 -0
  188. package/dist/entities/repair.d.ts +16 -0
  189. package/dist/entities/repair.js +29 -0
  190. package/dist/entities/schema.d.ts +22 -0
  191. package/dist/entities/schema.js +81 -0
  192. package/dist/entities/story.d.ts +47 -0
  193. package/dist/entities/story.js +2 -0
  194. package/dist/entities/structure-facts.d.ts +11 -0
  195. package/dist/entities/structure-facts.js +2 -0
  196. package/dist/entities/token.d.ts +23 -0
  197. package/dist/entities/token.js +2 -0
  198. package/dist/entities/tree/build.d.ts +6 -0
  199. package/dist/entities/tree/build.js +313 -0
  200. package/dist/entities/tree/entries.d.ts +7 -0
  201. package/dist/entities/tree/entries.js +145 -0
  202. package/dist/entities/tree/index.d.ts +6 -0
  203. package/dist/entities/tree/index.js +21 -0
  204. package/dist/entities/tree/match.d.ts +17 -0
  205. package/dist/entities/tree/match.js +190 -0
  206. package/dist/fa-index.d.ts +16 -0
  207. package/dist/fa-index.js +165 -0
  208. package/dist/fa-open.d.ts +51 -0
  209. package/dist/fa-open.js +242 -0
  210. package/dist/fa-store.d.ts +22 -0
  211. package/dist/fa-store.js +232 -0
  212. package/dist/fa-values.d.ts +37 -0
  213. package/dist/fa-values.js +104 -0
  214. package/dist/facts-record.d.ts +45 -0
  215. package/dist/facts-record.js +297 -0
  216. package/dist/frameworks/angular/index.d.ts +7 -0
  217. package/dist/frameworks/angular/index.js +18 -0
  218. package/dist/frameworks/facet.d.ts +18 -0
  219. package/dist/frameworks/facet.js +15 -0
  220. package/dist/frameworks/index.d.ts +9 -0
  221. package/dist/frameworks/index.js +134 -0
  222. package/dist/frameworks/react/index.d.ts +7 -0
  223. package/dist/frameworks/react/index.js +237 -0
  224. package/dist/frameworks/test/index.d.ts +6 -0
  225. package/dist/frameworks/test/index.js +157 -0
  226. package/dist/frameworks/vue/index.d.ts +7 -0
  227. package/dist/frameworks/vue/index.js +18 -0
  228. package/dist/ignore.d.ts +3 -0
  229. package/dist/ignore.js +62 -0
  230. package/dist/index-file.d.ts +43 -0
  231. package/dist/index-file.js +218 -0
  232. package/dist/index-run.d.ts +39 -0
  233. package/dist/index-run.js +217 -0
  234. package/dist/index-zone.d.ts +25 -0
  235. package/dist/index-zone.js +219 -0
  236. package/dist/main.d.ts +10 -0
  237. package/dist/main.js +411 -0
  238. package/dist/nodes/child-entities.d.ts +3 -0
  239. package/dist/nodes/child-entities.js +12 -0
  240. package/dist/nodes/children.d.ts +25 -0
  241. package/dist/nodes/children.js +165 -0
  242. package/dist/nodes/finally/emit.d.ts +6 -0
  243. package/dist/nodes/finally/emit.js +71 -0
  244. package/dist/nodes/finally/entities.d.ts +13 -0
  245. package/dist/nodes/finally/entities.js +42 -0
  246. package/dist/nodes/finally/index.d.ts +8 -0
  247. package/dist/nodes/finally/index.js +35 -0
  248. package/dist/nodes/finally/queries.d.ts +5 -0
  249. package/dist/nodes/finally/queries.js +25 -0
  250. package/dist/nodes/finally/relations-access.d.ts +5 -0
  251. package/dist/nodes/finally/relations-access.js +50 -0
  252. package/dist/nodes/finally/relations-edge.d.ts +29 -0
  253. package/dist/nodes/finally/relations-edge.js +148 -0
  254. package/dist/nodes/finally/relations-group.d.ts +31 -0
  255. package/dist/nodes/finally/relations-group.js +106 -0
  256. package/dist/nodes/finally/relations.d.ts +5 -0
  257. package/dist/nodes/finally/relations.js +85 -0
  258. package/dist/nodes/finally/required.d.ts +5 -0
  259. package/dist/nodes/finally/required.js +92 -0
  260. package/dist/nodes/finally/violation.d.ts +17 -0
  261. package/dist/nodes/finally/violation.js +2 -0
  262. package/dist/nodes/similar.d.ts +21 -0
  263. package/dist/nodes/similar.js +178 -0
  264. package/dist/piece-forms.d.ts +9 -0
  265. package/dist/piece-forms.js +68 -0
  266. package/dist/pipeline-entities.d.ts +6 -0
  267. package/dist/pipeline-entities.js +79 -0
  268. package/dist/pipeline-facts.d.ts +12 -0
  269. package/dist/pipeline-facts.js +114 -0
  270. package/dist/pipeline-unclassified.d.ts +14 -0
  271. package/dist/pipeline-unclassified.js +188 -0
  272. package/dist/pipeline.d.ts +7 -0
  273. package/dist/pipeline.js +28 -0
  274. package/dist/plugin.d.ts +2 -0
  275. package/dist/plugin.js +3 -0
  276. package/dist/release-file.d.ts +3 -0
  277. package/dist/release-file.js +13 -0
  278. package/dist/report/asks.d.ts +55 -0
  279. package/dist/report/asks.js +60 -0
  280. package/dist/report/cli-report.d.ts +2 -0
  281. package/dist/report/cli-report.js +13 -0
  282. package/dist/report/config-error-guard.d.ts +8 -0
  283. package/dist/report/config-error-guard.js +5 -0
  284. package/dist/report/configErrors.d.ts +126 -0
  285. package/dist/report/configErrors.js +121 -0
  286. package/dist/report/errorTypes/codes/structure.d.ts +15 -0
  287. package/dist/report/errorTypes/codes/structure.js +76 -0
  288. package/dist/report/errorTypes/decision-maker.d.ts +23 -0
  289. package/dist/report/errorTypes/decision-maker.js +109 -0
  290. package/dist/report/errorTypes/destinations.d.ts +38 -0
  291. package/dist/report/errorTypes/destinations.js +165 -0
  292. package/dist/report/errorTypes/finding-type.d.ts +11 -0
  293. package/dist/report/errorTypes/finding-type.js +2 -0
  294. package/dist/report/errorTypes/index.d.ts +15 -0
  295. package/dist/report/errorTypes/index.js +55 -0
  296. package/dist/report/errorTypes/types/fileContents.d.ts +9 -0
  297. package/dist/report/errorTypes/types/fileContents.js +40 -0
  298. package/dist/report/errorTypes/types/unknownEntity.d.ts +9 -0
  299. package/dist/report/errorTypes/types/unknownEntity.js +27 -0
  300. package/dist/report/errorTypes/types/wrongAction.d.ts +22 -0
  301. package/dist/report/errorTypes/types/wrongAction.js +140 -0
  302. package/dist/report/errorTypes/types/wrongPlacement.d.ts +9 -0
  303. package/dist/report/errorTypes/types/wrongPlacement.js +67 -0
  304. package/dist/report/errorTypes/vocabulary/ids.d.ts +5 -0
  305. package/dist/report/errorTypes/vocabulary/ids.js +16 -0
  306. package/dist/report/errorTypes/vocabulary/phrases.d.ts +10 -0
  307. package/dist/report/errorTypes/vocabulary/phrases.js +187 -0
  308. package/dist/report/errorTypes/vocabulary/places.d.ts +8 -0
  309. package/dist/report/errorTypes/vocabulary/places.js +36 -0
  310. package/dist/report/errorTypes/vocabulary/verbs.d.ts +7 -0
  311. package/dist/report/errorTypes/vocabulary/verbs.js +30 -0
  312. package/dist/report/finding-from.d.ts +9 -0
  313. package/dist/report/finding-from.js +108 -0
  314. package/dist/report/notices.d.ts +9 -0
  315. package/dist/report/notices.js +57 -0
  316. package/dist/report/observed.d.ts +19 -0
  317. package/dist/report/observed.js +87 -0
  318. package/dist/report/render-report.d.ts +12 -0
  319. package/dist/report/render-report.js +145 -0
  320. package/dist/report/user-report/build/bundle.d.ts +3 -0
  321. package/dist/report/user-report/build/bundle.js +188 -0
  322. package/dist/report/user-report/build/bundle.prebuilt.js +1262 -0
  323. package/dist/report/user-report/data/collect.d.ts +4 -0
  324. package/dist/report/user-report/data/collect.js +93 -0
  325. package/dist/report/user-report/data/entities.d.ts +7 -0
  326. package/dist/report/user-report/data/entities.js +88 -0
  327. package/dist/report/user-report/data/entity-examples.d.ts +16 -0
  328. package/dist/report/user-report/data/entity-examples.js +136 -0
  329. package/dist/report/user-report/data/entity-filters.d.ts +15 -0
  330. package/dist/report/user-report/data/entity-filters.js +79 -0
  331. package/dist/report/user-report/data/entity-marks.d.ts +5 -0
  332. package/dist/report/user-report/data/entity-marks.js +79 -0
  333. package/dist/report/user-report/data/file-tree.d.ts +9 -0
  334. package/dist/report/user-report/data/file-tree.js +80 -0
  335. package/dist/report/user-report/data/finding-boundary.d.ts +9 -0
  336. package/dist/report/user-report/data/finding-boundary.js +21 -0
  337. package/dist/report/user-report/data/finding-plan.d.ts +16 -0
  338. package/dist/report/user-report/data/finding-plan.js +45 -0
  339. package/dist/report/user-report/data/finding-title.d.ts +12 -0
  340. package/dist/report/user-report/data/finding-title.js +36 -0
  341. package/dist/report/user-report/data/findings.d.ts +10 -0
  342. package/dist/report/user-report/data/findings.js +181 -0
  343. package/dist/report/user-report/data/graph-edges.d.ts +19 -0
  344. package/dist/report/user-report/data/graph-edges.js +109 -0
  345. package/dist/report/user-report/data/graph-entities.d.ts +6 -0
  346. package/dist/report/user-report/data/graph-entities.js +158 -0
  347. package/dist/report/user-report/data/graph-helpers.d.ts +7 -0
  348. package/dist/report/user-report/data/graph-helpers.js +67 -0
  349. package/dist/report/user-report/data/graph.d.ts +12 -0
  350. package/dist/report/user-report/data/graph.js +97 -0
  351. package/dist/report/user-report/data/nodes.d.ts +11 -0
  352. package/dist/report/user-report/data/nodes.js +116 -0
  353. package/dist/report/user-report/data/rules.d.ts +7 -0
  354. package/dist/report/user-report/data/rules.js +62 -0
  355. package/dist/report/user-report/data/scan.d.ts +8 -0
  356. package/dist/report/user-report/data/scan.js +69 -0
  357. package/dist/report/user-report/html/shell.d.ts +3 -0
  358. package/dist/report/user-report/html/shell.js +27 -0
  359. package/dist/report/user-report/index.d.ts +8 -0
  360. package/dist/report/user-report/index.js +58 -0
  361. package/dist/report/user-report/shared/describe.d.ts +7 -0
  362. package/dist/report/user-report/shared/describe.js +86 -0
  363. package/dist/rules/index.d.ts +7 -0
  364. package/dist/rules/index.js +327 -0
  365. package/dist/rules/list-vars.d.ts +5 -0
  366. package/dist/rules/list-vars.js +149 -0
  367. package/dist/rules/name.d.ts +16 -0
  368. package/dist/rules/name.js +18 -0
  369. package/dist/rules/normalize.d.ts +5 -0
  370. package/dist/rules/normalize.js +108 -0
  371. package/dist/rules/vars.d.ts +22 -0
  372. package/dist/rules/vars.js +117 -0
  373. package/dist/scan-run.d.ts +20 -0
  374. package/dist/scan-run.js +130 -0
  375. package/dist/scripts/audit-report.d.ts +2 -0
  376. package/dist/scripts/audit-report.js +157 -0
  377. package/dist/usage-index.d.ts +4 -0
  378. package/dist/usage-index.js +282 -0
  379. package/dist/usage-mode.d.ts +7 -0
  380. package/dist/usage-mode.js +16 -0
  381. package/dist/usage-pass.d.ts +19 -0
  382. package/dist/usage-pass.js +136 -0
  383. package/dist/usage-prepare.d.ts +2 -0
  384. package/dist/usage-prepare.js +22 -0
  385. package/dist/usage-sweep.d.ts +10 -0
  386. package/dist/usage-sweep.js +264 -0
  387. package/dist/utils/accumulate.d.ts +6 -0
  388. package/dist/utils/accumulate.js +18 -0
  389. package/dist/utils/aliases.d.ts +22 -0
  390. package/dist/utils/aliases.js +173 -0
  391. package/dist/utils/article.d.ts +2 -0
  392. package/dist/utils/article.js +12 -0
  393. package/dist/utils/classify.d.ts +12 -0
  394. package/dist/utils/classify.js +25 -0
  395. package/dist/utils/configs.d.ts +25 -0
  396. package/dist/utils/configs.js +97 -0
  397. package/dist/utils/count.d.ts +7 -0
  398. package/dist/utils/count.js +13 -0
  399. package/dist/utils/dispatch.d.ts +2 -0
  400. package/dist/utils/dispatch.js +27 -0
  401. package/dist/utils/distinct.d.ts +2 -0
  402. package/dist/utils/distinct.js +14 -0
  403. package/dist/utils/field.d.ts +14 -0
  404. package/dist/utils/field.js +60 -0
  405. package/dist/utils/file-name.d.ts +2 -0
  406. package/dist/utils/file-name.js +11 -0
  407. package/dist/utils/files.d.ts +7 -0
  408. package/dist/utils/files.js +77 -0
  409. package/dist/utils/fixpoint.d.ts +2 -0
  410. package/dist/utils/fixpoint.js +19 -0
  411. package/dist/utils/gate.d.ts +2 -0
  412. package/dist/utils/gate.js +12 -0
  413. package/dist/utils/group.d.ts +3 -0
  414. package/dist/utils/group.js +33 -0
  415. package/dist/utils/host.d.ts +3 -0
  416. package/dist/utils/host.js +16 -0
  417. package/dist/utils/imports.d.ts +12 -0
  418. package/dist/utils/imports.js +185 -0
  419. package/dist/utils/judged.d.ts +5 -0
  420. package/dist/utils/judged.js +19 -0
  421. package/dist/utils/keyed.d.ts +2 -0
  422. package/dist/utils/keyed.js +23 -0
  423. package/dist/utils/map-record.d.ts +2 -0
  424. package/dist/utils/map-record.js +11 -0
  425. package/dist/utils/packages.d.ts +15 -0
  426. package/dist/utils/packages.js +207 -0
  427. package/dist/utils/path-label.d.ts +6 -0
  428. package/dist/utils/path-label.js +37 -0
  429. package/dist/utils/pattern.d.ts +19 -0
  430. package/dist/utils/pattern.js +231 -0
  431. package/dist/utils/permission.d.ts +16 -0
  432. package/dist/utils/permission.js +18 -0
  433. package/dist/utils/plural.d.ts +2 -0
  434. package/dist/utils/plural.js +9 -0
  435. package/dist/utils/qualified.d.ts +2 -0
  436. package/dist/utils/qualified.js +21 -0
  437. package/dist/utils/rank.d.ts +2 -0
  438. package/dist/utils/rank.js +24 -0
  439. package/dist/utils/read-field.d.ts +12 -0
  440. package/dist/utils/read-field.js +50 -0
  441. package/dist/utils/read-when.d.ts +2 -0
  442. package/dist/utils/read-when.js +17 -0
  443. package/dist/utils/reason.d.ts +4 -0
  444. package/dist/utils/reason.js +9 -0
  445. package/dist/utils/record.d.ts +3 -0
  446. package/dist/utils/record.js +21 -0
  447. package/dist/utils/resolve.d.ts +2 -0
  448. package/dist/utils/resolve.js +24 -0
  449. package/dist/utils/search.d.ts +2 -0
  450. package/dist/utils/search.js +21 -0
  451. package/dist/utils/seen.d.ts +6 -0
  452. package/dist/utils/seen.js +27 -0
  453. package/dist/utils/span.d.ts +5 -0
  454. package/dist/utils/span.js +2 -0
  455. package/dist/utils/speak.d.ts +2 -0
  456. package/dist/utils/speak.js +18 -0
  457. package/dist/utils/split.d.ts +8 -0
  458. package/dist/utils/split.js +21 -0
  459. package/dist/utils/template.d.ts +5 -0
  460. package/dist/utils/template.js +5 -0
  461. package/dist/utils/text.d.ts +4 -0
  462. package/dist/utils/text.js +42 -0
  463. package/dist/utils/tokenize.d.ts +2 -0
  464. package/dist/utils/tokenize.js +18 -0
  465. package/dist/utils/try-read.d.ts +4 -0
  466. package/dist/utils/try-read.js +24 -0
  467. package/dist/utils/typed-field.d.ts +3 -0
  468. package/dist/utils/typed-field.js +16 -0
  469. package/dist/utils/verdicts.d.ts +4 -0
  470. package/dist/utils/verdicts.js +20 -0
  471. package/entities/operators.ts +31 -0
  472. package/package.json +101 -47
  473. package/report/errorTypes/vocabulary/ids.ts +17 -0
  474. package/report/errorTypes/vocabulary/phrases.ts +181 -0
  475. package/report/errorTypes/vocabulary/places.ts +51 -0
  476. package/report/errorTypes/vocabulary/verbs.ts +31 -0
  477. package/report/user-report/shared/describe.ts +107 -0
  478. package/ast.js +0 -107
  479. package/bin/follow-architecture.js +0 -6
  480. package/config.js +0 -101
  481. package/entities/aliases.js +0 -10
  482. package/entities/invariants.js +0 -134
  483. package/entities/nodes.js +0 -112
  484. package/main.js +0 -96
  485. package/plugin.js +0 -5
  486. package/report.js +0 -73
  487. package/utils.js +0 -104
@@ -0,0 +1,518 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.kindFact = exports.descendantsOf = exports.descendantFact = exports.descriptor = exports.depthOf = exports.isMutable = exports.isExported = exports.rangeLines = exports.linesOf = exports.selfOf = exports.startLine = exports.isMeaningful = exports.memberFacts = exports.typeText = exports.unwrapParens = exports.inThisPiece = exports.isClassNode = exports.isCallNode = exports.isFunctionNode = exports.nodeText = exports.nameOfNode = exports.isImportDecl = exports.releaseTree = exports.fileDescendants = exports.kindName = exports.SK = void 0;
4
+ // The syntax tree: what a node IS, what it is called, and where it sits.
5
+ // Everything here is a question about ONE node — never about a project, an entity
6
+ // or a folder. Names come from ts-morph itself (`getKindName`), so the engine
7
+ // speaks exactly the vocabulary of the parser.
8
+ const ts_morph_1 = require("ts-morph");
9
+ Object.defineProperty(exports, "SK", { enumerable: true, get: function () { return ts_morph_1.SyntaxKind; } });
10
+ const notices_1 = require("@md-code/follow-architecture/report/notices");
11
+ // Declarations that ARE an import: the parser's own names for the three forms.
12
+ // One list, because three passes ask the same question (`file.js` twice,
13
+ // `assignments.js` once) and an import is recognised the same way in all of them.
14
+ const IMPORT_DECL_KINDS = new Set(["ImportSpecifier", "ImportClause", "NamespaceImport"]);
15
+ const isImportDecl = (decl) => IMPORT_DECL_KINDS.has(decl?.getKindName?.());
16
+ exports.isImportDecl = isImportDecl;
17
+ // Function-like nodes — the candidates for any function-shaped entity.
18
+ const FUNCTION_KINDS = new Set([
19
+ ts_morph_1.SyntaxKind.FunctionDeclaration,
20
+ ts_morph_1.SyntaxKind.FunctionExpression,
21
+ ts_morph_1.SyntaxKind.ArrowFunction,
22
+ ts_morph_1.SyntaxKind.MethodDeclaration,
23
+ ts_morph_1.SyntaxKind.GetAccessor,
24
+ ts_morph_1.SyntaxKind.SetAccessor,
25
+ ]);
26
+ // Loops — body shape, not a verdict: "this body is a loop" is a rule's question.
27
+ const LOOP_KINDS = new Set([ts_morph_1.SyntaxKind.ForStatement, ts_morph_1.SyntaxKind.ForOfStatement, ts_morph_1.SyntaxKind.ForInStatement, ts_morph_1.SyntaxKind.WhileStatement, ts_morph_1.SyntaxKind.DoStatement]);
28
+ // Call targets.
29
+ const CALL_KINDS = new Set([ts_morph_1.SyntaxKind.CallExpression, ts_morph_1.SyntaxKind.NewExpression, ts_morph_1.SyntaxKind.TaggedTemplateExpression]);
30
+ // The name of a node's kind, as the parser spells it ("FunctionDeclaration").
31
+ const kindName = (node) => node.getKindName();
32
+ exports.kindName = kindName;
33
+ // A parsed file's descendants, computed ONCE per SourceFile and shared by every
34
+ // per-file walk in a run (candidate collection, comment spans, docs). A re-parsed
35
+ // file can REUSE the same SourceFile wrapper with new text (ts-morph overwrites in
36
+ // place), so the cache is guarded by the file's current text — a changed file is a
37
+ // new list. `getFullText()` returns the compiler's own text string, so the guard
38
+ // compares references, not bytes. `getDescendants()` is the dominant cost of a
39
+ // scan, so walking the file once instead of once per consumer is what makes the
40
+ // whole-repo run tractable.
41
+ const FILE_DESCENDANTS = new WeakMap();
42
+ const fileDescendants = (sf) => {
43
+ const text = sf.getFullText();
44
+ const cached = FILE_DESCENDANTS.get(sf);
45
+ if (cached && cached.text === text)
46
+ return cached.list;
47
+ const list = sf.getDescendants();
48
+ FILE_DESCENDANTS.set(sf, { text, list });
49
+ return list;
50
+ };
51
+ exports.fileDescendants = fileDescendants;
52
+ // Give back everything this module remembers about ONE file, and hand back the
53
+ // nodes it remembered it for.
54
+ //
55
+ // The descendant list is the only STRONG reference to a file's node wrappers:
56
+ // while it lives, every wrapper stays reachable, and so does every value a
57
+ // node-keyed memo hangs off it (line, text, depth, and through them the
58
+ // candidate facts built for that file). A run that is done with a file's syntax
59
+ // — the project-wide index, once the file's facts are extracted — calls this, so
60
+ // a whole-repo pass holds one file's wrappers, not every file's. The compiler
61
+ // AST itself is untouched: re-reading the file re-creates wrappers on demand.
62
+ const releaseTree = (sf) => {
63
+ const cached = FILE_DESCENDANTS.get(sf);
64
+ FILE_DESCENDANTS.delete(sf);
65
+ FILE_MEMOS.delete(sf);
66
+ LINE_STARTS.delete(sf);
67
+ return cached?.list ?? [];
68
+ };
69
+ exports.releaseTree = releaseTree;
70
+ // The memos belong to the TEXT they were computed from, exactly like the line
71
+ // table below: a SourceFile wrapper is reused when the file is overwritten in
72
+ // place, and a memo answered for the previous text would be a stale number in a
73
+ // long-lived process (the ESLint server). The text is compared by reference with
74
+ // `getFullText()`, which returns the same string for an unchanged file.
75
+ const FILE_MEMOS = new WeakMap();
76
+ const memosOf = (node) => {
77
+ const sf = node.getSourceFile();
78
+ const text = sf.getFullText();
79
+ const known = FILE_MEMOS.get(sf);
80
+ if (known && known.text === text)
81
+ return known.memos;
82
+ const created = {
83
+ startLine: new Map(),
84
+ endLine: new Map(),
85
+ type: new Map(),
86
+ depth: new Map(),
87
+ };
88
+ FILE_MEMOS.set(sf, { text, memos: created });
89
+ return created;
90
+ };
91
+ // Where each line of a file begins, built ONCE per file. The parser's own
92
+ // position lookup (`getLineAndColumnAtPos`) walks the text from the start of the
93
+ // file for every question, twice — once for the line and once for the column —
94
+ // and a whole-repo pass asks it a million times. One scan per file plus a binary
95
+ // search answers the same numbers in a few steps.
96
+ //
97
+ // A file's record is keyed by the text it was built from: the SourceFile wrapper
98
+ // is REUSED when a file is overwritten in place, so a table outliving one version
99
+ // of the text would answer for another.
100
+ const LINE_STARTS = new WeakMap();
101
+ const lineStartsOf = (sf) => {
102
+ const text = sf.getFullText();
103
+ const known = LINE_STARTS.get(sf);
104
+ if (known && known.text === text)
105
+ return known.starts;
106
+ // The five line breaks the parser counts (and `getLineNumberAtPos` counts):
107
+ // `\n`, `\r`, `\r\n` as ONE break, U+2028 and U+2029. A table built from `\n`
108
+ // alone would number the lines of a CRLF file differently from every other
109
+ // reader of the same file.
110
+ const starts = [0];
111
+ for (let i = 0; i < text.length; i += 1) {
112
+ const code = text.charCodeAt(i);
113
+ if (code === 13) {
114
+ const paired = text.charCodeAt(i + 1) === 10;
115
+ starts.push(paired ? i + 2 : i + 1);
116
+ if (paired)
117
+ i += 1;
118
+ }
119
+ else if (code === 10 || code === 0x2028 || code === 0x2029)
120
+ starts.push(i + 1);
121
+ }
122
+ const built = Int32Array.from(starts);
123
+ LINE_STARTS.set(sf, { text, starts: built });
124
+ return built;
125
+ };
126
+ // The 1-based line of a position — the same number the parser reports.
127
+ const lineAt = (sf, pos) => {
128
+ const starts = lineStartsOf(sf);
129
+ let low = 0;
130
+ let high = starts.length - 1;
131
+ while (low < high) {
132
+ const mid = (low + high + 1) >> 1;
133
+ if (starts[mid] <= pos)
134
+ low = mid;
135
+ else
136
+ high = mid - 1;
137
+ }
138
+ return low + 1;
139
+ };
140
+ // A node's text as an IDENTITY, not as formatting. A fact is compared to what
141
+ // the architecture writes by hand (`origin: { equals: "t.model" }`,
142
+ // `source: { equals: "./x" }`), so the source LAYOUT must not leak into it: a
143
+ // chain broken across lines is the same callee, and entities silently stopped
144
+ // matching the moment it was not.
145
+ //
146
+ // Two rules, one helper:
147
+ // • a LITERAL denotes its VALUE — `'./x'` names the module `./x`, quotes are
148
+ // syntax and the import map holds the value; `Base<'a b'>` keeps its space;
149
+ // • everything else is its spelling with the whitespace removed — whitespace
150
+ // can never sit inside an identifier, a dot or `[0]`.
151
+ const QUOTED_OR_SPACE = /"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`|\s+/g;
152
+ const stripLayout = (text) => text.replace(QUOTED_OR_SPACE, (match) => (/^["'`]/.test(match) ? match : ""));
153
+ const nodeText = (node) => {
154
+ if (!node)
155
+ return "";
156
+ const value = typeof node.getLiteralText === "function" ? node.getLiteralText() : null;
157
+ if (typeof value === "string")
158
+ return value;
159
+ return stripLayout(String(node.getText?.() ?? ""));
160
+ };
161
+ exports.nodeText = nodeText;
162
+ const isFunctionNode = (n) => FUNCTION_KINDS.has(n.getKind());
163
+ exports.isFunctionNode = isFunctionNode;
164
+ const isLoopNode = (n) => LOOP_KINDS.has(n.getKind());
165
+ const isCallNode = (n) => CALL_KINDS.has(n.getKind());
166
+ exports.isCallNode = isCallNode;
167
+ // A class declaration or expression — a candidate like any other.
168
+ const isClassNode = (n) => n.getKind() === ts_morph_1.SyntaxKind.ClassDeclaration || n.getKind() === ts_morph_1.SyntaxKind.ClassExpression;
169
+ exports.isClassNode = isClassNode;
170
+ // Does a descendant belong to THIS piece, and not to a function nested inside
171
+ // it? A nested function is a candidate of its own, so what it does there is ITS
172
+ // work: counting it here too would attribute one line to two pieces.
173
+ const inThisPiece = (node, d) => {
174
+ for (let cur = d.getParent(); cur && cur !== node; cur = cur.getParent())
175
+ if (isFunctionNode(cur))
176
+ return false;
177
+ return true;
178
+ };
179
+ exports.inThisPiece = inThisPiece;
180
+ // Unwrap parenthesized expressions: `() => ({...})` yields a
181
+ // ParenthesizedExpression whose `getExpression()` is the real ObjectLiteral.
182
+ const unwrapParens = (node) => {
183
+ let n = node;
184
+ while (ts_morph_1.Node.isParenthesizedExpression(n))
185
+ n = n.getExpression();
186
+ return n;
187
+ };
188
+ exports.unwrapParens = unwrapParens;
189
+ // ── One node: name, line, depth, members ────────────────────────────────────
190
+ // A type as the parser reads it, or "any". The CHECKER call (`getType`) is the
191
+ // single most expensive fact a scan produces, and the same member node is
192
+ // reached from more than one walk (a candidate's descendant list, its
193
+ // initializer's members), so the answer is memoised per node for the run.
194
+ const typeText = (node) => {
195
+ const memos = memosOf(node);
196
+ const cached = memos.type.get(node);
197
+ if (cached !== undefined)
198
+ return cached;
199
+ try {
200
+ const t = node.getType();
201
+ const text = t.isAny() ? "any" : t.getText();
202
+ memos.type.set(node, text);
203
+ return text;
204
+ }
205
+ catch (error) {
206
+ // The checker fails on an import it cannot resolve (a broken path, a package
207
+ // that is not installed). That is NOT a type: the fact is UNKNOWN, and an
208
+ // unknown type must not take the analysis of the whole run down with it. The
209
+ // reason is reported, so a partial answer never passes for a clean one.
210
+ const file = node.getSourceFile?.()?.getFilePath?.() ?? "?";
211
+ const e = error;
212
+ (0, notices_1.notice)(`a type could not be read (${file})`, e.message ?? String(e));
213
+ memos.type.set(node, null);
214
+ return null;
215
+ }
216
+ };
217
+ exports.typeText = typeText;
218
+ // Raw per-member facts of an object literal: `[{name, is, type}]`. The engine
219
+ // records DATA, not verdicts — "does this literal have methods?" is a query
220
+ // (`members: { some: { is: { equals: "MethodDeclaration" } } }`).
221
+ // A property whose initializer is a LITERAL also carries the VALUE it was written
222
+ // with (`'#182022'`, `12`, `0`). That is what makes an object's `colors: { section:
223
+ // '#182022' }` readable as a COLOUR — a property of the thing itself, not of the
224
+ // folder it sits in.
225
+ const literalValueOf = (property) => {
226
+ const init = property.getInitializer?.();
227
+ if (!init)
228
+ return null;
229
+ if (ts_morph_1.Node.isNumericLiteral(init))
230
+ return Number(init.getLiteralText());
231
+ if (ts_morph_1.Node.isStringLiteral(init) || ts_morph_1.Node.isNoSubstitutionTemplateLiteral(init))
232
+ return init.getLiteralText();
233
+ return null;
234
+ };
235
+ // A member whose initializer is ANOTHER object literal carries its own members —
236
+ // that is what makes `spec.colors.section` reachable as a fact. The walk stops at
237
+ // MAX_MEMBER_DEPTH so a pathological literal cannot turn a report into a full tree
238
+ // walk; what is NOT an object literal (`new Map(…)`, a call, a method shorthand)
239
+ // simply has no `members`, instead of an empty list that would read like "none".
240
+ const MAX_MEMBER_DEPTH = 4;
241
+ const memberFacts = (objLit, depth = 0) => objLit.getProperties().map((p) => {
242
+ const init = p.getInitializer?.() ?? null;
243
+ const nested = depth < MAX_MEMBER_DEPTH && init !== null && ts_morph_1.Node.isObjectLiteralExpression(init) ? init : null;
244
+ return {
245
+ name: typeof p.getName === "function" ? p.getName() : null,
246
+ is: kindName(p),
247
+ type: typeText(p),
248
+ value: literalValueOf(p),
249
+ ...(nested ? { members: memberFacts(nested, depth + 1) } : {}),
250
+ };
251
+ });
252
+ exports.memberFacts = memberFacts;
253
+ // A descendant is meaningful when it is not a SyntaxList and not a punctuation
254
+ // token. Keywords (NumberKeyword, …) are kept — they are meaningful.
255
+ const isMeaningful = (d) => {
256
+ if (d.getKind() === ts_morph_1.SyntaxKind.SyntaxList)
257
+ return false;
258
+ const k = d.getKind();
259
+ if (k >= ts_morph_1.SyntaxKind.FirstToken && k <= ts_morph_1.SyntaxKind.LastToken)
260
+ return d.getKindName().endsWith("Keyword");
261
+ return true;
262
+ };
263
+ exports.isMeaningful = isMeaningful;
264
+ const startLine = (n) => {
265
+ // The SourceFile wrapper is REUSED when a file is overwritten in place, so its
266
+ // line span is not cached (its children are new wrappers and cache safely).
267
+ if (n.getKind() === ts_morph_1.SyntaxKind.SourceFile)
268
+ return lineAt(n.getSourceFile(), n.getStart());
269
+ const memos = memosOf(n);
270
+ const cached = memos.startLine.get(n);
271
+ if (cached !== undefined)
272
+ return cached;
273
+ const line = lineAt(n.getSourceFile(), n.getStart());
274
+ memos.startLine.set(n, line);
275
+ return line;
276
+ };
277
+ exports.startLine = startLine;
278
+ // A candidate's OWN IDENTITY: where it starts — file, line and column, as one
279
+ // comparable value. A name is not an identity (three files have a `run`), a line
280
+ // is not one either (a `const` and its arrow start on the same line), so every
281
+ // fact that points at a piece can point at this instead of at a name that
282
+ // aliases.
283
+ const selfOf = (rel, sf, pos) => {
284
+ const line = lineAt(sf, pos);
285
+ const column = pos - lineStartsOf(sf)[line - 1] + 1;
286
+ return `${rel ?? ""}:${line}:${column}`;
287
+ };
288
+ exports.selfOf = selfOf;
289
+ // Depth of a node below `root` (0 = a direct child of the root).
290
+ const depthOf = (n, root) => {
291
+ let depth = 0;
292
+ let p = n.getParent();
293
+ while (p && p !== root) {
294
+ depth += 1;
295
+ p = p.getParent();
296
+ }
297
+ return depth;
298
+ };
299
+ exports.depthOf = depthOf;
300
+ // A node's absolute depth from the SourceFile (the SourceFile itself is 0),
301
+ // memoised per node. For a TRUE descendant of `root`, `depthOf` is the difference
302
+ // of two absolute depths — a subtraction instead of a fresh parent walk per
303
+ // descendant. Only used where the node is known to descend from the root.
304
+ const depthFromFile = (n) => {
305
+ const memos = memosOf(n);
306
+ const cached = memos.depth.get(n);
307
+ if (cached !== undefined)
308
+ return cached;
309
+ const parent = n.getParent();
310
+ const depth = parent ? depthFromFile(parent) + 1 : 0;
311
+ memos.depth.set(n, depth);
312
+ return depth;
313
+ };
314
+ // A node's own name. `getName()` throws on a destructured parameter
315
+ // (`({ a, b }) => …`): ts-morph's `getNameNode()` is undefined for a binding
316
+ // pattern, so the pattern's own text is what names it.
317
+ const nameOfNode = (node) => {
318
+ if (typeof node.getNameNode === "function") {
319
+ const nameNode = node.getNameNode();
320
+ return nameNode ? String(nameNode.getText()) : null;
321
+ }
322
+ return typeof node.getName === "function" ? (node.getName() ?? null) : null;
323
+ };
324
+ exports.nameOfNode = nameOfNode;
325
+ // Raw facts for ONE node, as the `kind` fact describes it. Every facet of
326
+ // `kind` — own, parent, ancestors, children, siblings, descendants — answers
327
+ // with this same descriptor; the extras (`depth`, `nested`, `members`, …) are
328
+ // what that particular facet knows on top of it.
329
+ const descriptor = (node) => ({
330
+ is: kindName(node),
331
+ name: nameOfNode(node),
332
+ line: startLine(node),
333
+ });
334
+ exports.descriptor = descriptor;
335
+ // Raw facts for one descendant node, relative to `root` (a file or a
336
+ // candidate). `nested` is set on function-like / loop nodes: true when another
337
+ // function-like node sits between the node and `root`.
338
+ const descendantFact = (d, root, depth = 0) => {
339
+ const f = { ...descriptor(d), depth };
340
+ if (d.getKind() === ts_morph_1.SyntaxKind.AsExpression) {
341
+ // The cast target as written; "is it `unknown`?" is the rule's question.
342
+ f.type = d.getTypeNode()?.getText() ?? null;
343
+ }
344
+ if (ts_morph_1.Node.isObjectLiteralExpression(d))
345
+ f.members = memberFacts(d);
346
+ if (isFunctionNode(d) || isLoopNode(d))
347
+ f.nested = isNestedIn(d, root) || (isFunctionNode(root) && d !== root);
348
+ return f;
349
+ };
350
+ exports.descendantFact = descendantFact;
351
+ // Is a function-like descendant nested inside another function-like node that
352
+ // is itself inside the candidate?
353
+ const isNestedIn = (fn, candidate) => {
354
+ let n = fn.getParent();
355
+ while (n && n !== candidate) {
356
+ if (isFunctionNode(n))
357
+ return true;
358
+ n = n.getParent();
359
+ }
360
+ return false;
361
+ };
362
+ // The lines a node spans, as ONE fact: `lines[0]` is where it starts,
363
+ // `lines[lines.length - 1]` where it ends, and everything the node contains is
364
+ // between them. A line count is `lines.length` — there is no second field for it.
365
+ const endLine = (n) => {
366
+ if (n.getKind() === ts_morph_1.SyntaxKind.SourceFile)
367
+ return lineAt(n.getSourceFile(), n.getEnd());
368
+ const memos = memosOf(n);
369
+ const cached = memos.endLine.get(n);
370
+ if (cached !== undefined)
371
+ return cached;
372
+ const line = lineAt(n.getSourceFile(), n.getEnd());
373
+ memos.endLine.set(n, line);
374
+ return line;
375
+ };
376
+ // The consecutive lines `first..last` inclusive, as a plain array — the one
377
+ // spelling of "a span of lines" shared by `linesOf` (a node) and `linesOfRange`
378
+ // (a comment's trivia range).
379
+ const rangeLines = (first, last) => {
380
+ const out = [];
381
+ for (let i = first; i <= last; i += 1)
382
+ out.push(i);
383
+ return out;
384
+ };
385
+ exports.rangeLines = rangeLines;
386
+ const linesOf = (node) => rangeLines(startLine(node), endLine(node));
387
+ exports.linesOf = linesOf;
388
+ // Is the declaration published? `export` sits on the STATEMENT, never on the
389
+ // value: for `export const f = () => …` it is written on the variable statement,
390
+ // so the search walks up to the node that carries it.
391
+ const isExported = (node) => {
392
+ let target = node;
393
+ while (target.getParent) {
394
+ if (typeof target.getModifiers === "function" &&
395
+ target.getModifiers().some((m) => m.getKind() === ts_morph_1.SyntaxKind.ExportKeyword))
396
+ return true;
397
+ const parent = target.getParent();
398
+ if (!parent || parent.getKind() === ts_morph_1.SyntaxKind.Block || parent.getKind() === ts_morph_1.SyntaxKind.SourceFile)
399
+ break;
400
+ target = parent;
401
+ }
402
+ return false;
403
+ };
404
+ exports.isExported = isExported;
405
+ // May the binding be reassigned? That is the `let`/`var` token and nothing else.
406
+ const isMutable = (node) => {
407
+ if (!ts_morph_1.Node.isVariableDeclaration(node))
408
+ return false;
409
+ const list = node.getParent();
410
+ if (!ts_morph_1.Node.isVariableDeclarationList(list))
411
+ return false;
412
+ const kind = String(list.getDeclarationKind());
413
+ return kind === "let" || kind === "var";
414
+ };
415
+ exports.isMutable = isMutable;
416
+ // ── The `kind` fact: a node's place in the tree ─────────────────────────────
417
+ //
418
+ // ONE fact for the node's position, and ONE shape for every entry in it. A rule
419
+ // that says "a function" is almost always too wide — a function is a
420
+ // declaration, a field of an object literal, a callback, a class method…
421
+ //
422
+ // kind.own — the node itself
423
+ // kind.parent — what holds it
424
+ // kind.ancestors — everything above it, nearest first
425
+ // kind.children — its direct children
426
+ // kind.siblings — the nodes next to it
427
+ // kind.descendants — everything below it, flat
428
+ // kind.initializer — what a declaration is initialised with
429
+ //
430
+ // Every entry is the SAME descriptor — `{ is, name, line }` — plus whatever that
431
+ // node has on top (`depth`, `nested`, `members`, …). One interface means one set
432
+ // of filters: `is`, `origin`, `members`, `depth` are queried with `equals` /
433
+ // `in` / `any` / … like any other fact, and no entry needs its own vocabulary.
434
+ // "What is around and below this node" is ONE question with ONE answer.
435
+ // The docs the parser attached to this declaration. A function carries its own;
436
+ // a binding does not — its doc hangs on the STATEMENT that declares it, and a
437
+ // function expression is what that binding is initialised WITH, so it is the
438
+ // same statement's doc. The climb goes through those wrappers only: never to an
439
+ // enclosing function, whose doc says nothing about this node.
440
+ const isVariableHolder = (n) => {
441
+ const kind = n.getKind();
442
+ return kind === ts_morph_1.SyntaxKind.VariableDeclaration || kind === ts_morph_1.SyntaxKind.VariableDeclarationList;
443
+ };
444
+ const jsDocsOf = (n) => n.getJsDocs?.() ?? [];
445
+ const parentOf = (n) => n.getParent?.();
446
+ const holdsAsInitializer = (parent, child) => parent !== undefined && parent.getKind() === ts_morph_1.SyntaxKind.VariableDeclaration && parent.getInitializer?.() === child;
447
+ const docsOf = (node) => {
448
+ let holder = node;
449
+ while (holder.getKind() !== ts_morph_1.SyntaxKind.VariableStatement) {
450
+ const parent = parentOf(holder);
451
+ if (!isVariableHolder(holder) && !holdsAsInitializer(parent, holder))
452
+ break;
453
+ holder = parent;
454
+ }
455
+ const docs = jsDocsOf(holder);
456
+ return docs.length ? docs : jsDocsOf(node);
457
+ };
458
+ // Everything below the node: no SyntaxList, no punctuation tokens — and the
459
+ // node's own documentation, which the parser keeps beside it rather than inside
460
+ // it. A doc block is a node like any other, so "what is written above this
461
+ // declaration" is a query over the same list, told apart by `is`.
462
+ const descendantsOf = (node) => {
463
+ const docs = docsOf(node);
464
+ const descendants = node.getDescendants();
465
+ // The common case has no attached docs, and `getDescendants()` already yields
466
+ // each node once — so no seen-set (and no per-node identity string) is built.
467
+ // Every node here is a true descendant of `node`, so its depth is the difference
468
+ // of the (memoised) depth-from-file, not a fresh parent walk.
469
+ if (docs.length === 0) {
470
+ const rootDepth = depthFromFile(node);
471
+ return descendants.filter(isMeaningful).map((d) => descendantFact(d, node, depthFromFile(d) - rootDepth - 1));
472
+ }
473
+ const seen = new Set();
474
+ const nodes = [...docs, ...descendants].filter((d) => {
475
+ // Identity is kind + span, not `getPos()`: several nodes start at the same
476
+ // position (a statement, its declaration list and its first keyword all
477
+ // begin together), and keying by position dropped the whole statement.
478
+ const id = `${d.getKind()}:${d.getStart()}:${d.getEnd()}`;
479
+ if (seen.has(id))
480
+ return false;
481
+ seen.add(id);
482
+ return isMeaningful(d);
483
+ });
484
+ return nodes.map((d) => descendantFact(d, node, depthOf(d, node)));
485
+ };
486
+ exports.descendantsOf = descendantsOf;
487
+ const ancestorsOf = (n) => {
488
+ const ancestors = [];
489
+ let cur = n.getParent?.();
490
+ for (let depth = 0; cur !== undefined && depth < 8; depth += 1) {
491
+ ancestors.push(descriptor(cur));
492
+ cur = cur.getParent?.();
493
+ }
494
+ return ancestors;
495
+ };
496
+ const initializerFact = (initializer) => {
497
+ if (!initializer)
498
+ return null;
499
+ return {
500
+ is: initializer.is,
501
+ origin: initializer.origin,
502
+ members: initializer.members ?? [],
503
+ ...(initializer.value !== undefined ? { value: initializer.value } : {}),
504
+ };
505
+ };
506
+ const kindFact = (n, initializer = null) => {
507
+ const parent = n.getParent?.() ?? null;
508
+ return {
509
+ own: descriptor(n),
510
+ parent: parent ? descriptor(parent) : null,
511
+ ancestors: ancestorsOf(n),
512
+ children: (n.getChildren?.() ?? []).map(descriptor),
513
+ siblings: (parent?.getChildren?.() ?? []).filter((c) => c !== n).map(descriptor),
514
+ descendants: descendantsOf(n),
515
+ initializer: initializerFact(initializer),
516
+ };
517
+ };
518
+ exports.kindFact = kindFact;
@@ -0,0 +1,6 @@
1
+ import type { Node } from "ts-morph";
2
+ import type { LooseNode } from "./loose";
3
+ import type { Candidate } from "@md-code/follow-architecture/entities/facts";
4
+ declare const isTypeNode: (n: Node) => boolean;
5
+ declare const typeFact: (node: LooseNode, rel: string) => Candidate;
6
+ export { typeFact, isTypeNode };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTypeNode = exports.typeFact = void 0;
4
+ // Type declarations — `interface` and `type`. They are candidates like any
5
+ // other, so a node can say `kind: [type, interface]` and a rule can tell a
6
+ // type-only file from a runtime one. A type has no code inside it, so it holds
7
+ // no actions: only where it is, the lines it spans, whether it is published —
8
+ // and what it is made of.
9
+ const tree_1 = require("./tree");
10
+ const declaration_1 = require("./declaration");
11
+ const isTypeNode = (n) => n.getKind() === tree_1.SK.InterfaceDeclaration || n.getKind() === tree_1.SK.TypeAliasDeclaration;
12
+ exports.isTypeNode = isTypeNode;
13
+ // The members of a shape: a property (`PropertySignature`), a method
14
+ // (`MethodSignature`), an index (`IndexSignature`), a call or a `new` signature.
15
+ // The parser's own kind name says which, so "is this data or behaviour?" is a
16
+ // query, never a list of names kept in sync here.
17
+ //
18
+ // A member whose type is ANOTHER inline shape carries its own members — the
19
+ // same fact an object-literal member carries (`memberFacts` in tree.js), so
20
+ // `shape.colors.section` is reachable as a fact whether the shape is written
21
+ // as a value or as a type. The walk stops at MAX_MEMBER_DEPTH for the same
22
+ // reason it does there: a pathological shape must not turn a report into a
23
+ // full tree walk. A type REFERENCE (`Foo`, `Foo<Bar>`) is not an inline shape
24
+ // and simply has no `members` — following references is the checker's job,
25
+ // not the syntax reader's.
26
+ const MAX_MEMBER_DEPTH = 4;
27
+ const isInlineShape = (typeNode) => typeNode?.getKind?.() === tree_1.SK.TypeLiteral;
28
+ const membersOf = (node, depth = 0) => {
29
+ const members = typeof node.getMembers === "function" ? node.getMembers() : [];
30
+ return members.map((m) => {
31
+ const name = typeof m.getName === "function" ? (m.getName() ?? null) : null;
32
+ const typeNode = (typeof m.getReturnTypeNode === "function" ? m.getReturnTypeNode() : null) ??
33
+ (typeof m.getTypeNode === "function" ? m.getTypeNode() : null);
34
+ const nested = depth < MAX_MEMBER_DEPTH && isInlineShape(typeNode);
35
+ return {
36
+ name,
37
+ is: m.getKindName(),
38
+ type: typeNode ? typeNode.getText() : null,
39
+ ...(nested ? { members: membersOf(typeNode, depth + 1) } : {}),
40
+ };
41
+ });
42
+ };
43
+ // What the shape is made of: `PropertySignature` is data, `MethodSignature` is
44
+ // behaviour, and the rule reads the difference off `is`.
45
+ const typeFact = (node, rel) => (0, declaration_1.declarationFact)(node, rel, membersOf(node));
46
+ exports.typeFact = typeFact;
@@ -0,0 +1,11 @@
1
+ import type { SourceFile } from "ts-morph";
2
+ import type { LooseNode } from "./loose";
3
+ import type { ReferencesFact } from "@md-code/follow-architecture/entities/facts";
4
+ declare const usageFact: (node: LooseNode, sf: SourceFile, { exported, relOf }: {
5
+ exported: boolean;
6
+ relOf?: (p: string) => string;
7
+ }) => {
8
+ references: ReferencesFact | null;
9
+ implementations: number | null;
10
+ };
11
+ export { usageFact };
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usageFact = void 0;
4
+ // What ts-morph knows BEYOND the syntax tree: who uses a name, and who
5
+ // implements a shape. Both are questions about the whole project, so they are
6
+ // asked once per named candidate and only where the answer can change a verdict:
7
+ // a name nothing outside its file mentions is a name nobody needs.
8
+ const notices_1 = require("@md-code/follow-architecture/report/notices");
9
+ const countReferences = (node, sf, relOf) => {
10
+ if (typeof node.findReferencesAsNodes !== "function")
11
+ return null;
12
+ let refs = [];
13
+ try {
14
+ refs = node.findReferencesAsNodes();
15
+ }
16
+ catch (error) {
17
+ const e = error;
18
+ // Who uses a name is a project-wide answer the checker may fail to give. The
19
+ // fact is then UNKNOWN (`null`), and the reason is reported.
20
+ (0, notices_1.notice)(`the references of \`${node.getText?.() ?? "a name"}\` could not be read`, e.message ?? String(e));
21
+ return null;
22
+ }
23
+ const file = sf.getFilePath();
24
+ const outside = refs.filter((r) => r.getSourceFile().getFilePath() !== file);
25
+ // The declaration itself is not a use.
26
+ const uses = refs.filter((r) => r !== node);
27
+ // WHO uses it — not only how many. "One file calls this helper" is the whole
28
+ // question behind "does it belong to a feature or to everybody", and a count
29
+ // cannot answer it: two files in one feature read the same as two features.
30
+ const where = (list) => [...new Set(list.map((r) => relOf(r.getSourceFile().getFilePath())))];
31
+ const files = where(outside);
32
+ return {
33
+ total: uses.length,
34
+ outside: outside.length,
35
+ // Every file the name APPEARS in.
36
+ files,
37
+ // …and the subset where it is USED: a reference inside `export { x } from
38
+ // "./x"` republishes the name instead of using it. Two facts, no verdict —
39
+ // whether a barrel counts as a caller is a question for the rule.
40
+ usedIn: where(outside.filter((r) => !insideExportFrom(r))),
41
+ };
42
+ };
43
+ // Is this reference part of an `export … from` statement? Syntax only: walk up
44
+ // to the statement that holds the name.
45
+ const insideExportFrom = (node) => {
46
+ for (let current = node.getParent?.(); current; current = current.getParent?.()) {
47
+ const kind = current.getKindName?.();
48
+ if (kind === "SourceFile")
49
+ return false;
50
+ if (kind === "ExportDeclaration")
51
+ return true;
52
+ }
53
+ return false;
54
+ };
55
+ // How many shapes declare themselves implementations of this one. An interface
56
+ // nobody implements is a shape the project carries and nothing depends on.
57
+ const countImplementations = (node) => {
58
+ if (typeof node.getImplementations !== "function")
59
+ return null;
60
+ try {
61
+ return node.getImplementations().length;
62
+ }
63
+ catch (error) {
64
+ const e = error;
65
+ // How many shapes implement this one is unknown when the checker fails; the
66
+ // reason is reported rather than counted as zero.
67
+ (0, notices_1.notice)(`the implementations of \`${node.getText?.() ?? "a shape"}\` could not be read`, e.message ?? String(e));
68
+ return null;
69
+ }
70
+ };
71
+ // `{ references, implementations }` — every candidate answers both, `null` where
72
+ // the question does not apply (a comment has no name; a local binding's reach is
73
+ // its own file). A fact set with holes is a fact set rules cannot rely on.
74
+ const usageFact = (node, sf, { exported, relOf = (p) => p }) => {
75
+ const named = typeof node.getName === "function" ? node.getName() : null;
76
+ return {
77
+ references: named && exported ? countReferences(node, sf, relOf) : null,
78
+ implementations: named && exported && node.getKindName() === "InterfaceDeclaration" ? countImplementations(node) : null,
79
+ };
80
+ };
81
+ exports.usageFact = usageFact;
@@ -0,0 +1,8 @@
1
+ import { Node } from "ts-morph";
2
+ import type { LooseNode } from "./loose";
3
+ import type { Initializer, Assertion } from "@md-code/follow-architecture/entities/facts";
4
+ declare const literalTextOf: (n: Node) => string | null;
5
+ declare const variableInitializer: (node: LooseNode) => Initializer | null;
6
+ declare const assertionOf: (node: LooseNode) => Assertion | null;
7
+ declare const isDisposable: (node: LooseNode) => boolean;
8
+ export { variableInitializer, assertionOf, isDisposable, literalTextOf };