repometry 0.0.0-stage → 0.2.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 (274) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +28 -2
  3. package/package.json +64 -4
  4. package/target/main/resources/report/json/compact-json-v1.schema.json +24 -0
  5. package/target/main/resources/report/json/comparison-v1.schema.json +65 -0
  6. package/target/main/resources/report/json/config-v1.schema.json +33 -0
  7. package/target/main/resources/report/json/diff-coverage-v1.schema.json +55 -0
  8. package/target/main/resources/report/json/file-metrics-v1.schema.json +134 -0
  9. package/target/main/resources/report/json/inspection-context-v1.schema.json +172 -0
  10. package/target/main/resources/report/json/metabranch-v1.schema.json +9 -0
  11. package/target/main/resources/report/json/metric-catalog-v1.schema.json +31 -0
  12. package/target/main/resources/report/json/public-history-v1.schema.json +50 -0
  13. package/target/main/resources/report/json/pull-review-v1.schema.json +97 -0
  14. package/target/main/resources/report/json/quality-history-v1.schema.json +51 -0
  15. package/target/main/resources/report/json/report-v1.schema.json +65 -0
  16. package/target/main/resources/report/json/report-v2.schema.json +252 -0
  17. package/target/main/resources/report/json/repository-summary-v1.schema.json +181 -0
  18. package/target/main/resources/report/json/viewer-details-v1.schema.json +343 -0
  19. package/target/main/resources/report/json/viewer-inspection-v1.schema.json +13 -0
  20. package/target/main/resources/viewer/files.css +578 -0
  21. package/target/main/resources/viewer/index.html +120 -0
  22. package/target/main/resources/viewer/projects.html +52 -0
  23. package/target/main/resources/viewer/styles.css +560 -0
  24. package/target/main/resources/viewer/viewer-pulls.css +64 -0
  25. package/target/main/ts/api/gh/github.d.ts +6 -0
  26. package/target/main/ts/api/gh/github.js +92 -0
  27. package/target/main/ts/api/git/blob-batch.d.ts +10 -0
  28. package/target/main/ts/api/git/blob-batch.js +106 -0
  29. package/target/main/ts/api/git/changes.d.ts +22 -0
  30. package/target/main/ts/api/git/changes.js +108 -0
  31. package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
  32. package/target/main/ts/api/git/commit-metadata.js +53 -0
  33. package/target/main/ts/api/git/git-churn.d.ts +9 -0
  34. package/target/main/ts/api/git/git-churn.js +71 -0
  35. package/target/main/ts/api/git/git-reader.d.ts +16 -0
  36. package/target/main/ts/api/git/git-reader.js +74 -0
  37. package/target/main/ts/api/git/git.d.ts +21 -0
  38. package/target/main/ts/api/git/git.js +153 -0
  39. package/target/main/ts/api/git/inspection-source.d.ts +15 -0
  40. package/target/main/ts/api/git/inspection-source.js +31 -0
  41. package/target/main/ts/api/git/local-sources.d.ts +5 -0
  42. package/target/main/ts/api/git/local-sources.js +47 -0
  43. package/target/main/ts/api/git/local.d.ts +3 -0
  44. package/target/main/ts/api/git/local.js +36 -0
  45. package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
  46. package/target/main/ts/api/git/metabranch-worktree.js +35 -0
  47. package/target/main/ts/api/git/source-cache.d.ts +3 -0
  48. package/target/main/ts/api/git/source-cache.js +57 -0
  49. package/target/main/ts/api/import/finding-import.d.ts +9 -0
  50. package/target/main/ts/api/import/finding-import.js +227 -0
  51. package/target/main/ts/api/import/lcov-files.d.ts +5 -0
  52. package/target/main/ts/api/import/lcov-files.js +14 -0
  53. package/target/main/ts/api/import/profile-file.d.ts +4 -0
  54. package/target/main/ts/api/import/profile-file.js +17 -0
  55. package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
  56. package/target/main/ts/api/worker/remote-executor.js +46 -0
  57. package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
  58. package/target/main/ts/api/worker/worker-protocol.js +102 -0
  59. package/target/main/ts/api/worker/worker.d.ts +5 -0
  60. package/target/main/ts/api/worker/worker.js +86 -0
  61. package/target/main/ts/cli/arguments.d.ts +28 -0
  62. package/target/main/ts/cli/arguments.js +111 -0
  63. package/target/main/ts/cli/config.d.ts +13 -0
  64. package/target/main/ts/cli/config.js +58 -0
  65. package/target/main/ts/cli/imports.d.ts +7 -0
  66. package/target/main/ts/cli/imports.js +30 -0
  67. package/target/main/ts/cli/main.d.ts +2 -0
  68. package/target/main/ts/cli/main.js +379 -0
  69. package/target/main/ts/cli/reporting.d.ts +18 -0
  70. package/target/main/ts/cli/reporting.js +104 -0
  71. package/target/main/ts/cli/revisions.d.ts +6 -0
  72. package/target/main/ts/cli/revisions.js +16 -0
  73. package/target/main/ts/cli/store.d.ts +13 -0
  74. package/target/main/ts/cli/store.js +39 -0
  75. package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
  76. package/target/main/ts/compose/analyze-snapshot.js +164 -0
  77. package/target/main/ts/compose/attach-churn.d.ts +2 -0
  78. package/target/main/ts/compose/attach-churn.js +50 -0
  79. package/target/main/ts/compose/diff-coverage.d.ts +20 -0
  80. package/target/main/ts/compose/diff-coverage.js +57 -0
  81. package/target/main/ts/compose/inspect.d.ts +23 -0
  82. package/target/main/ts/compose/inspect.js +45 -0
  83. package/target/main/ts/compose/plugin-list.d.ts +6 -0
  84. package/target/main/ts/compose/plugin-list.js +10 -0
  85. package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
  86. package/target/main/ts/compose/prepare-metabranch.js +17 -0
  87. package/target/main/ts/compose/review.d.ts +16 -0
  88. package/target/main/ts/compose/review.js +39 -0
  89. package/target/main/ts/compose/sources.d.ts +3 -0
  90. package/target/main/ts/compose/sources.js +30 -0
  91. package/target/main/ts/core/engine/execute.d.ts +10 -0
  92. package/target/main/ts/core/engine/execute.js +50 -0
  93. package/target/main/ts/core/engine/manifest.d.ts +4 -0
  94. package/target/main/ts/core/engine/manifest.js +105 -0
  95. package/target/main/ts/core/engine/plan.d.ts +22 -0
  96. package/target/main/ts/core/engine/plan.js +107 -0
  97. package/target/main/ts/core/engine/plugin.d.ts +59 -0
  98. package/target/main/ts/core/engine/plugin.js +4 -0
  99. package/target/main/ts/core/engine/report-products.d.ts +16 -0
  100. package/target/main/ts/core/engine/report-products.js +86 -0
  101. package/target/main/ts/core/model/changes.d.ts +8 -0
  102. package/target/main/ts/core/model/changes.js +2 -0
  103. package/target/main/ts/core/model/churn.d.ts +11 -0
  104. package/target/main/ts/core/model/churn.js +5 -0
  105. package/target/main/ts/core/model/clone-source.d.ts +16 -0
  106. package/target/main/ts/core/model/clone-source.js +15 -0
  107. package/target/main/ts/core/model/code-structure.d.ts +30 -0
  108. package/target/main/ts/core/model/code-structure.js +32 -0
  109. package/target/main/ts/core/model/comparison.d.ts +24 -0
  110. package/target/main/ts/core/model/comparison.js +1 -0
  111. package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
  112. package/target/main/ts/core/model/diff-coverage.js +1 -0
  113. package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
  114. package/target/main/ts/core/model/finding-ignore.js +36 -0
  115. package/target/main/ts/core/model/finding.d.ts +28 -0
  116. package/target/main/ts/core/model/finding.js +29 -0
  117. package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
  118. package/target/main/ts/core/model/ignore-rule.js +1 -0
  119. package/target/main/ts/core/model/measurement.d.ts +33 -0
  120. package/target/main/ts/core/model/measurement.js +30 -0
  121. package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
  122. package/target/main/ts/core/model/metric-descriptor.js +1 -0
  123. package/target/main/ts/core/model/plugin-data.d.ts +25 -0
  124. package/target/main/ts/core/model/plugin-data.js +1 -0
  125. package/target/main/ts/core/model/pull-review.d.ts +48 -0
  126. package/target/main/ts/core/model/pull-review.js +1 -0
  127. package/target/main/ts/core/model/quality-summary.d.ts +42 -0
  128. package/target/main/ts/core/model/quality-summary.js +64 -0
  129. package/target/main/ts/core/model/report.d.ts +40 -0
  130. package/target/main/ts/core/model/report.js +5 -0
  131. package/target/main/ts/core/model/scanner-import.d.ts +39 -0
  132. package/target/main/ts/core/model/scanner-import.js +29 -0
  133. package/target/main/ts/core/model/snapshot.d.ts +15 -0
  134. package/target/main/ts/core/model/snapshot.js +51 -0
  135. package/target/main/ts/core/model/source-locator.d.ts +7 -0
  136. package/target/main/ts/core/model/source-locator.js +1 -0
  137. package/target/main/ts/core/model/source.d.ts +23 -0
  138. package/target/main/ts/core/model/source.js +1 -0
  139. package/target/main/ts/core/ports/report.d.ts +9 -0
  140. package/target/main/ts/core/ports/report.js +2 -0
  141. package/target/main/ts/core/ports/source-provider.d.ts +14 -0
  142. package/target/main/ts/core/ports/source-provider.js +5 -0
  143. package/target/main/ts/core/profile/exclusions.d.ts +11 -0
  144. package/target/main/ts/core/profile/exclusions.js +58 -0
  145. package/target/main/ts/core/profile/maintainability.d.ts +31 -0
  146. package/target/main/ts/core/profile/maintainability.js +10 -0
  147. package/target/main/ts/core/profile/profile.d.ts +4 -0
  148. package/target/main/ts/core/profile/profile.js +11 -0
  149. package/target/main/ts/core/usecases/compare.d.ts +6 -0
  150. package/target/main/ts/core/usecases/compare.js +146 -0
  151. package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
  152. package/target/main/ts/core/usecases/diff-coverage-policy.js +11 -0
  153. package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
  154. package/target/main/ts/core/usecases/diff-coverage.js +16 -0
  155. package/target/main/ts/core/usecases/inspect.d.ts +38 -0
  156. package/target/main/ts/core/usecases/inspect.js +42 -0
  157. package/target/main/ts/core/usecases/review.d.ts +31 -0
  158. package/target/main/ts/core/usecases/review.js +129 -0
  159. package/target/main/ts/index.d.ts +35 -0
  160. package/target/main/ts/index.js +18 -0
  161. package/target/main/ts/plugin.d.ts +14 -0
  162. package/target/main/ts/plugin.js +6 -0
  163. package/target/main/ts/plugins/coverage/coverage.d.ts +25 -0
  164. package/target/main/ts/plugins/coverage/coverage.js +199 -0
  165. package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
  166. package/target/main/ts/plugins/coverage/diff-coverage.js +90 -0
  167. package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
  168. package/target/main/ts/plugins/duplication/duplication.js +94 -0
  169. package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
  170. package/target/main/ts/plugins/language-js/babel-provider.js +47 -0
  171. package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
  172. package/target/main/ts/plugins/language-js/clone-candidates.js +65 -0
  173. package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
  174. package/target/main/ts/plugins/language-js/code-lines.js +36 -0
  175. package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
  176. package/target/main/ts/plugins/language-js/function-facts.js +61 -0
  177. package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
  178. package/target/main/ts/plugins/language-js/structural-observations.js +80 -0
  179. package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
  180. package/target/main/ts/plugins/maintainability/maintainability.js +43 -0
  181. package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
  182. package/target/main/ts/plugins/maintainability/structural-smells.js +16 -0
  183. package/target/main/ts/plugins/source/forges.d.ts +4 -0
  184. package/target/main/ts/plugins/source/forges.js +80 -0
  185. package/target/main/ts/plugins/structure/structure.d.ts +2 -0
  186. package/target/main/ts/plugins/structure/structure.js +38 -0
  187. package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
  188. package/target/main/ts/report/html/app/viewer-chart.js +711 -0
  189. package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
  190. package/target/main/ts/report/html/app/viewer-commits.js +280 -0
  191. package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
  192. package/target/main/ts/report/html/app/viewer-data.js +105 -0
  193. package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
  194. package/target/main/ts/report/html/app/viewer-files.js +2104 -0
  195. package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
  196. package/target/main/ts/report/html/app/viewer-filter.js +492 -0
  197. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +70 -0
  198. package/target/main/ts/report/html/app/viewer-metric-registry.js +224 -0
  199. package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
  200. package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
  201. package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
  202. package/target/main/ts/report/html/app/viewer-profile.js +401 -0
  203. package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
  204. package/target/main/ts/report/html/app/viewer-projects.js +90 -0
  205. package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
  206. package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
  207. package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
  208. package/target/main/ts/report/html/app/viewer-source.js +313 -0
  209. package/target/main/ts/report/html/app/viewer-trends.d.ts +73 -0
  210. package/target/main/ts/report/html/app/viewer-trends.js +423 -0
  211. package/target/main/ts/report/html/app/viewer.d.ts +1 -0
  212. package/target/main/ts/report/html/app/viewer.js +735 -0
  213. package/target/main/ts/report/html/site/badges.d.ts +14 -0
  214. package/target/main/ts/report/html/site/badges.js +40 -0
  215. package/target/main/ts/report/html/site/export-site.d.ts +22 -0
  216. package/target/main/ts/report/html/site/export-site.js +150 -0
  217. package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
  218. package/target/main/ts/report/html/site/exported-server.js +71 -0
  219. package/target/main/ts/report/html/site/local-server.d.ts +7 -0
  220. package/target/main/ts/report/html/site/local-server.js +65 -0
  221. package/target/main/ts/report/html/site/projects.d.ts +3 -0
  222. package/target/main/ts/report/html/site/projects.js +80 -0
  223. package/target/main/ts/report/html/site/server.d.ts +4 -0
  224. package/target/main/ts/report/html/site/server.js +65 -0
  225. package/target/main/ts/report/html/site/source-route.d.ts +6 -0
  226. package/target/main/ts/report/html/site/source-route.js +23 -0
  227. package/target/main/ts/report/json/projections/commit-summary.d.ts +12 -0
  228. package/target/main/ts/report/json/projections/commit-summary.js +124 -0
  229. package/target/main/ts/report/json/projections/components.d.ts +4 -0
  230. package/target/main/ts/report/json/projections/components.js +30 -0
  231. package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
  232. package/target/main/ts/report/json/projections/file-metrics.js +244 -0
  233. package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
  234. package/target/main/ts/report/json/projections/inspection-context.js +93 -0
  235. package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
  236. package/target/main/ts/report/json/projections/inspection-details.js +70 -0
  237. package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
  238. package/target/main/ts/report/json/projections/metric-values.js +58 -0
  239. package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
  240. package/target/main/ts/report/json/projections/public-history.js +17 -0
  241. package/target/main/ts/report/json/store/components.d.ts +2 -0
  242. package/target/main/ts/report/json/store/components.js +32 -0
  243. package/target/main/ts/report/json/store/local-store.d.ts +13 -0
  244. package/target/main/ts/report/json/store/local-store.js +180 -0
  245. package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
  246. package/target/main/ts/report/json/store/pull-review-store.js +52 -0
  247. package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
  248. package/target/main/ts/report/json/validation/metabranch.js +8 -0
  249. package/target/main/ts/report/json/validation/report.d.ts +15 -0
  250. package/target/main/ts/report/json/validation/report.js +65 -0
  251. package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
  252. package/target/main/ts/report/json/validation/summary-validation.js +28 -0
  253. package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
  254. package/target/main/ts/report/json/wire/compact-json.js +76 -0
  255. package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
  256. package/target/main/ts/report/json/wire/component-model.js +1 -0
  257. package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
  258. package/target/main/ts/report/json/wire/domain-types.js +1 -0
  259. package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
  260. package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
  261. package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
  262. package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
  263. package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
  264. package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
  265. package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
  266. package/target/main/ts/report/json/wire/project-model.js +1 -0
  267. package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
  268. package/target/main/ts/report/json/wire/public-history-model.js +6 -0
  269. package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
  270. package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
  271. package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
  272. package/target/main/ts/report/json/wire/summary-model.js +1 -0
  273. package/target/main/ts/report.d.ts +11 -0
  274. package/target/main/ts/report.js +6 -0
@@ -0,0 +1,18 @@
1
+ export { pluginApi } from './core/engine/plugin.js';
2
+ export { plan } from './core/engine/plan.js';
3
+ export { execute } from './core/engine/execute.js';
4
+ export { analyzeSnapshot, inspect } from './compose/inspect.js';
5
+ export { diffCoverageSchema, measureDiffCoverage } from './compose/diff-coverage.js';
6
+ export { reviewPull, reviewExitCode } from './compose/review.js';
7
+ export { compareInspections, comparisonSchema } from './core/usecases/compare.js';
8
+ export { compareInspections as compare } from './core/usecases/compare.js';
9
+ export { measureDiffCoverage as diffCoverage } from './compose/diff-coverage.js';
10
+ export { review } from './compose/review.js';
11
+ export { fileMetrics, fileMetricsSchema } from './report/json/projections/file-metrics.js';
12
+ export { LocalReportStore } from './report/json/store/local-store.js';
13
+ export { GitReportReader } from './api/git/git-reader.js';
14
+ export { readReport, reportSchema } from './report/json/validation/report.js';
15
+ export { coverageGrade, qualitySummary } from './core/model/quality-summary.js';
16
+ export { pullReviewSchema } from './core/model/pull-review.js';
17
+ export { pullReviewsSchema } from './report/json/wire/pull-review-model.js';
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ export { pluginApi } from './core/engine/plugin.js';
2
+ export type { DataContract, InspectionInputs, Operation, Plugin, PluginConfigSchema, Product, RuleDescriptor } from './core/engine/plugin.js';
3
+ export type { FileClaims, LegacyPlugin, MetricDescriptor, MetricScope, PluginKind, ProductDeclaration } from './core/engine/plugin.js';
4
+ export { codeStructure } from './core/model/code-structure.js';
5
+ export type { CodeStructure, FunctionComplexity, StructuralCheck, StructuralObservation } from './core/model/code-structure.js';
6
+ export type { Candidate, CloneSource } from './core/model/clone-source.js';
7
+ export { sourceFile } from './core/model/snapshot.js';
8
+ export type { InventoryFile, SourceFile, SourceSnapshot } from './core/model/source.js';
9
+ export { measurements } from './core/model/measurement.js';
10
+ export type { Measurement } from './core/model/measurement.js';
11
+ export { findingResult } from './core/model/finding.js';
12
+ export type { Finding, FindingResult } from './core/model/finding.js';
13
+ export type { SourceContext, SourcePlugin, SourceProvider } from './core/ports/source-provider.js';
14
+ export type { SourceLocator } from './core/model/source-locator.js';
@@ -0,0 +1,6 @@
1
+ export { pluginApi } from './core/engine/plugin.js';
2
+ export { codeStructure } from './core/model/code-structure.js';
3
+ export { sourceFile } from './core/model/snapshot.js';
4
+ export { measurements } from './core/model/measurement.js';
5
+ export { findingResult } from './core/model/finding.js';
6
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1,25 @@
1
+ import type { DataContract, Plugin } from '../../core/engine/plugin.js';
2
+ import type { Measurement } from '../../core/model/measurement.js';
3
+ export interface CoverageInput {
4
+ readonly text: string;
5
+ readonly root: string;
6
+ readonly sourceLines: ReadonlyMap<string, number>;
7
+ readonly excludes?: (path: string) => boolean;
8
+ }
9
+ interface CoverageResult {
10
+ readonly measurements: readonly Measurement[];
11
+ readonly gaps: readonly {
12
+ readonly path: string;
13
+ readonly reason: string;
14
+ }[];
15
+ }
16
+ export declare const lcovInput: DataContract<CoverageInput>;
17
+ export declare const coverageResult: DataContract<CoverageResult>;
18
+ export declare const coverage: Plugin;
19
+ export declare function mapCoverage({ text, root, sourceLines, excludes }: CoverageInput): {
20
+ files: Map<string, Map<number, boolean>>;
21
+ branches: Map<string, Map<string, boolean>>;
22
+ functions: Map<string, Map<string, boolean>>;
23
+ gaps: Map<string, string>;
24
+ };
25
+ export {};
@@ -0,0 +1,199 @@
1
+ import { posix, win32 } from 'node:path';
2
+ import { isRecord, pluginApi } from '../../core/engine/plugin.js';
3
+ import { comparePaths } from '../../core/model/snapshot.js';
4
+ import { definitions, measurements } from '../../core/model/measurement.js';
5
+ export const lcovInput = {
6
+ id: 'repometry.lcov-input/v1',
7
+ accepts: (value) => isRecord(value) && typeof value.text === 'string'
8
+ && typeof value.root === 'string' && value.sourceLines instanceof Map
9
+ && (value.excludes === undefined || typeof value.excludes === 'function'),
10
+ };
11
+ export const coverageResult = {
12
+ id: 'repometry.coverage-result/v1',
13
+ accepts: (value) => isRecord(value) && measurements.accepts(value.measurements)
14
+ && Array.isArray(value.gaps) && value.gaps.every(gap => isRecord(gap) && typeof gap.path === 'string' && typeof gap.reason === 'string'),
15
+ };
16
+ export const coverage = {
17
+ id: 'lcov',
18
+ version: '1.2.0',
19
+ api: pluginApi,
20
+ kinds: ['coverage', 'import'],
21
+ produces: [{ contract: coverageResult.id, persistence: 'report', metrics: [
22
+ { id: definitions.coverage, label: 'Line coverage', unit: 'ratio', scope: 'file', aggregate: 'sum', better: 'higher',
23
+ ratio: { of: definitions.coveredLines, over: definitions.coverableLines }, bands: [0.6, 0.7, 0.8, 0.9], group: 'Coverage' },
24
+ { id: definitions.coveredLines, label: 'Covered lines', unit: 'count', scope: 'file', aggregate: 'sum', better: 'higher', group: 'Coverage' },
25
+ { id: definitions.coverableLines, label: 'Measured lines', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Coverage' },
26
+ { id: definitions.branchCoverage, label: 'Branch coverage', unit: 'ratio', scope: 'file', aggregate: 'sum', better: 'higher',
27
+ ratio: { of: definitions.coveredBranches, over: definitions.coverableBranches }, bands: [0.6, 0.7, 0.8, 0.9], group: 'Coverage' },
28
+ { id: definitions.coveredBranches, label: 'Covered branches', unit: 'count', scope: 'file', aggregate: 'sum', better: 'higher', group: 'Coverage' },
29
+ { id: definitions.coverableBranches, label: 'Measured branches', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Coverage' },
30
+ { id: definitions.functionCoverage, label: 'Function coverage', unit: 'ratio', scope: 'file', aggregate: 'sum', better: 'higher',
31
+ ratio: { of: definitions.coveredFunctions, over: definitions.coverableFunctions }, bands: [0.6, 0.7, 0.8, 0.9], group: 'Coverage' },
32
+ { id: definitions.coveredFunctions, label: 'Covered functions', unit: 'count', scope: 'file', aggregate: 'sum', better: 'higher', group: 'Coverage' },
33
+ { id: definitions.coverableFunctions, label: 'Measured functions', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Coverage' },
34
+ ] }],
35
+ operations: [{
36
+ id: 'import',
37
+ role: 'inspection',
38
+ inputs: { report: lcovInput },
39
+ output: coverageResult,
40
+ execute: inputs => importCoverage(inputs.read('report', lcovInput)),
41
+ }],
42
+ };
43
+ export function mapCoverage({ text, root, sourceLines, excludes }) {
44
+ const files = new Map();
45
+ // Branches by line, block and branch. Functions by name and its occurrence in the record: tools such as c8 repeat a
46
+ // name for different functions and list FNDA in FN order. Several reports merge by any hit.
47
+ const branches = new Map();
48
+ const declared = new Map();
49
+ const called = new Map();
50
+ const occurrences = { declared: new Map(), called: new Map() };
51
+ const occurrence = (seen, name) => {
52
+ const count = (seen.get(name) ?? 0) + 1;
53
+ seen.set(name, count);
54
+ return `${name}#${count}`;
55
+ };
56
+ const gaps = new Map();
57
+ let active;
58
+ let ignored = false;
59
+ let sawSource = false;
60
+ const lines = text.split(/\r?\n/);
61
+ for (const [index, line] of lines.entries()) {
62
+ if (line.startsWith('SF:')) {
63
+ if (active !== undefined || line.length === 3)
64
+ throw new Error(`Unexpected LCOV source at line ${index + 1}`);
65
+ active = normalizeLcovPath(root, line.slice(3));
66
+ occurrences.declared.clear();
67
+ occurrences.called.clear();
68
+ sawSource = true;
69
+ ignored = excludes?.(active) ?? false;
70
+ if (ignored)
71
+ continue;
72
+ if (!sourceLines.has(active))
73
+ gaps.set(active, 'LCOV source is outside the inspected file set');
74
+ else if (!files.has(active))
75
+ files.set(active, new Map());
76
+ }
77
+ else if (line.startsWith('DA:')) {
78
+ if (active === undefined)
79
+ throw new Error(`LCOV line data outside a source record at line ${index + 1}`);
80
+ if (ignored)
81
+ continue;
82
+ const match = /^DA:([1-9]\d*),(\d+)(?:,[^,]+)?$/.exec(line);
83
+ const number = Number(match?.[1]);
84
+ const hits = Number(match?.[2]);
85
+ if (!Number.isSafeInteger(number) || !Number.isSafeInteger(hits))
86
+ throw new Error(`Invalid LCOV line data at line ${index + 1}`);
87
+ const file = files.get(active);
88
+ const limit = sourceLines.get(active);
89
+ if (limit !== undefined && number > limit)
90
+ gaps.set(active, 'LCOV refers to a line outside the inspected source');
91
+ else if (file)
92
+ file.set(number, (file.get(number) ?? false) || hits > 0);
93
+ }
94
+ else if (line.startsWith('BRDA:') || line.startsWith('FN:') || line.startsWith('FNDA:')) {
95
+ if (active === undefined)
96
+ throw new Error(`LCOV data outside a source record at line ${index + 1}`);
97
+ if (ignored || !files.has(active))
98
+ continue;
99
+ const branch = /^BRDA:([1-9]\d*),([^,]+),([^,]+),(\d+|-)$/.exec(line);
100
+ const declaration = /^FN:[1-9]\d*(?:,[1-9]\d*)?,(.+)$/.exec(line);
101
+ const call = /^FNDA:(\d+),(.+)$/.exec(line);
102
+ if (branch) {
103
+ const taken = branch[4] !== '-' && Number(branch[4]) > 0;
104
+ const key = `${branch[1]},${branch[2]},${branch[3]}`;
105
+ const file = branches.get(active) ?? new Map();
106
+ file.set(key, (file.get(key) ?? false) || taken);
107
+ branches.set(active, file);
108
+ }
109
+ else if (declaration) {
110
+ declared.set(active, (declared.get(active) ?? new Set()).add(occurrence(occurrences.declared, declaration[1])));
111
+ }
112
+ else if (call) {
113
+ const key = occurrence(occurrences.called, call[2]);
114
+ const file = called.get(active) ?? new Map();
115
+ file.set(key, (file.get(key) ?? false) || Number(call[1]) > 0);
116
+ called.set(active, file);
117
+ }
118
+ else {
119
+ throw new Error(`Invalid LCOV data at line ${index + 1}`);
120
+ }
121
+ }
122
+ else if (line === 'end_of_record') {
123
+ if (active === undefined)
124
+ throw new Error(`Unexpected LCOV record end at line ${index + 1}`);
125
+ active = undefined;
126
+ }
127
+ }
128
+ if (active !== undefined)
129
+ throw new Error('Unterminated LCOV source record');
130
+ if (!sawSource && text.trim() !== '')
131
+ throw new Error('LCOV contains no source records');
132
+ const functions = new Map([...declared].map(([path, names]) => [path, new Map([...names].map(name => [name, called.get(path)?.get(name) ?? false]))]));
133
+ return { files, branches, functions, gaps };
134
+ }
135
+ function importCoverage(input) {
136
+ const { files, branches, functions, gaps } = mapCoverage(input);
137
+ const rows = [];
138
+ let totalCovered = 0;
139
+ let totalLines = 0;
140
+ for (const [path, hits] of [...files].sort(([left], [right]) => comparePaths(left, right))) {
141
+ if (gaps.has(path))
142
+ continue;
143
+ let covered = 0;
144
+ for (const hit of hits.values())
145
+ if (hit)
146
+ covered++;
147
+ totalCovered += covered;
148
+ totalLines += hits.size;
149
+ rows.push({ definition: definitions.coverage, target: 'file', path, covered, total: hits.size, value: ratio(covered, hits.size) });
150
+ }
151
+ rows.push({ definition: definitions.coverage, target: 'repository', covered: totalCovered, total: totalLines, value: ratio(totalCovered, totalLines) });
152
+ const counts = rows.flatMap(({ target, path, covered, total }) => [
153
+ { definition: definitions.coveredLines, target, path, value: covered ?? null },
154
+ { definition: definitions.coverableLines, target, path, value: total ?? null },
155
+ ]);
156
+ const extra = [
157
+ ...hitRows(branches, gaps, definitions.branchCoverage, definitions.coveredBranches, definitions.coverableBranches),
158
+ ...hitRows(functions, gaps, definitions.functionCoverage, definitions.coveredFunctions, definitions.coverableFunctions),
159
+ ];
160
+ return { measurements: [...rows, ...counts, ...extra],
161
+ gaps: [...gaps].sort(([left], [right]) => comparePaths(left, right)).map(([path, reason]) => ({ path, reason })) };
162
+ }
163
+ /** Per-file and repository ratios with their counts, for a kind the LCOV reports; nothing when it reports none. */
164
+ function hitRows(files, gaps, ratioId, coveredId, totalId) {
165
+ const rows = [];
166
+ let totalCovered = 0;
167
+ let totalCount = 0;
168
+ for (const [path, hits] of [...files].sort(([left], [right]) => comparePaths(left, right))) {
169
+ if (gaps.has(path) || hits.size === 0)
170
+ continue;
171
+ let covered = 0;
172
+ for (const hit of hits.values())
173
+ if (hit)
174
+ covered++;
175
+ totalCovered += covered;
176
+ totalCount += hits.size;
177
+ rows.push({ definition: ratioId, target: 'file', path, covered, total: hits.size, value: ratio(covered, hits.size) });
178
+ }
179
+ if (totalCount === 0)
180
+ return [];
181
+ rows.push({ definition: ratioId, target: 'repository', covered: totalCovered, total: totalCount, value: ratio(totalCovered, totalCount) });
182
+ return [...rows, ...rows.flatMap(({ target, path, covered, total }) => [
183
+ { definition: coveredId, target, path, value: covered ?? null },
184
+ { definition: totalId, target, path, value: total ?? null },
185
+ ])];
186
+ }
187
+ function ratio(covered, total) {
188
+ return total === 0 ? null : covered / total;
189
+ }
190
+ function normalizeLcovPath(root, path) {
191
+ const platform = /^(?:[a-z]:[\\/]|\\\\)/i.test(root) ? win32 : posix;
192
+ const candidate = platform.isAbsolute(path) ? platform.relative(root, path) : path;
193
+ if (platform.isAbsolute(candidate))
194
+ return candidate;
195
+ if (platform === win32)
196
+ return posix.normalize(candidate.replaceAll('\\', '/'));
197
+ return posix.normalize(candidate);
198
+ }
199
+ //# sourceMappingURL=coverage.js.map
@@ -0,0 +1,7 @@
1
+ import type { DataContract, Plugin } from '../../core/engine/plugin.js';
2
+ import type { GitChanges } from '../../core/model/changes.js';
3
+ import type { DiffCoverageResult } from '../../core/model/diff-coverage.js';
4
+ export type { DiffCoverage } from '../../core/model/diff-coverage.js';
5
+ export declare const changesInput: DataContract<GitChanges>;
6
+ export declare const diffCoverageResult: DataContract<DiffCoverageResult>;
7
+ export declare const diffCoverage: Plugin;
@@ -0,0 +1,90 @@
1
+ import { isRecord, pluginApi } from '../../core/engine/plugin.js';
2
+ import { comparePaths } from '../../core/model/snapshot.js';
3
+ import { lcovInput, mapCoverage } from './coverage.js';
4
+ export const changesInput = {
5
+ id: 'repometry.git-line-changes/v1',
6
+ accepts: (value) => isRecord(value) && value.files instanceof Map && value.gaps instanceof Map,
7
+ };
8
+ export const diffCoverageResult = {
9
+ id: 'repometry.diff-coverage-result/v1',
10
+ accepts: (value) => isRecord(value) && Array.isArray(value.files) && Array.isArray(value.gaps)
11
+ && Array.isArray(value.uncovered)
12
+ && (value.status === 'complete' || value.status === 'partial' || value.status === 'not-applicable')
13
+ && typeof value.covered === 'number' && typeof value.total === 'number'
14
+ && (value.percent === null || typeof value.percent === 'number'),
15
+ };
16
+ export const diffCoverage = {
17
+ id: 'diff-coverage',
18
+ version: '1.0.0',
19
+ api: pluginApi,
20
+ kinds: ['coverage'],
21
+ produces: [{ contract: diffCoverageResult.id, persistence: 'transient' }],
22
+ operations: [{
23
+ id: 'measure',
24
+ role: 'inspection',
25
+ inputs: { changes: changesInput, lcov: lcovInput },
26
+ output: diffCoverageResult,
27
+ execute: inputs => measure(inputs.read('changes', changesInput), inputs.read('lcov', lcovInput)),
28
+ }],
29
+ };
30
+ function measure(changes, input) {
31
+ if (changes.files.size === 0 && changes.gaps.size === 0) {
32
+ return { status: 'not-applicable', covered: 0, total: 0, percent: null, files: [], gaps: [], uncovered: [] };
33
+ }
34
+ const lcov = mapCoverage(input);
35
+ const gaps = new Map([...lcov.gaps, ...changes.gaps]);
36
+ const files = [];
37
+ const uncovered = [];
38
+ let covered = 0;
39
+ let total = 0;
40
+ for (const [path, ranges] of changes.files) {
41
+ const addedLines = ranges.reduce((sum, range) => sum + range.last - range.first + 1, 0);
42
+ const lines = lcov.files.get(path);
43
+ if (gaps.has(path) || lines === undefined) {
44
+ if (!gaps.has(path))
45
+ gaps.set(path, 'Changed file has no LCOV source record');
46
+ files.push({ path, addedLines, covered: null, total: null });
47
+ continue;
48
+ }
49
+ let fileCovered = 0;
50
+ let fileTotal = 0;
51
+ const missed = [];
52
+ for (const [line, hit] of lines) {
53
+ if (!containsLine(ranges, line))
54
+ continue;
55
+ fileTotal++;
56
+ if (hit)
57
+ fileCovered++;
58
+ else
59
+ missed.push(line);
60
+ }
61
+ covered += fileCovered;
62
+ total += fileTotal;
63
+ files.push({ path, addedLines, covered: fileCovered, total: fileTotal });
64
+ if (missed.length > 0)
65
+ uncovered.push({ path, lines: missed.sort((left, right) => left - right) });
66
+ }
67
+ return {
68
+ status: gaps.size > 0 ? 'partial' : total === 0 ? 'not-applicable' : 'complete',
69
+ covered, total, percent: total === 0 ? null : 100 * covered / total,
70
+ files: files.sort((a, b) => comparePaths(a.path, b.path)),
71
+ gaps: [...gaps].sort(([a], [b]) => comparePaths(a, b)).map(([path, reason]) => ({ path, reason })),
72
+ uncovered: uncovered.sort((left, right) => comparePaths(left.path, right.path)),
73
+ };
74
+ }
75
+ function containsLine(ranges, line) {
76
+ let lower = 0;
77
+ let upper = ranges.length;
78
+ while (lower < upper) {
79
+ const middle = Math.floor((lower + upper) / 2);
80
+ const { first, last } = ranges[middle];
81
+ if (line < first)
82
+ upper = middle;
83
+ else if (line > last)
84
+ lower = middle + 1;
85
+ else
86
+ return true;
87
+ }
88
+ return false;
89
+ }
90
+ //# sourceMappingURL=diff-coverage.js.map
@@ -0,0 +1,4 @@
1
+ import type { DataContract, Plugin } from '../../core/engine/plugin.js';
2
+ import type { CloneSource } from '../../core/model/clone-source.js';
3
+ export declare const duplication: Plugin;
4
+ export declare const duplicationInput: DataContract<readonly CloneSource[]>;
@@ -0,0 +1,94 @@
1
+ import { pluginApi } from '../../core/engine/plugin.js';
2
+ import { comparePaths } from '../../core/model/snapshot.js';
3
+ import { findingResult } from '../../core/model/finding.js';
4
+ import { definitions } from '../../core/model/measurement.js';
5
+ import { isCloneSource } from '../../core/model/clone-source.js';
6
+ import { duplicationSettings } from '../../core/profile/maintainability.js';
7
+ const cloneSources = {
8
+ id: 'repometry.clone-sources-babel/v1',
9
+ accepts: (value) => Array.isArray(value) && value.every(isCloneSource),
10
+ };
11
+ export const duplication = {
12
+ id: 'duplication', version: '1.0.0', api: pluginApi,
13
+ kinds: ['analysis'],
14
+ produces: [{ contract: findingResult.id, persistence: 'report', metrics: [
15
+ { id: definitions.duplicatedLines, label: 'Duplicated lines', unit: 'count', scope: 'file', aggregate: 'sum', better: 'lower',
16
+ group: 'Maintainability' },
17
+ ] }],
18
+ operations: [{
19
+ id: 'detect', role: 'inspection', inputs: { sources: cloneSources }, output: findingResult,
20
+ execute(inputs) { return detectClones(inputs.read('sources', cloneSources)); },
21
+ }],
22
+ };
23
+ export const duplicationInput = cloneSources;
24
+ function detectClones(sources) {
25
+ const byFingerprint = new Map();
26
+ for (const { path, candidates } of sources) {
27
+ for (const candidate of candidates) {
28
+ const occurrences = byFingerprint.get(candidate.similar);
29
+ const occurrence = { ...candidate, path };
30
+ if (occurrences)
31
+ occurrences.push(occurrence);
32
+ else
33
+ byFingerprint.set(candidate.similar, [occurrence]);
34
+ }
35
+ }
36
+ const groups = [...byFingerprint.values()].filter(group => group.length > 1)
37
+ .sort((left, right) => right[0].nodes - left[0].nodes || comparePaths(left[0].similar, right[0].similar));
38
+ const matched = new Map(sources.map(source => [source.path, []]));
39
+ const findings = [];
40
+ for (const group of groups) {
41
+ const fresh = group.filter(occurrence => {
42
+ const selected = matched.get(occurrence.path);
43
+ const index = insertionIndex(selected, occurrence.start);
44
+ return (selected[index - 1]?.end ?? -1) <= occurrence.start && (selected[index]?.start ?? Infinity) >= occurrence.end;
45
+ });
46
+ if (fresh.length < 2)
47
+ continue;
48
+ fresh.sort((left, right) => comparePaths(left.path, right.path) || left.start - right.start);
49
+ const first = fresh[0];
50
+ const identical = fresh.every(item => item.exact === first.exact);
51
+ for (const occurrence of fresh) {
52
+ const selected = matched.get(occurrence.path);
53
+ selected.splice(insertionIndex(selected, occurrence.start), 0, occurrence);
54
+ }
55
+ const rule = identical ? 'identical-code' : 'similar-code';
56
+ const effortMinutes = fresh.slice(1).reduce((total, occurrence) => total + occurrence.codeLines, 0) * duplicationSettings.minutesPerRepeatedLine;
57
+ findings.push({ tool: 'repometry', rule, category: 'duplication', level: 'medium',
58
+ message: `${identical ? 'Identical' : 'Similar'} code in ${fresh.length} locations`, ...location(first),
59
+ related: fresh.slice(1).map(location), effortMinutes });
60
+ }
61
+ return {
62
+ findings,
63
+ measurements: sources.map(({ path, codeLines }) => ({ definition: definitions.duplicatedLines, target: 'file',
64
+ path, value: matchedLineCount(codeLines, matched.get(path)) })),
65
+ };
66
+ }
67
+ function location({ path, line, endLine }) {
68
+ return { path, line, endLine };
69
+ }
70
+ function insertionIndex(selected, start) {
71
+ let left = 0;
72
+ let right = selected.length;
73
+ while (left < right) {
74
+ const middle = Math.floor((left + right) / 2);
75
+ if (selected[middle].start < start)
76
+ left = middle + 1;
77
+ else
78
+ right = middle;
79
+ }
80
+ return left;
81
+ }
82
+ function matchedLineCount(codeLines, matches) {
83
+ let index = 0;
84
+ let count = 0;
85
+ for (const line of codeLines) {
86
+ while (index < matches.length && matches[index].endLine < line)
87
+ index++;
88
+ const match = matches[index];
89
+ if (match && match.line <= line)
90
+ count++;
91
+ }
92
+ return count;
93
+ }
94
+ //# sourceMappingURL=duplication.js.map
@@ -0,0 +1,10 @@
1
+ import type { Plugin } from '../../core/engine/plugin.js';
2
+ export declare const parserDefaults: {
3
+ readonly sourceType: 'unambiguous';
4
+ readonly errorRecovery: false;
5
+ readonly attachComment: false;
6
+ };
7
+ export declare const babelTypes: {
8
+ '@babel/types': string;
9
+ };
10
+ export declare const babelProvider: Plugin;
@@ -0,0 +1,47 @@
1
+ import { createRequire } from 'node:module';
2
+ import { extname } from 'node:path';
3
+ import { parse } from '@babel/parser';
4
+ import { pluginApi } from '../../core/engine/plugin.js';
5
+ import { codeStructure } from '../../core/model/code-structure.js';
6
+ import { physicalLines, sourceExtensions, sourceFile, utf8 } from '../../core/model/snapshot.js';
7
+ import { cloneCandidates } from './clone-candidates.js';
8
+ import { classifyLines } from './code-lines.js';
9
+ import { functionFacts } from './function-facts.js';
10
+ import { structuralObservations } from './structural-observations.js';
11
+ const require = createRequire(import.meta.url);
12
+ export const parserDefaults = { sourceType: 'unambiguous', errorRecovery: false, attachComment: false };
13
+ export const babelTypes = { '@babel/types': require('@babel/types/package.json').version };
14
+ export const babelProvider = {
15
+ id: 'babel-syntax',
16
+ version: '1.0.0',
17
+ api: pluginApi,
18
+ kinds: ['language'],
19
+ claims: { extensions: sourceExtensions, languages: ['javascript', 'typescript'] },
20
+ produces: [{ contract: codeStructure.id, persistence: 'transient' }],
21
+ tools: { '@babel/parser': require('@babel/parser/package.json').version },
22
+ operations: [{
23
+ id: 'parse',
24
+ role: 'provider',
25
+ inputs: { source: sourceFile },
26
+ output: codeStructure,
27
+ execute(inputs) {
28
+ const file = inputs.read('source', sourceFile);
29
+ const source = utf8(file.bytes);
30
+ const ext = extname(file.path);
31
+ const plugins = [];
32
+ if (['.ts', '.mts', '.cts', '.tsx'].includes(ext)) {
33
+ plugins.push(['typescript', { dts: /\.d\.[cm]?ts$/.test(file.path), disallowAmbiguousJSXLike: ext === '.mts' || ext === '.cts' }]);
34
+ }
35
+ if (ext === '.jsx' || ext === '.tsx')
36
+ plugins.push('jsx');
37
+ const sourceType = ext === '.mjs' || ext === '.mts' ? 'module'
38
+ : ext === '.cjs' || ext === '.cts' ? 'commonjs' : parserDefaults.sourceType;
39
+ const ast = parse(source, { ...parserDefaults, sourceType, plugins });
40
+ const lines = physicalLines(source);
41
+ const { code, comments } = classifyLines(source, ast, lines);
42
+ return { path: file.path, lines, commentLines: comments, ...functionFacts(ast),
43
+ ...structuralObservations(ast), clones: cloneCandidates(file.path, ast, code) };
44
+ },
45
+ }],
46
+ };
47
+ //# sourceMappingURL=babel-provider.js.map
@@ -0,0 +1,3 @@
1
+ import type { Node } from '@babel/types';
2
+ import type { CloneSource } from '../../core/model/clone-source.js';
3
+ export declare function cloneCandidates(path: string, ast: Node, codeLines: readonly number[]): CloneSource;
@@ -0,0 +1,65 @@
1
+ import { NODE_FIELDS, VISITOR_KEYS, isFunction, isStatement } from '@babel/types';
2
+ import { createHash } from 'node:crypto';
3
+ import { duplicationSettings } from '../../core/profile/maintainability.js';
4
+ export function cloneCandidates(path, ast, codeLines) {
5
+ const candidates = [];
6
+ if (codeLines.length >= duplicationSettings.minCodeLines)
7
+ walk(ast);
8
+ return { path, codeLines, candidates };
9
+ function walk(node) {
10
+ let nodes = 1;
11
+ const exact = [node.type];
12
+ const similar = [node.type];
13
+ const properties = node;
14
+ const keys = VISITOR_KEYS[node.type] ?? [];
15
+ for (const key of keys) {
16
+ const value = properties[key];
17
+ const descendants = (Array.isArray(value) ? value : [value]).map((child) => child ? walk(child) : null);
18
+ for (const descendant of descendants)
19
+ nodes += descendant?.nodes ?? 0;
20
+ exact.push(descendants.map(descendant => descendant?.exact ?? null));
21
+ similar.push(descendants.map(descendant => descendant?.similar ?? null));
22
+ }
23
+ for (const key of Object.keys(NODE_FIELDS[node.type] ?? {})) {
24
+ if (keys.includes(key))
25
+ continue;
26
+ const value = properties[key] ?? null;
27
+ exact.push(value);
28
+ similar.push(normalized(node.type, key) ? null : value);
29
+ }
30
+ const fingerprint = { exact: hash(exact), similar: hash(similar), nodes };
31
+ const { start, end, loc } = node;
32
+ const eligible = (isFunction(node) || isStatement(node) || node.type === 'SwitchCase') && node.type !== 'EmptyStatement';
33
+ if (eligible && nodes >= duplicationSettings.minNodes && loc && start != null && end != null) {
34
+ const endLine = loc.end.line - Number(loc.end.column === 0);
35
+ const codeCount = firstAtLeast(codeLines, endLine + 1) - firstAtLeast(codeLines, loc.start.line);
36
+ if (codeCount >= duplicationSettings.minCodeLines) {
37
+ candidates.push({ ...fingerprint, start, end, line: loc.start.line, endLine, codeLines: codeCount });
38
+ }
39
+ }
40
+ return fingerprint;
41
+ }
42
+ }
43
+ function normalized(type, property) {
44
+ if ((type === 'Identifier' || type === 'JSXIdentifier') && property === 'name')
45
+ return true;
46
+ if (type === 'RegExpLiteral' && property === 'pattern')
47
+ return true;
48
+ return property === 'value' && (type.endsWith('Literal') || type === 'TemplateElement');
49
+ }
50
+ function hash(parts) {
51
+ return createHash('sha256').update(JSON.stringify(parts)).digest('base64url');
52
+ }
53
+ function firstAtLeast(numbers, number) {
54
+ let left = 0;
55
+ let right = numbers.length;
56
+ while (left < right) {
57
+ const middle = Math.floor((left + right) / 2);
58
+ if (numbers[middle] < number)
59
+ left = middle + 1;
60
+ else
61
+ right = middle;
62
+ }
63
+ return left;
64
+ }
65
+ //# sourceMappingURL=clone-candidates.js.map
@@ -0,0 +1,6 @@
1
+ import type { File } from '@babel/types';
2
+ export interface CodeLineCounts {
3
+ readonly code: readonly number[];
4
+ readonly comments: number;
5
+ }
6
+ export declare function classifyLines(source: string, ast: File, physical: number): CodeLineCounts;
@@ -0,0 +1,36 @@
1
+ export function classifyLines(source, ast, physical) {
2
+ const lines = source.split(/\r\n|[\n\r\u2028\u2029]/);
3
+ const masks = new Map();
4
+ for (const { loc } of [...(ast.program.interpreter ? [ast.program.interpreter] : []), ...ast.comments ?? []]) {
5
+ if (!loc)
6
+ continue;
7
+ for (let line = loc.start.line; line <= loc.end.line && line <= physical; line++) {
8
+ const start = line === loc.start.line ? loc.start.column : 0;
9
+ const end = line === loc.end.line ? loc.end.column : lines[line - 1].length;
10
+ const mask = { start, end };
11
+ const intervals = masks.get(line);
12
+ if (intervals)
13
+ intervals.push(mask);
14
+ else
15
+ masks.set(line, [mask]);
16
+ }
17
+ }
18
+ const code = [];
19
+ let comments = 0;
20
+ for (let line = 1; line <= physical; line++) {
21
+ const text = lines[line - 1];
22
+ const intervals = masks.get(line) ?? [];
23
+ let offset = 0;
24
+ let hasCode = false;
25
+ for (const { start, end } of intervals) {
26
+ hasCode ||= text.slice(offset, start).trim() !== '';
27
+ offset = end;
28
+ }
29
+ if (hasCode || text.slice(offset).trim() !== '')
30
+ code.push(line);
31
+ else if (intervals.length > 0)
32
+ comments++;
33
+ }
34
+ return { code, comments };
35
+ }
36
+ //# sourceMappingURL=code-lines.js.map
@@ -0,0 +1,8 @@
1
+ import type { Function as BabelFunction, Node } from '@babel/types';
2
+ import type { FunctionComplexity } from '../../core/model/code-structure.js';
3
+ export declare function functionFacts(ast: Node): {
4
+ functions: number;
5
+ cyclomaticFunctions: FunctionComplexity[];
6
+ };
7
+ export declare function children(node: Node): Iterable<Node>;
8
+ export declare function functionName(node: BabelFunction): string;