@md-code/follow-architecture 0.1.0 → 0.3.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 (436) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +202 -0
  3. package/README.md +597 -126
  4. package/dist/aliases.d.ts +3 -0
  5. package/dist/aliases.js +12 -0
  6. package/dist/args.d.ts +14 -0
  7. package/dist/args.js +77 -0
  8. package/dist/bin/follow-architecture.d.ts +2 -0
  9. package/dist/bin/follow-architecture.js +23 -0
  10. package/dist/code-roles/classify.d.ts +11 -0
  11. package/dist/code-roles/classify.js +43 -0
  12. package/dist/code-roles/connector.d.ts +5 -0
  13. package/dist/code-roles/connector.js +114 -0
  14. package/dist/code-roles/project.d.ts +12 -0
  15. package/dist/code-roles/project.js +122 -0
  16. package/dist/code-roles/roles.d.ts +8 -0
  17. package/dist/code-roles/roles.js +190 -0
  18. package/dist/config-options.d.ts +53 -0
  19. package/dist/config-options.js +35 -0
  20. package/dist/config-project.d.ts +4 -0
  21. package/dist/config-project.js +74 -0
  22. package/dist/config-report.d.ts +19 -0
  23. package/dist/config-report.js +134 -0
  24. package/dist/config-rule.d.ts +70 -0
  25. package/dist/config-rule.js +118 -0
  26. package/dist/config-state.d.ts +14 -0
  27. package/dist/config-state.js +96 -0
  28. package/dist/config.d.ts +82 -0
  29. package/dist/config.js +38 -0
  30. package/dist/css/index.d.ts +27 -0
  31. package/dist/css/index.js +140 -0
  32. package/dist/css/syntax/css/gate.d.ts +2 -0
  33. package/dist/css/syntax/css/gate.js +69 -0
  34. package/dist/css/syntax/css/index.d.ts +7 -0
  35. package/dist/css/syntax/css/index.js +41 -0
  36. package/dist/css/syntax/css/reference.d.ts +3 -0
  37. package/dist/css/syntax/css/reference.js +24 -0
  38. package/dist/css/syntax/language.d.ts +25 -0
  39. package/dist/css/syntax/language.js +69 -0
  40. package/dist/css/syntax/scss/index.d.ts +25 -0
  41. package/dist/css/syntax/scss/index.js +85 -0
  42. package/dist/css/syntax/scss/reference.d.ts +3 -0
  43. package/dist/css/syntax/scss/reference.js +11 -0
  44. package/dist/css/syntax/styled/document.d.ts +68 -0
  45. package/dist/css/syntax/styled/document.js +241 -0
  46. package/dist/css/syntax/styled/markup.d.ts +6 -0
  47. package/dist/css/syntax/styled/markup.js +76 -0
  48. package/dist/css/syntax/styled/template.d.ts +23 -0
  49. package/dist/css/syntax/styled/template.js +61 -0
  50. package/dist/css/syntax/tailwind/tailwind-engine.d.ts +23 -0
  51. package/dist/css/syntax/tailwind/tailwind-engine.js +37 -0
  52. package/dist/css/syntax/tailwind/tailwind.d.ts +26 -0
  53. package/dist/css/syntax/tailwind/tailwind.js +118 -0
  54. package/dist/css/value/check.d.ts +86 -0
  55. package/dist/css/value/check.js +122 -0
  56. package/dist/css/value/expression/arithmetic.d.ts +7 -0
  57. package/dist/css/value/expression/arithmetic.js +69 -0
  58. package/dist/css/value/expression/block.d.ts +9 -0
  59. package/dist/css/value/expression/block.js +91 -0
  60. package/dist/css/value/expression/conditional.d.ts +8 -0
  61. package/dist/css/value/expression/conditional.js +53 -0
  62. package/dist/css/value/expression/index.d.ts +5 -0
  63. package/dist/css/value/expression/index.js +69 -0
  64. package/dist/css/value/expression/map.d.ts +7 -0
  65. package/dist/css/value/expression/map.js +113 -0
  66. package/dist/css/value/object/index.d.ts +5 -0
  67. package/dist/css/value/object/index.js +103 -0
  68. package/dist/css/value/object/members.d.ts +7 -0
  69. package/dist/css/value/object/members.js +103 -0
  70. package/dist/css/value/object/node.d.ts +8 -0
  71. package/dist/css/value/object/node.js +129 -0
  72. package/dist/css/value/object/path.d.ts +10 -0
  73. package/dist/css/value/object/path.js +146 -0
  74. package/dist/css/value/pieces.d.ts +61 -0
  75. package/dist/css/value/pieces.js +55 -0
  76. package/dist/css/value/resolve.d.ts +33 -0
  77. package/dist/css/value/resolve.js +94 -0
  78. package/dist/css/value/scope.d.ts +27 -0
  79. package/dist/css/value/scope.js +187 -0
  80. package/dist/css/value/substitute.d.ts +10 -0
  81. package/dist/css/value/substitute.js +113 -0
  82. package/dist/css/value/values.d.ts +23 -0
  83. package/dist/css/value/values.js +131 -0
  84. package/dist/entities/architecture.d.ts +162 -0
  85. package/dist/entities/architecture.js +2 -0
  86. package/dist/entities/ast/assignments-nodes.d.ts +10 -0
  87. package/dist/entities/ast/assignments-nodes.js +64 -0
  88. package/dist/entities/ast/assignments-raw.d.ts +6 -0
  89. package/dist/entities/ast/assignments-raw.js +86 -0
  90. package/dist/entities/ast/assignments-tagged.d.ts +5 -0
  91. package/dist/entities/ast/assignments-tagged.js +180 -0
  92. package/dist/entities/ast/assignments.d.ts +9 -0
  93. package/dist/entities/ast/assignments.js +78 -0
  94. package/dist/entities/ast/branches.d.ts +4 -0
  95. package/dist/entities/ast/branches.js +32 -0
  96. package/dist/entities/ast/calls.d.ts +6 -0
  97. package/dist/entities/ast/calls.js +134 -0
  98. package/dist/entities/ast/classes.d.ts +5 -0
  99. package/dist/entities/ast/classes.js +57 -0
  100. package/dist/entities/ast/climb.d.ts +12 -0
  101. package/dist/entities/ast/climb.js +17 -0
  102. package/dist/entities/ast/comments.d.ts +4 -0
  103. package/dist/entities/ast/comments.js +100 -0
  104. package/dist/entities/ast/declaration.d.ts +4 -0
  105. package/dist/entities/ast/declaration.js +26 -0
  106. package/dist/entities/ast/depth.d.ts +17 -0
  107. package/dist/entities/ast/depth.js +149 -0
  108. package/dist/entities/ast/enums.d.ts +6 -0
  109. package/dist/entities/ast/enums.js +17 -0
  110. package/dist/entities/ast/file-exports.d.ts +7 -0
  111. package/dist/entities/ast/file-exports.js +78 -0
  112. package/dist/entities/ast/file-facts.d.ts +13 -0
  113. package/dist/entities/ast/file-facts.js +35 -0
  114. package/dist/entities/ast/file-imports.d.ts +5 -0
  115. package/dist/entities/ast/file-imports.js +77 -0
  116. package/dist/entities/ast/file.d.ts +5 -0
  117. package/dist/entities/ast/file.js +22 -0
  118. package/dist/entities/ast/functions.d.ts +8 -0
  119. package/dist/entities/ast/functions.js +102 -0
  120. package/dist/entities/ast/heritage.d.ts +4 -0
  121. package/dist/entities/ast/heritage.js +36 -0
  122. package/dist/entities/ast/index.d.ts +6 -0
  123. package/dist/entities/ast/index.js +125 -0
  124. package/dist/entities/ast/kind.d.ts +5 -0
  125. package/dist/entities/ast/kind.js +28 -0
  126. package/dist/entities/ast/loose.d.ts +37 -0
  127. package/dist/entities/ast/loose.js +2 -0
  128. package/dist/entities/ast/modifiers.d.ts +5 -0
  129. package/dist/entities/ast/modifiers.js +32 -0
  130. package/dist/entities/ast/project.d.ts +9 -0
  131. package/dist/entities/ast/project.js +75 -0
  132. package/dist/entities/ast/properties.d.ts +11 -0
  133. package/dist/entities/ast/properties.js +171 -0
  134. package/dist/entities/ast/resolve.d.ts +16 -0
  135. package/dist/entities/ast/resolve.js +307 -0
  136. package/dist/entities/ast/tree.d.ts +29 -0
  137. package/dist/entities/ast/tree.js +351 -0
  138. package/dist/entities/ast/types.d.ts +6 -0
  139. package/dist/entities/ast/types.js +45 -0
  140. package/dist/entities/ast/usage.d.ts +11 -0
  141. package/dist/entities/ast/usage.js +81 -0
  142. package/dist/entities/ast/variables.d.ts +8 -0
  143. package/dist/entities/ast/variables.js +91 -0
  144. package/dist/entities/context.d.ts +29 -0
  145. package/dist/entities/context.js +2 -0
  146. package/dist/entities/facts.d.ts +261 -0
  147. package/dist/entities/facts.js +2 -0
  148. package/dist/entities/findings.d.ts +19 -0
  149. package/dist/entities/findings.js +2 -0
  150. package/dist/entities/kinds.d.ts +40 -0
  151. package/dist/entities/kinds.js +221 -0
  152. package/dist/entities/location/homes.d.ts +28 -0
  153. package/dist/entities/location/homes.js +169 -0
  154. package/dist/entities/location/place.d.ts +10 -0
  155. package/dist/entities/location/place.js +56 -0
  156. package/dist/entities/location/where.d.ts +17 -0
  157. package/dist/entities/location/where.js +218 -0
  158. package/dist/entities/location.d.ts +16 -0
  159. package/dist/entities/location.js +140 -0
  160. package/dist/entities/operators.d.ts +14 -0
  161. package/dist/entities/operators.js +30 -0
  162. package/dist/entities/overview/data.d.ts +43 -0
  163. package/dist/entities/overview/data.js +2 -0
  164. package/dist/entities/overview/decision.d.ts +60 -0
  165. package/dist/entities/overview/decision.js +2 -0
  166. package/dist/entities/overview/file-tree.d.ts +10 -0
  167. package/dist/entities/overview/file-tree.js +2 -0
  168. package/dist/entities/overview/finding.d.ts +58 -0
  169. package/dist/entities/overview/finding.js +2 -0
  170. package/dist/entities/overview/graph.d.ts +65 -0
  171. package/dist/entities/overview/graph.js +2 -0
  172. package/dist/entities/overview/input.d.ts +15 -0
  173. package/dist/entities/overview/input.js +2 -0
  174. package/dist/entities/overview/summaries.d.ts +79 -0
  175. package/dist/entities/overview/summaries.js +2 -0
  176. package/dist/entities/place.d.ts +5 -0
  177. package/dist/entities/place.js +2 -0
  178. package/dist/entities/queries.d.ts +9 -0
  179. package/dist/entities/queries.js +305 -0
  180. package/dist/entities/repair.d.ts +16 -0
  181. package/dist/entities/repair.js +23 -0
  182. package/dist/entities/schema.d.ts +8 -0
  183. package/dist/entities/schema.js +23 -0
  184. package/dist/entities/story.d.ts +47 -0
  185. package/dist/entities/story.js +2 -0
  186. package/dist/entities/structure-facts.d.ts +11 -0
  187. package/dist/entities/structure-facts.js +2 -0
  188. package/dist/entities/token.d.ts +23 -0
  189. package/dist/entities/token.js +2 -0
  190. package/dist/entities/tree/build.d.ts +5 -0
  191. package/dist/entities/tree/build.js +252 -0
  192. package/dist/entities/tree/entries.d.ts +7 -0
  193. package/dist/entities/tree/entries.js +120 -0
  194. package/dist/entities/tree/index.d.ts +6 -0
  195. package/dist/entities/tree/index.js +21 -0
  196. package/dist/entities/tree/match.d.ts +17 -0
  197. package/dist/entities/tree/match.js +176 -0
  198. package/dist/frameworks/angular/index.d.ts +7 -0
  199. package/dist/frameworks/angular/index.js +17 -0
  200. package/dist/frameworks/facet.d.ts +16 -0
  201. package/dist/frameworks/facet.js +2 -0
  202. package/dist/frameworks/index.d.ts +9 -0
  203. package/dist/frameworks/index.js +120 -0
  204. package/dist/frameworks/react/index.d.ts +7 -0
  205. package/dist/frameworks/react/index.js +214 -0
  206. package/dist/frameworks/vue/index.d.ts +7 -0
  207. package/dist/frameworks/vue/index.js +17 -0
  208. package/dist/invariants/index.d.ts +6 -0
  209. package/dist/invariants/index.js +299 -0
  210. package/dist/invariants/list-vars.d.ts +5 -0
  211. package/dist/invariants/list-vars.js +143 -0
  212. package/dist/invariants/name.d.ts +16 -0
  213. package/dist/invariants/name.js +18 -0
  214. package/dist/invariants/normalize.d.ts +4 -0
  215. package/dist/invariants/normalize.js +95 -0
  216. package/dist/invariants/vars.d.ts +20 -0
  217. package/dist/invariants/vars.js +117 -0
  218. package/dist/main.d.ts +7 -0
  219. package/dist/main.js +229 -0
  220. package/dist/nodes/child-roles.d.ts +3 -0
  221. package/dist/nodes/child-roles.js +12 -0
  222. package/dist/nodes/children.d.ts +25 -0
  223. package/dist/nodes/children.js +112 -0
  224. package/dist/nodes/finally/emit.d.ts +6 -0
  225. package/dist/nodes/finally/emit.js +55 -0
  226. package/dist/nodes/finally/index.d.ts +8 -0
  227. package/dist/nodes/finally/index.js +35 -0
  228. package/dist/nodes/finally/queries.d.ts +5 -0
  229. package/dist/nodes/finally/queries.js +22 -0
  230. package/dist/nodes/finally/relations-access.d.ts +5 -0
  231. package/dist/nodes/finally/relations-access.js +46 -0
  232. package/dist/nodes/finally/relations-edge.d.ts +29 -0
  233. package/dist/nodes/finally/relations-edge.js +125 -0
  234. package/dist/nodes/finally/relations-group.d.ts +31 -0
  235. package/dist/nodes/finally/relations-group.js +103 -0
  236. package/dist/nodes/finally/relations.d.ts +5 -0
  237. package/dist/nodes/finally/relations.js +81 -0
  238. package/dist/nodes/finally/required.d.ts +5 -0
  239. package/dist/nodes/finally/required.js +90 -0
  240. package/dist/nodes/finally/roles.d.ts +13 -0
  241. package/dist/nodes/finally/roles.js +41 -0
  242. package/dist/nodes/finally/violation.d.ts +17 -0
  243. package/dist/nodes/finally/violation.js +2 -0
  244. package/dist/nodes/similar.d.ts +21 -0
  245. package/dist/nodes/similar.js +156 -0
  246. package/dist/pipeline-facts.d.ts +11 -0
  247. package/dist/pipeline-facts.js +112 -0
  248. package/dist/pipeline-roles.d.ts +6 -0
  249. package/dist/pipeline-roles.js +75 -0
  250. package/dist/pipeline-unroled.d.ts +14 -0
  251. package/dist/pipeline-unroled.js +193 -0
  252. package/dist/pipeline.d.ts +7 -0
  253. package/dist/pipeline.js +73 -0
  254. package/dist/plugin.d.ts +2 -0
  255. package/dist/plugin.js +3 -0
  256. package/dist/report/asks.d.ts +55 -0
  257. package/dist/report/asks.js +50 -0
  258. package/dist/report/cli-report.d.ts +2 -0
  259. package/dist/report/cli-report.js +13 -0
  260. package/dist/report/config-error-guard.d.ts +8 -0
  261. package/dist/report/config-error-guard.js +5 -0
  262. package/dist/report/configErrors.d.ts +98 -0
  263. package/dist/report/configErrors.js +75 -0
  264. package/dist/report/errorTypes/codes/structure.d.ts +15 -0
  265. package/dist/report/errorTypes/codes/structure.js +76 -0
  266. package/dist/report/errorTypes/decision-maker.d.ts +23 -0
  267. package/dist/report/errorTypes/decision-maker.js +99 -0
  268. package/dist/report/errorTypes/destinations.d.ts +38 -0
  269. package/dist/report/errorTypes/destinations.js +147 -0
  270. package/dist/report/errorTypes/finding-type.d.ts +11 -0
  271. package/dist/report/errorTypes/finding-type.js +2 -0
  272. package/dist/report/errorTypes/index.d.ts +15 -0
  273. package/dist/report/errorTypes/index.js +45 -0
  274. package/dist/report/errorTypes/types/fileContents.d.ts +9 -0
  275. package/dist/report/errorTypes/types/fileContents.js +34 -0
  276. package/dist/report/errorTypes/types/unknownRole.d.ts +9 -0
  277. package/dist/report/errorTypes/types/unknownRole.js +22 -0
  278. package/dist/report/errorTypes/types/wrongAction.d.ts +22 -0
  279. package/dist/report/errorTypes/types/wrongAction.js +135 -0
  280. package/dist/report/errorTypes/types/wrongPlacement.d.ts +9 -0
  281. package/dist/report/errorTypes/types/wrongPlacement.js +57 -0
  282. package/dist/report/errorTypes/vocabulary/ids.d.ts +5 -0
  283. package/dist/report/errorTypes/vocabulary/ids.js +16 -0
  284. package/dist/report/errorTypes/vocabulary/phrases.d.ts +10 -0
  285. package/dist/report/errorTypes/vocabulary/phrases.js +174 -0
  286. package/dist/report/errorTypes/vocabulary/places.d.ts +8 -0
  287. package/dist/report/errorTypes/vocabulary/places.js +36 -0
  288. package/dist/report/errorTypes/vocabulary/verbs.d.ts +7 -0
  289. package/dist/report/errorTypes/vocabulary/verbs.js +30 -0
  290. package/dist/report/finding-from.d.ts +9 -0
  291. package/dist/report/finding-from.js +103 -0
  292. package/dist/report/notices.d.ts +4 -0
  293. package/dist/report/notices.js +31 -0
  294. package/dist/report/render-report.d.ts +12 -0
  295. package/dist/report/render-report.js +142 -0
  296. package/dist/report/user-report/build/bundle.d.ts +3 -0
  297. package/dist/report/user-report/build/bundle.js +169 -0
  298. package/dist/report/user-report/build/bundle.prebuilt.js +760 -0
  299. package/dist/report/user-report/data/collect.d.ts +4 -0
  300. package/dist/report/user-report/data/collect.js +80 -0
  301. package/dist/report/user-report/data/file-tree.d.ts +9 -0
  302. package/dist/report/user-report/data/file-tree.js +72 -0
  303. package/dist/report/user-report/data/finding-boundary.d.ts +9 -0
  304. package/dist/report/user-report/data/finding-boundary.js +21 -0
  305. package/dist/report/user-report/data/finding-plan.d.ts +16 -0
  306. package/dist/report/user-report/data/finding-plan.js +45 -0
  307. package/dist/report/user-report/data/finding-title.d.ts +12 -0
  308. package/dist/report/user-report/data/finding-title.js +36 -0
  309. package/dist/report/user-report/data/findings.d.ts +10 -0
  310. package/dist/report/user-report/data/findings.js +171 -0
  311. package/dist/report/user-report/data/graph-edges.d.ts +19 -0
  312. package/dist/report/user-report/data/graph-edges.js +109 -0
  313. package/dist/report/user-report/data/graph-helpers.d.ts +7 -0
  314. package/dist/report/user-report/data/graph-helpers.js +67 -0
  315. package/dist/report/user-report/data/graph-roles.d.ts +5 -0
  316. package/dist/report/user-report/data/graph-roles.js +71 -0
  317. package/dist/report/user-report/data/graph.d.ts +11 -0
  318. package/dist/report/user-report/data/graph.js +90 -0
  319. package/dist/report/user-report/data/invariants.d.ts +7 -0
  320. package/dist/report/user-report/data/invariants.js +62 -0
  321. package/dist/report/user-report/data/nodes.d.ts +11 -0
  322. package/dist/report/user-report/data/nodes.js +106 -0
  323. package/dist/report/user-report/data/role-examples.d.ts +16 -0
  324. package/dist/report/user-report/data/role-examples.js +94 -0
  325. package/dist/report/user-report/data/role-filters.d.ts +15 -0
  326. package/dist/report/user-report/data/role-filters.js +79 -0
  327. package/dist/report/user-report/data/role-marks.d.ts +5 -0
  328. package/dist/report/user-report/data/role-marks.js +79 -0
  329. package/dist/report/user-report/data/roles.d.ts +7 -0
  330. package/dist/report/user-report/data/roles.js +83 -0
  331. package/dist/report/user-report/data/scan.d.ts +8 -0
  332. package/dist/report/user-report/data/scan.js +59 -0
  333. package/dist/report/user-report/html/shell.d.ts +3 -0
  334. package/dist/report/user-report/html/shell.js +27 -0
  335. package/dist/report/user-report/index.d.ts +8 -0
  336. package/dist/report/user-report/index.js +48 -0
  337. package/dist/report/user-report/shared/describe.d.ts +7 -0
  338. package/dist/report/user-report/shared/describe.js +86 -0
  339. package/dist/scripts/audit-report.d.ts +2 -0
  340. package/dist/scripts/audit-report.js +147 -0
  341. package/dist/utils/accumulate.d.ts +6 -0
  342. package/dist/utils/accumulate.js +18 -0
  343. package/dist/utils/article.d.ts +2 -0
  344. package/dist/utils/article.js +12 -0
  345. package/dist/utils/classify.d.ts +12 -0
  346. package/dist/utils/classify.js +25 -0
  347. package/dist/utils/configs.d.ts +25 -0
  348. package/dist/utils/configs.js +87 -0
  349. package/dist/utils/count.d.ts +7 -0
  350. package/dist/utils/count.js +13 -0
  351. package/dist/utils/dispatch.d.ts +2 -0
  352. package/dist/utils/dispatch.js +27 -0
  353. package/dist/utils/distinct.d.ts +2 -0
  354. package/dist/utils/distinct.js +12 -0
  355. package/dist/utils/field.d.ts +14 -0
  356. package/dist/utils/field.js +60 -0
  357. package/dist/utils/file-name.d.ts +2 -0
  358. package/dist/utils/file-name.js +11 -0
  359. package/dist/utils/files.d.ts +7 -0
  360. package/dist/utils/files.js +73 -0
  361. package/dist/utils/fixpoint.d.ts +2 -0
  362. package/dist/utils/fixpoint.js +19 -0
  363. package/dist/utils/gate.d.ts +2 -0
  364. package/dist/utils/gate.js +12 -0
  365. package/dist/utils/group.d.ts +3 -0
  366. package/dist/utils/group.js +33 -0
  367. package/dist/utils/host.d.ts +3 -0
  368. package/dist/utils/host.js +13 -0
  369. package/dist/utils/imports.d.ts +12 -0
  370. package/dist/utils/imports.js +121 -0
  371. package/dist/utils/judged.d.ts +5 -0
  372. package/dist/utils/judged.js +19 -0
  373. package/dist/utils/keyed.d.ts +2 -0
  374. package/dist/utils/keyed.js +23 -0
  375. package/dist/utils/map-record.d.ts +2 -0
  376. package/dist/utils/map-record.js +11 -0
  377. package/dist/utils/path-label.d.ts +6 -0
  378. package/dist/utils/path-label.js +35 -0
  379. package/dist/utils/pattern.d.ts +18 -0
  380. package/dist/utils/pattern.js +191 -0
  381. package/dist/utils/permission.d.ts +16 -0
  382. package/dist/utils/permission.js +16 -0
  383. package/dist/utils/plural.d.ts +2 -0
  384. package/dist/utils/plural.js +9 -0
  385. package/dist/utils/qualified.d.ts +2 -0
  386. package/dist/utils/qualified.js +21 -0
  387. package/dist/utils/rank.d.ts +2 -0
  388. package/dist/utils/rank.js +24 -0
  389. package/dist/utils/read-field.d.ts +12 -0
  390. package/dist/utils/read-field.js +50 -0
  391. package/dist/utils/read-when.d.ts +2 -0
  392. package/dist/utils/read-when.js +17 -0
  393. package/dist/utils/reason.d.ts +4 -0
  394. package/dist/utils/reason.js +9 -0
  395. package/dist/utils/record.d.ts +3 -0
  396. package/dist/utils/record.js +21 -0
  397. package/dist/utils/resolve.d.ts +2 -0
  398. package/dist/utils/resolve.js +24 -0
  399. package/dist/utils/search.d.ts +2 -0
  400. package/dist/utils/search.js +16 -0
  401. package/dist/utils/seen.d.ts +6 -0
  402. package/dist/utils/seen.js +27 -0
  403. package/dist/utils/span.d.ts +5 -0
  404. package/dist/utils/span.js +2 -0
  405. package/dist/utils/speak.d.ts +2 -0
  406. package/dist/utils/speak.js +18 -0
  407. package/dist/utils/split.d.ts +8 -0
  408. package/dist/utils/split.js +8 -0
  409. package/dist/utils/template.d.ts +5 -0
  410. package/dist/utils/template.js +5 -0
  411. package/dist/utils/text.d.ts +4 -0
  412. package/dist/utils/text.js +42 -0
  413. package/dist/utils/tokenize.d.ts +2 -0
  414. package/dist/utils/tokenize.js +13 -0
  415. package/dist/utils/try-read.d.ts +4 -0
  416. package/dist/utils/try-read.js +24 -0
  417. package/dist/utils/typed-field.d.ts +3 -0
  418. package/dist/utils/typed-field.js +16 -0
  419. package/dist/utils/verdicts.d.ts +4 -0
  420. package/dist/utils/verdicts.js +20 -0
  421. package/entities/operators.ts +31 -0
  422. package/package.json +62 -19
  423. package/report/errorTypes/vocabulary/ids.ts +12 -0
  424. package/report/errorTypes/vocabulary/phrases.ts +161 -0
  425. package/report/errorTypes/vocabulary/places.ts +46 -0
  426. package/report/errorTypes/vocabulary/verbs.ts +31 -0
  427. package/report/user-report/shared/describe.ts +107 -0
  428. package/ast.js +0 -107
  429. package/bin/follow-architecture.js +0 -6
  430. package/config.js +0 -82
  431. package/entities/aliases.js +0 -10
  432. package/entities/invariants.js +0 -134
  433. package/entities/nodes.js +0 -112
  434. package/main.js +0 -95
  435. package/report.js +0 -73
  436. package/utils.js +0 -104
@@ -0,0 +1,351 @@
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.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, a role
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("../../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 role.
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 node's text as an IDENTITY, not as formatting. A fact is compared to what
34
+ // the architecture writes by hand (`origin: { equals: "t.model" }`,
35
+ // `source: { equals: "./x" }`), so the source LAYOUT must not leak into it: a
36
+ // chain broken across lines is the same callee, and roles silently stopped
37
+ // matching the moment it was not.
38
+ //
39
+ // Two rules, one helper:
40
+ // • a LITERAL denotes its VALUE — `'./x'` names the module `./x`, quotes are
41
+ // syntax and the import map holds the value; `Base<'a b'>` keeps its space;
42
+ // • everything else is its spelling with the whitespace removed — whitespace
43
+ // can never sit inside an identifier, a dot or `[0]`.
44
+ const QUOTED_OR_SPACE = /"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`|\s+/g;
45
+ const stripLayout = (text) => text.replace(QUOTED_OR_SPACE, (match) => (/^["'`]/.test(match) ? match : ""));
46
+ const nodeText = (node) => {
47
+ if (!node)
48
+ return "";
49
+ const value = typeof node.getLiteralText === "function" ? node.getLiteralText() : null;
50
+ if (typeof value === "string")
51
+ return value;
52
+ return stripLayout(String(node.getText?.() ?? ""));
53
+ };
54
+ exports.nodeText = nodeText;
55
+ const isFunctionNode = (n) => FUNCTION_KINDS.has(n.getKind());
56
+ exports.isFunctionNode = isFunctionNode;
57
+ const isLoopNode = (n) => LOOP_KINDS.has(n.getKind());
58
+ const isCallNode = (n) => CALL_KINDS.has(n.getKind());
59
+ exports.isCallNode = isCallNode;
60
+ // A class declaration or expression — a candidate like any other.
61
+ const isClassNode = (n) => n.getKind() === ts_morph_1.SyntaxKind.ClassDeclaration || n.getKind() === ts_morph_1.SyntaxKind.ClassExpression;
62
+ exports.isClassNode = isClassNode;
63
+ // Does a descendant belong to THIS piece, and not to a function nested inside
64
+ // it? A nested function is a candidate of its own, so what it does there is ITS
65
+ // work: counting it here too would attribute one line to two pieces.
66
+ const inThisPiece = (node, d) => {
67
+ for (let cur = d.getParent(); cur && cur !== node; cur = cur.getParent())
68
+ if (isFunctionNode(cur))
69
+ return false;
70
+ return true;
71
+ };
72
+ exports.inThisPiece = inThisPiece;
73
+ // Unwrap parenthesized expressions: `() => ({...})` yields a
74
+ // ParenthesizedExpression whose `getExpression()` is the real ObjectLiteral.
75
+ const unwrapParens = (node) => {
76
+ let n = node;
77
+ while (ts_morph_1.Node.isParenthesizedExpression(n))
78
+ n = n.getExpression();
79
+ return n;
80
+ };
81
+ exports.unwrapParens = unwrapParens;
82
+ // ── One node: name, line, depth, members ────────────────────────────────────
83
+ // A type as the parser reads it, or "any".
84
+ const typeText = (node) => {
85
+ try {
86
+ const t = node.getType();
87
+ return t.isAny() ? "any" : t.getText();
88
+ }
89
+ catch (error) {
90
+ // The checker fails on an import it cannot resolve (a broken path, a package
91
+ // that is not installed). That is NOT a type: the fact is UNKNOWN, and an
92
+ // unknown type must not take the analysis of the whole run down with it. The
93
+ // reason is reported, so a partial answer never passes for a clean one.
94
+ const file = node.getSourceFile?.()?.getFilePath?.() ?? "?";
95
+ const e = error;
96
+ (0, notices_1.notice)(`a type could not be read (${file})`, e.message ?? String(e));
97
+ return null;
98
+ }
99
+ };
100
+ exports.typeText = typeText;
101
+ // Raw per-member facts of an object literal: `[{name, is, type}]`. The engine
102
+ // records DATA, not verdicts — "does this literal have methods?" is a query
103
+ // (`members: { some: { is: { equals: "MethodDeclaration" } } }`).
104
+ // A property whose initializer is a LITERAL also carries the VALUE it was written
105
+ // with (`'#182022'`, `12`, `0`). That is what makes an object's `colors: { section:
106
+ // '#182022' }` readable as a COLOUR — a property of the thing itself, not of the
107
+ // folder it sits in.
108
+ const literalValueOf = (property) => {
109
+ const init = property.getInitializer?.();
110
+ if (!init)
111
+ return null;
112
+ if (ts_morph_1.Node.isNumericLiteral(init))
113
+ return Number(init.getLiteralText());
114
+ if (ts_morph_1.Node.isStringLiteral(init) || ts_morph_1.Node.isNoSubstitutionTemplateLiteral(init))
115
+ return init.getLiteralText();
116
+ return null;
117
+ };
118
+ // A member whose initializer is ANOTHER object literal carries its own members —
119
+ // that is what makes `spec.colors.section` reachable as a fact. The walk stops at
120
+ // MAX_MEMBER_DEPTH so a pathological literal cannot turn a report into a full tree
121
+ // walk; what is NOT an object literal (`new Map(…)`, a call, a method shorthand)
122
+ // simply has no `members`, instead of an empty list that would read like "none".
123
+ const MAX_MEMBER_DEPTH = 4;
124
+ const memberFacts = (objLit, depth = 0) => objLit.getProperties().map((p) => {
125
+ const init = p.getInitializer?.() ?? null;
126
+ const nested = depth < MAX_MEMBER_DEPTH && init !== null && ts_morph_1.Node.isObjectLiteralExpression(init) ? init : null;
127
+ return {
128
+ name: typeof p.getName === "function" ? p.getName() : null,
129
+ is: kindName(p),
130
+ type: typeText(p),
131
+ value: literalValueOf(p),
132
+ ...(nested ? { members: memberFacts(nested, depth + 1) } : {}),
133
+ };
134
+ });
135
+ exports.memberFacts = memberFacts;
136
+ // A descendant is meaningful when it is not a SyntaxList and not a punctuation
137
+ // token. Keywords (NumberKeyword, …) are kept — they are meaningful.
138
+ const isMeaningful = (d) => {
139
+ if (d.getKind() === ts_morph_1.SyntaxKind.SyntaxList)
140
+ return false;
141
+ const k = d.getKind();
142
+ if (k >= ts_morph_1.SyntaxKind.FirstToken && k <= ts_morph_1.SyntaxKind.LastToken)
143
+ return d.getKindName().endsWith("Keyword");
144
+ return true;
145
+ };
146
+ exports.isMeaningful = isMeaningful;
147
+ const startLine = (n) => n.getSourceFile().getLineAndColumnAtPos(n.getStart()).line;
148
+ exports.startLine = startLine;
149
+ // A candidate's OWN IDENTITY: where it starts — file, line and column, as one
150
+ // comparable value. A name is not an identity (three files have a `run`), a line
151
+ // is not one either (a `const` and its arrow start on the same line), so every
152
+ // fact that points at a piece can point at this instead of at a name that
153
+ // aliases.
154
+ const selfOf = (rel, sf, pos) => {
155
+ const { line, column } = sf.getLineAndColumnAtPos(pos);
156
+ return `${rel ?? ""}:${line}:${column}`;
157
+ };
158
+ exports.selfOf = selfOf;
159
+ // Depth of a node below `root` (0 = a direct child of the root).
160
+ const depthOf = (n, root) => {
161
+ let depth = 0;
162
+ let p = n.getParent();
163
+ while (p && p !== root) {
164
+ depth += 1;
165
+ p = p.getParent();
166
+ }
167
+ return depth;
168
+ };
169
+ exports.depthOf = depthOf;
170
+ // A node's own name. `getName()` throws on a destructured parameter
171
+ // (`({ a, b }) => …`): ts-morph's `getNameNode()` is undefined for a binding
172
+ // pattern, so the pattern's own text is what names it.
173
+ const nameOfNode = (node) => {
174
+ if (typeof node.getNameNode === "function") {
175
+ const nameNode = node.getNameNode();
176
+ return nameNode ? String(nameNode.getText()) : null;
177
+ }
178
+ return typeof node.getName === "function" ? (node.getName() ?? null) : null;
179
+ };
180
+ exports.nameOfNode = nameOfNode;
181
+ // Raw facts for ONE node, as the `kind` fact describes it. Every facet of
182
+ // `kind` — own, parent, ancestors, children, siblings, descendants — answers
183
+ // with this same descriptor; the extras (`depth`, `nested`, `members`, …) are
184
+ // what that particular facet knows on top of it.
185
+ const descriptor = (node) => ({
186
+ is: kindName(node),
187
+ name: nameOfNode(node),
188
+ line: startLine(node),
189
+ });
190
+ exports.descriptor = descriptor;
191
+ // Raw facts for one descendant node, relative to `root` (a file or a
192
+ // candidate). `nested` is set on function-like / loop nodes: true when another
193
+ // function-like node sits between the node and `root`.
194
+ const descendantFact = (d, root, depth = 0) => {
195
+ const f = { ...descriptor(d), depth, snippet: d.getText().trim().slice(0, 120) };
196
+ // A short, reportable label: the node's name when it has one, otherwise its
197
+ // (trimmed) source text. Feeds the `{what}` / `{snippet}` report vars.
198
+ f.snippet = d.getText().trim().slice(0, 120);
199
+ if (d.getKind() === ts_morph_1.SyntaxKind.AsExpression) {
200
+ // The cast target as written; "is it `unknown`?" is the rule's question.
201
+ f.type = d.getTypeNode()?.getText() ?? null;
202
+ }
203
+ if (ts_morph_1.Node.isObjectLiteralExpression(d))
204
+ f.members = memberFacts(d);
205
+ if (isFunctionNode(d) || isLoopNode(d))
206
+ f.nested = isNestedIn(d, root) || (isFunctionNode(root) && d !== root);
207
+ return f;
208
+ };
209
+ exports.descendantFact = descendantFact;
210
+ // Is a function-like descendant nested inside another function-like node that
211
+ // is itself inside the candidate?
212
+ const isNestedIn = (fn, candidate) => {
213
+ let n = fn.getParent();
214
+ while (n && n !== candidate) {
215
+ if (isFunctionNode(n))
216
+ return true;
217
+ n = n.getParent();
218
+ }
219
+ return false;
220
+ };
221
+ // The lines a node spans, as ONE fact: `lines[0]` is where it starts,
222
+ // `lines[lines.length - 1]` where it ends, and everything the node contains is
223
+ // between them. A line count is `lines.length` — there is no second field for it.
224
+ const endLine = (n) => n.getSourceFile().getLineAndColumnAtPos(n.getEnd()).line;
225
+ // The consecutive lines `first..last` inclusive, as a plain array — the one
226
+ // spelling of "a span of lines" shared by `linesOf` (a node) and `linesOfRange`
227
+ // (a comment's trivia range).
228
+ const rangeLines = (first, last) => {
229
+ const out = [];
230
+ for (let i = first; i <= last; i += 1)
231
+ out.push(i);
232
+ return out;
233
+ };
234
+ exports.rangeLines = rangeLines;
235
+ const linesOf = (node) => rangeLines(startLine(node), endLine(node));
236
+ exports.linesOf = linesOf;
237
+ // Is the declaration published? `export` sits on the STATEMENT, never on the
238
+ // value: for `export const f = () => …` it is written on the variable statement,
239
+ // so the search walks up to the node that carries it.
240
+ const isExported = (node) => {
241
+ let target = node;
242
+ while (target.getParent) {
243
+ if (typeof target.getModifiers === "function" && target.getModifiers().some((m) => m.getKind() === ts_morph_1.SyntaxKind.ExportKeyword))
244
+ return true;
245
+ const parent = target.getParent();
246
+ if (!parent || parent.getKind() === ts_morph_1.SyntaxKind.Block || parent.getKind() === ts_morph_1.SyntaxKind.SourceFile)
247
+ break;
248
+ target = parent;
249
+ }
250
+ return false;
251
+ };
252
+ exports.isExported = isExported;
253
+ // May the binding be reassigned? That is the `let`/`var` token and nothing else.
254
+ const isMutable = (node) => {
255
+ if (!ts_morph_1.Node.isVariableDeclaration(node))
256
+ return false;
257
+ const list = node.getParent();
258
+ if (!ts_morph_1.Node.isVariableDeclarationList(list))
259
+ return false;
260
+ const kind = String(list.getDeclarationKind());
261
+ return kind === "let" || kind === "var";
262
+ };
263
+ exports.isMutable = isMutable;
264
+ // ── The `kind` fact: a node's place in the tree ─────────────────────────────
265
+ //
266
+ // ONE fact for the node's position, and ONE shape for every entry in it. A rule
267
+ // that says "a function" is almost always too wide — a function is a
268
+ // declaration, a field of an object literal, a callback, a class method…
269
+ //
270
+ // kind.own — the node itself
271
+ // kind.parent — what holds it
272
+ // kind.ancestors — everything above it, nearest first
273
+ // kind.children — its direct children
274
+ // kind.siblings — the nodes next to it
275
+ // kind.descendants — everything below it, flat
276
+ // kind.initializer — what a declaration is initialised with
277
+ //
278
+ // Every entry is the SAME descriptor — `{ is, name, line }` — plus whatever that
279
+ // node has on top (`depth`, `nested`, `members`, …). One interface means one set
280
+ // of filters: `is`, `origin`, `members`, `depth` are queried with `equals` /
281
+ // `in` / `any` / … like any other fact, and no entry needs its own vocabulary.
282
+ // "What is around and below this node" is ONE question with ONE answer.
283
+ // The docs the parser attached to this declaration. A function carries its own;
284
+ // a binding does not — its doc hangs on the STATEMENT that declares it, and a
285
+ // function expression is what that binding is initialised WITH, so it is the
286
+ // same statement's doc. The climb goes through those wrappers only: never to an
287
+ // enclosing function, whose doc says nothing about this node.
288
+ const isVariableHolder = (n) => {
289
+ const kind = n.getKind();
290
+ return kind === ts_morph_1.SyntaxKind.VariableDeclaration || kind === ts_morph_1.SyntaxKind.VariableDeclarationList;
291
+ };
292
+ const jsDocsOf = (n) => n.getJsDocs?.() ?? [];
293
+ const parentOf = (n) => n.getParent?.();
294
+ const holdsAsInitializer = (parent, child) => parent !== undefined && parent.getKind() === ts_morph_1.SyntaxKind.VariableDeclaration && parent.getInitializer?.() === child;
295
+ const docsOf = (node) => {
296
+ let holder = node;
297
+ while (holder.getKind() !== ts_morph_1.SyntaxKind.VariableStatement) {
298
+ const parent = parentOf(holder);
299
+ if (!isVariableHolder(holder) && !holdsAsInitializer(parent, holder))
300
+ break;
301
+ holder = parent;
302
+ }
303
+ const docs = jsDocsOf(holder);
304
+ return docs.length ? docs : jsDocsOf(node);
305
+ };
306
+ // Everything below the node: no SyntaxList, no punctuation tokens — and the
307
+ // node's own documentation, which the parser keeps beside it rather than inside
308
+ // it. A doc block is a node like any other, so "what is written above this
309
+ // declaration" is a query over the same list, told apart by `is`.
310
+ const descendantsOf = (node) => {
311
+ const seen = new Set();
312
+ const nodes = [...docsOf(node), ...node.getDescendants()].filter((d) => {
313
+ // Identity is kind + span, not `getPos()`: several nodes start at the same
314
+ // position (a statement, its declaration list and its first keyword all
315
+ // begin together), and keying by position dropped the whole statement.
316
+ const id = `${d.getKind()}:${d.getStart()}:${d.getEnd()}`;
317
+ if (seen.has(id))
318
+ return false;
319
+ seen.add(id);
320
+ return isMeaningful(d);
321
+ });
322
+ return nodes.map((d) => descendantFact(d, node, depthOf(d, node)));
323
+ };
324
+ exports.descendantsOf = descendantsOf;
325
+ const ancestorsOf = (n) => {
326
+ const ancestors = [];
327
+ let cur = n.getParent?.();
328
+ for (let depth = 0; cur !== undefined && depth < 8; depth += 1) {
329
+ ancestors.push(descriptor(cur));
330
+ cur = cur.getParent?.();
331
+ }
332
+ return ancestors;
333
+ };
334
+ const initializerFact = (initializer) => {
335
+ if (!initializer)
336
+ return null;
337
+ return { is: initializer.is, origin: initializer.origin, members: initializer.members ?? [], ...(initializer.value !== undefined ? { value: initializer.value } : {}) };
338
+ };
339
+ const kindFact = (n, initializer = null) => {
340
+ const parent = n.getParent?.() ?? null;
341
+ return {
342
+ own: descriptor(n),
343
+ parent: parent ? descriptor(parent) : null,
344
+ ancestors: ancestorsOf(n),
345
+ children: (n.getChildren?.() ?? []).map(descriptor),
346
+ siblings: (parent?.getChildren?.() ?? []).filter((c) => c !== n).map(descriptor),
347
+ descendants: descendantsOf(n),
348
+ initializer: initializerFact(initializer),
349
+ };
350
+ };
351
+ 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 "../facts";
4
+ declare const isTypeNode: (n: Node) => boolean;
5
+ declare const typeFact: (node: LooseNode, rel: string) => Candidate;
6
+ export { typeFact, isTypeNode };
@@ -0,0 +1,45 @@
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) ?? (typeof m.getTypeNode === "function" ? m.getTypeNode() : null);
33
+ const nested = depth < MAX_MEMBER_DEPTH && isInlineShape(typeNode);
34
+ return {
35
+ name,
36
+ is: m.getKindName(),
37
+ type: typeNode ? typeNode.getText() : null,
38
+ ...(nested ? { members: membersOf(typeNode, depth + 1) } : {}),
39
+ };
40
+ });
41
+ };
42
+ // What the shape is made of: `PropertySignature` is data, `MethodSignature` is
43
+ // behaviour, and the rule reads the difference off `is`.
44
+ const typeFact = (node, rel) => (0, declaration_1.declarationFact)(node, rel, membersOf(node));
45
+ 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 "../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("../../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 "../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 };
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.literalTextOf = exports.isDisposable = exports.assertionOf = exports.variableInitializer = void 0;
4
+ // Variable declarations — what a variable is initialised with. That is the whole
5
+ // question: whether the binding may be reassigned is `mutable` (ast/tree.js),
6
+ // and who may write into the value is the `assign`/`mutate` relation.
7
+ //
8
+ // Two things the initializer alone cannot say are read here: the ASSERTION on it
9
+ // (`as const`, `satisfies X`, `<X>x`) and whether the binding is DISPOSABLE
10
+ // (`using x = …`), which runs a `[Symbol.dispose]` at the end of its scope.
11
+ const ts_morph_1 = require("ts-morph");
12
+ const tree_1 = require("./tree");
13
+ const properties_1 = require("./properties");
14
+ // A STATIC STRING keeps its text — a quoted string and a backtick string without
15
+ // substitutions are both static. The ONE reading of "a literal's own text",
16
+ // shared by the initializer fact below and the CSS facet's class-attribute
17
+ // reader (`css/markup`): a class list written as `const cls = "flex p-4"` is a
18
+ // declaration list, and the text is the fact that makes it readable.
19
+ const literalTextOf = (n) => {
20
+ if (ts_morph_1.Node.isStringLiteral(n) || ts_morph_1.Node.isNoSubstitutionTemplateLiteral(n))
21
+ return n.getLiteralText();
22
+ return null;
23
+ };
24
+ exports.literalTextOf = literalTextOf;
25
+ // The initializer, in the same shape as `kind.initializer`: the parser's kind of
26
+ // the expression, its origin (`t.model(...)` → "t.model"), and — for an object
27
+ // literal — raw per-member facts. A STATIC STRING initializer keeps its text
28
+ // (`value`) via the shared `literalTextOf` above.
29
+ // A published anonymous value (`export default { … }`) has no binding of its
30
+ // own: the export assignment IS its declaration, and the expression it exports
31
+ // is its initializer — the same fact, read off the node that carries it.
32
+ const initOf = (n) => {
33
+ if (n.getKind() === tree_1.SK.VariableDeclaration)
34
+ return n.getInitializer?.() ?? null;
35
+ if (n.getKind() === tree_1.SK.ExportAssignment)
36
+ return n.getExpression?.() ?? null;
37
+ return null;
38
+ };
39
+ const variableInitializer = (node) => {
40
+ const init = initOf(node);
41
+ if (!init)
42
+ return null;
43
+ const value = literalTextOf(init);
44
+ return {
45
+ is: (0, tree_1.kindName)(init),
46
+ origin: (0, properties_1.leftmostOrigin)(init),
47
+ members: ts_morph_1.Node.isObjectLiteralExpression(init) ? (0, tree_1.memberFacts)(init) : [],
48
+ ...(value !== null ? { value } : {}),
49
+ };
50
+ };
51
+ exports.variableInitializer = variableInitializer;
52
+ // `x as Foo`, `x satisfies Foo`, `<Foo>x` — the assertion is part of what the
53
+ // variable IS, and `as const` is the one that changes its shape.
54
+ const ASSERTIONS = new Map([
55
+ [tree_1.SK.AsExpression, "as"],
56
+ [tree_1.SK.SatisfiesExpression, "satisfies"],
57
+ [tree_1.SK.TypeAssertionExpression, "asserts"],
58
+ ]);
59
+ const outermost = (n) => {
60
+ let expr = n;
61
+ while (ts_morph_1.Node.isParenthesizedExpression(expr))
62
+ expr = expr.getExpression();
63
+ return expr;
64
+ };
65
+ const typeTextOfExpr = (expr) => {
66
+ const typeNode = expr.getTypeNode?.() ?? null;
67
+ if (typeNode)
68
+ return typeNode.getText();
69
+ return expr.getType?.().getText?.() ?? null;
70
+ };
71
+ const assertionOf = (node) => {
72
+ const init = node.getKind() === tree_1.SK.VariableDeclaration ? node.getInitializer?.() : null;
73
+ if (!init)
74
+ return null;
75
+ // Assertions nest and sit under parentheses, so the outermost one is unwrapped
76
+ // first: `(x as const) satisfies Y` is still an assertion.
77
+ const expr = outermost(init);
78
+ const form = ASSERTIONS.get(expr.getKind());
79
+ if (!form)
80
+ return null;
81
+ const text = typeTextOfExpr(expr);
82
+ return { form, type: text, isConst: text === "const" };
83
+ };
84
+ exports.assertionOf = assertionOf;
85
+ // `using x = …` / `await using x = …` — the binding is disposed at scope exit.
86
+ const isDisposable = (node) => {
87
+ const list = node.getKind() === tree_1.SK.VariableDeclaration ? node.getParent() : null;
88
+ const flags = typeof list?.getDeclarationKind === "function" ? String(list.getDeclarationKind()) : "";
89
+ return flags === "using" || flags === "await using";
90
+ };
91
+ exports.isDisposable = isDisposable;
@@ -0,0 +1,29 @@
1
+ import type { Project, SourceFile } from "ts-morph";
2
+ import type { Arch } from "./architecture";
3
+ import type { FileFacts } from "./facts";
4
+ import type { Facts } from "./kinds";
5
+ import type { ResolveContext } from "../utils/imports";
6
+ import type { ObjectLiteral } from "../css/value/scope";
7
+ type FileContext = {
8
+ abs?: string;
9
+ rel: string;
10
+ dir?: string;
11
+ basename?: string;
12
+ sf?: SourceFile;
13
+ repoRoot?: string;
14
+ aliases?: Record<string, string>;
15
+ arch?: Arch;
16
+ roles?: string[];
17
+ roleCtx?: {
18
+ present: string[];
19
+ candidates: FileFacts["candidates"];
20
+ } | null;
21
+ facts?: Facts | null;
22
+ repoFiles?: string[];
23
+ dedupe?: Map<string, Set<string>>;
24
+ objectsFor?: (slugs: readonly string[]) => ObjectLiteral[];
25
+ };
26
+ type ScanContext = ResolveContext & {
27
+ project: Project;
28
+ };
29
+ export type { FileContext, ScanContext };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });