repometry 0.4.2 → 0.6.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 (269) hide show
  1. package/README.md +36 -14
  2. package/package.json +1 -1
  3. package/target/main/resources/report/json/comparison-v1.schema.json +6 -6
  4. package/target/main/resources/report/json/file-metrics-v1.schema.json +7 -6
  5. package/target/main/resources/report/json/pull-review-v1.schema.json +5 -5
  6. package/target/main/resources/report/json/report-v2.schema.json +210 -11
  7. package/target/main/resources/report/json/repository-summary-v1.schema.json +161 -14
  8. package/target/main/resources/report/json/viewer-inspection-v1.schema.json +518 -6
  9. package/target/main/resources/viewer/styles.css +7 -2
  10. package/target/main/ts/api/git/changes.d.ts +1 -1
  11. package/target/main/ts/api/git/changes.js +3 -3
  12. package/target/main/ts/api/git/commit-metadata.js +6 -4
  13. package/target/main/ts/api/git/git.d.ts +2 -1
  14. package/target/main/ts/api/git/git.js +16 -4
  15. package/target/main/ts/api/git/inspection-source.d.ts +1 -1
  16. package/target/main/ts/api/git/inspection-source.js +4 -10
  17. package/target/main/ts/api/git/local.d.ts +1 -1
  18. package/target/main/ts/api/git/local.js +41 -7
  19. package/target/main/ts/api/process/docker-tool-runner.d.ts +13 -0
  20. package/target/main/ts/api/process/docker-tool-runner.js +108 -0
  21. package/target/main/ts/api/process/failure.d.ts +1 -0
  22. package/target/main/ts/api/process/failure.js +12 -0
  23. package/target/main/ts/api/process/plugin.d.ts +10 -0
  24. package/target/main/ts/api/process/plugin.js +96 -0
  25. package/target/main/ts/api/worker/remote-executor.d.ts +1 -1
  26. package/target/main/ts/api/worker/remote-executor.js +2 -2
  27. package/target/main/ts/api/worker/worker-protocol.d.ts +2 -2
  28. package/target/main/ts/api/worker/worker-protocol.js +8 -8
  29. package/target/main/ts/api/worker/worker.d.ts +1 -1
  30. package/target/main/ts/api/worker/worker.js +4 -4
  31. package/target/main/ts/cli/main.js +4 -3
  32. package/target/main/ts/cli/reporting.d.ts +1 -1
  33. package/target/main/ts/cli/reporting.js +1 -1
  34. package/target/main/ts/compose/analysis-files.d.ts +13 -0
  35. package/target/main/ts/compose/analysis-files.js +95 -0
  36. package/target/main/ts/compose/analysis-imports.d.ts +7 -0
  37. package/target/main/ts/compose/analysis-imports.js +34 -0
  38. package/target/main/ts/compose/analysis-report.d.ts +5 -0
  39. package/target/main/ts/compose/analysis-report.js +78 -0
  40. package/target/main/ts/compose/analysis-repository.d.ts +6 -0
  41. package/target/main/ts/compose/analysis-repository.js +61 -0
  42. package/target/main/ts/compose/analysis-results.d.ts +38 -0
  43. package/target/main/ts/compose/analysis-results.js +78 -0
  44. package/target/main/ts/compose/analysis-sources.d.ts +73 -0
  45. package/target/main/ts/compose/analysis-sources.js +47 -0
  46. package/target/main/ts/compose/analyze-snapshot.d.ts +3 -2
  47. package/target/main/ts/compose/analyze-snapshot.js +19 -197
  48. package/target/main/ts/compose/diff-coverage.d.ts +2 -0
  49. package/target/main/ts/compose/diff-coverage.js +6 -4
  50. package/target/main/ts/compose/inspect.d.ts +5 -0
  51. package/target/main/ts/compose/inspect.js +14 -7
  52. package/target/main/ts/compose/languages.d.ts +29 -0
  53. package/target/main/ts/compose/languages.js +87 -0
  54. package/target/main/ts/compose/sources.js +14 -12
  55. package/target/main/ts/core/engine/execute.d.ts +3 -1
  56. package/target/main/ts/core/engine/execute.js +14 -2
  57. package/target/main/ts/core/engine/manifest.d.ts +2 -2
  58. package/target/main/ts/core/engine/manifest.js +25 -5
  59. package/target/main/ts/core/engine/operation-cache.d.ts +14 -0
  60. package/target/main/ts/core/engine/operation-cache.js +66 -0
  61. package/target/main/ts/core/engine/plan.d.ts +3 -4
  62. package/target/main/ts/core/engine/plan.js +28 -11
  63. package/target/main/ts/core/engine/plugin.d.ts +10 -2
  64. package/target/main/ts/core/engine/plugin.js +1 -3
  65. package/target/main/ts/core/engine/report-products.js +2 -13
  66. package/target/main/ts/core/model/clone-source.d.ts +1 -0
  67. package/target/main/ts/core/model/clone-source.js +2 -1
  68. package/target/main/ts/core/model/code-structure.d.ts +5 -0
  69. package/target/main/ts/core/model/code-structure.js +10 -1
  70. package/target/main/ts/core/model/finding-ignore.js +1 -1
  71. package/target/main/ts/core/model/finding.js +1 -1
  72. package/target/main/ts/core/model/language.d.ts +10 -0
  73. package/target/main/ts/core/model/language.js +6 -0
  74. package/target/main/ts/core/model/line-coverage.d.ts +5 -1
  75. package/target/main/ts/core/model/line-coverage.js +14 -11
  76. package/target/main/ts/core/model/measurement.d.ts +7 -6
  77. package/target/main/ts/core/model/measurement.js +18 -7
  78. package/target/main/ts/core/model/plugin-data.d.ts +5 -0
  79. package/target/main/ts/core/model/plugin-data.js +15 -1
  80. package/target/main/ts/core/model/quality-summary.js +6 -5
  81. package/target/main/ts/core/model/report.d.ts +1 -2
  82. package/target/main/ts/core/model/report.js +0 -1
  83. package/target/main/ts/core/model/scanner-import.js +1 -1
  84. package/target/main/ts/core/model/snapshot.d.ts +1 -2
  85. package/target/main/ts/core/model/snapshot.js +5 -7
  86. package/target/main/ts/core/model/source.d.ts +3 -0
  87. package/target/main/ts/core/model/source.js +15 -0
  88. package/target/main/ts/core/ports/tool-runner.d.ts +18 -0
  89. package/target/main/ts/core/ports/tool-runner.js +2 -0
  90. package/target/main/ts/core/usecases/compare.js +61 -17
  91. package/target/main/ts/core/usecases/inspect.js +2 -2
  92. package/target/main/ts/plugin.d.ts +10 -3
  93. package/target/main/ts/plugin.js +4 -2
  94. package/target/main/ts/plugins/coverage/coverage.d.ts +5 -2
  95. package/target/main/ts/plugins/coverage/coverage.js +35 -10
  96. package/target/main/ts/plugins/duplication/duplication.js +10 -4
  97. package/target/main/ts/plugins/language-js/babel-provider.js +8 -2
  98. package/target/main/ts/plugins/language-js/extensions.d.ts +3 -0
  99. package/target/main/ts/plugins/language-js/extensions.js +4 -0
  100. package/target/main/ts/plugins/language-js/function-facts.d.ts +1 -0
  101. package/target/main/ts/plugins/language-js/function-facts.js +30 -4
  102. package/target/main/ts/plugins/language-js/js-security.js +3 -2
  103. package/target/main/ts/report/html/app/viewer-chart-bars.d.ts +11 -0
  104. package/target/main/ts/report/html/app/viewer-chart-bars.js +54 -0
  105. package/target/main/ts/report/html/app/viewer-chart-label.d.ts +15 -0
  106. package/target/main/ts/report/html/app/viewer-chart-label.js +43 -0
  107. package/target/main/ts/report/html/app/viewer-chart-line.d.ts +24 -0
  108. package/target/main/ts/report/html/app/viewer-chart-line.js +89 -0
  109. package/target/main/ts/report/html/app/viewer-chart-points.d.ts +49 -0
  110. package/target/main/ts/report/html/app/viewer-chart-points.js +74 -0
  111. package/target/main/ts/report/html/app/viewer-chart-scale.d.ts +21 -0
  112. package/target/main/ts/report/html/app/viewer-chart-scale.js +93 -0
  113. package/target/main/ts/report/html/app/viewer-chart-svg.d.ts +28 -0
  114. package/target/main/ts/report/html/app/viewer-chart-svg.js +41 -0
  115. package/target/main/ts/report/html/app/viewer-chart-time.d.ts +26 -0
  116. package/target/main/ts/report/html/app/viewer-chart-time.js +150 -0
  117. package/target/main/ts/report/html/app/viewer-chart-tip.d.ts +4 -0
  118. package/target/main/ts/report/html/app/viewer-chart-tip.js +210 -0
  119. package/target/main/ts/report/html/app/viewer-chart-x.d.ts +12 -0
  120. package/target/main/ts/report/html/app/viewer-chart-x.js +50 -0
  121. package/target/main/ts/report/html/app/viewer-chart.d.ts +4 -98
  122. package/target/main/ts/report/html/app/viewer-chart.js +16 -677
  123. package/target/main/ts/report/html/app/viewer-code-map.d.ts +27 -0
  124. package/target/main/ts/report/html/app/viewer-code-map.js +175 -0
  125. package/target/main/ts/report/html/app/viewer-columns.d.ts +38 -0
  126. package/target/main/ts/report/html/app/viewer-columns.js +92 -0
  127. package/target/main/ts/report/html/app/viewer-commit-picker.d.ts +12 -0
  128. package/target/main/ts/report/html/app/viewer-commit-picker.js +229 -0
  129. package/target/main/ts/report/html/app/viewer-commits.d.ts +5 -9
  130. package/target/main/ts/report/html/app/viewer-commits.js +17 -216
  131. package/target/main/ts/report/html/app/viewer-controls.d.ts +43 -0
  132. package/target/main/ts/report/html/app/viewer-controls.js +141 -0
  133. package/target/main/ts/report/html/app/viewer-copy.d.ts +17 -0
  134. package/target/main/ts/report/html/app/viewer-copy.js +64 -0
  135. package/target/main/ts/report/html/app/viewer-data.d.ts +1 -1
  136. package/target/main/ts/report/html/app/viewer-data.js +2 -29
  137. package/target/main/ts/report/html/app/viewer-diagnostics.d.ts +4 -0
  138. package/target/main/ts/report/html/app/viewer-diagnostics.js +60 -0
  139. package/target/main/ts/report/html/app/viewer-dom.d.ts +27 -0
  140. package/target/main/ts/report/html/app/viewer-dom.js +99 -0
  141. package/target/main/ts/report/html/app/viewer-file-aside.d.ts +19 -0
  142. package/target/main/ts/report/html/app/viewer-file-aside.js +124 -0
  143. package/target/main/ts/report/html/app/viewer-file-figures.d.ts +15 -0
  144. package/target/main/ts/report/html/app/viewer-file-figures.js +60 -0
  145. package/target/main/ts/report/html/app/viewer-file-source.d.ts +7 -0
  146. package/target/main/ts/report/html/app/viewer-file-source.js +119 -0
  147. package/target/main/ts/report/html/app/viewer-files.d.ts +2 -118
  148. package/target/main/ts/report/html/app/viewer-files.js +24 -2184
  149. package/target/main/ts/report/html/app/viewer-filter.d.ts +3 -51
  150. package/target/main/ts/report/html/app/viewer-filter.js +111 -450
  151. package/target/main/ts/report/html/app/viewer-hotspots.d.ts +4 -0
  152. package/target/main/ts/report/html/app/viewer-hotspots.js +131 -0
  153. package/target/main/ts/report/html/app/viewer-inspection.d.ts +69 -0
  154. package/target/main/ts/report/html/app/viewer-inspection.js +36 -0
  155. package/target/main/ts/report/html/app/viewer-issue-group.d.ts +27 -0
  156. package/target/main/ts/report/html/app/viewer-issue-group.js +174 -0
  157. package/target/main/ts/report/html/app/viewer-issues.d.ts +4 -0
  158. package/target/main/ts/report/html/app/viewer-issues.js +173 -0
  159. package/target/main/ts/report/html/app/viewer-language-bar.d.ts +9 -0
  160. package/target/main/ts/report/html/app/viewer-language-bar.js +72 -0
  161. package/target/main/ts/report/html/app/viewer-languages.d.ts +27 -0
  162. package/target/main/ts/report/html/app/viewer-languages.js +93 -0
  163. package/target/main/ts/report/html/app/viewer-layout.d.ts +14 -0
  164. package/target/main/ts/report/html/app/viewer-layout.js +134 -0
  165. package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +47 -0
  166. package/target/main/ts/report/html/app/viewer-line-coverage.js +121 -0
  167. package/target/main/ts/report/html/app/viewer-locations.d.ts +16 -0
  168. package/target/main/ts/report/html/app/viewer-locations.js +31 -0
  169. package/target/main/ts/report/html/app/viewer-map-scale.d.ts +26 -0
  170. package/target/main/ts/report/html/app/viewer-map-scale.js +147 -0
  171. package/target/main/ts/report/html/app/viewer-map-shape.d.ts +42 -0
  172. package/target/main/ts/report/html/app/viewer-map-shape.js +102 -0
  173. package/target/main/ts/report/html/app/viewer-metric-format.d.ts +23 -0
  174. package/target/main/ts/report/html/app/viewer-metric-format.js +93 -0
  175. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -20
  176. package/target/main/ts/report/html/app/viewer-metric-registry.js +7 -84
  177. package/target/main/ts/report/html/app/viewer-metrics-view.d.ts +4 -0
  178. package/target/main/ts/report/html/app/viewer-metrics-view.js +162 -0
  179. package/target/main/ts/report/html/app/viewer-metrics.d.ts +6 -1
  180. package/target/main/ts/report/html/app/viewer-metrics.js +53 -35
  181. package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +12 -0
  182. package/target/main/ts/report/html/app/viewer-overview-cards.js +118 -0
  183. package/target/main/ts/report/html/app/viewer-overview-hotspots.d.ts +9 -0
  184. package/target/main/ts/report/html/app/viewer-overview-hotspots.js +173 -0
  185. package/target/main/ts/report/html/app/viewer-overview-lead.d.ts +12 -0
  186. package/target/main/ts/report/html/app/viewer-overview-lead.js +116 -0
  187. package/target/main/ts/report/html/app/viewer-profile-badges.d.ts +11 -0
  188. package/target/main/ts/report/html/app/viewer-profile-badges.js +119 -0
  189. package/target/main/ts/report/html/app/viewer-profile-table.d.ts +29 -0
  190. package/target/main/ts/report/html/app/viewer-profile-table.js +124 -0
  191. package/target/main/ts/report/html/app/viewer-profile.d.ts +2 -6
  192. package/target/main/ts/report/html/app/viewer-profile.js +6 -248
  193. package/target/main/ts/report/html/app/viewer-pull-sections.d.ts +4 -0
  194. package/target/main/ts/report/html/app/viewer-pull-sections.js +118 -0
  195. package/target/main/ts/report/html/app/viewer-pull-trend.d.ts +5 -0
  196. package/target/main/ts/report/html/app/viewer-pull-trend.js +63 -0
  197. package/target/main/ts/report/html/app/viewer-pulls.d.ts +0 -1
  198. package/target/main/ts/report/html/app/viewer-pulls.js +28 -178
  199. package/target/main/ts/report/html/app/viewer-query-field.d.ts +19 -0
  200. package/target/main/ts/report/html/app/viewer-query-field.js +203 -0
  201. package/target/main/ts/report/html/app/viewer-route.d.ts +34 -0
  202. package/target/main/ts/report/html/app/viewer-route.js +55 -0
  203. package/target/main/ts/report/html/app/viewer-shell.d.ts +20 -0
  204. package/target/main/ts/report/html/app/viewer-shell.js +116 -0
  205. package/target/main/ts/report/html/app/viewer-source-view.d.ts +49 -0
  206. package/target/main/ts/report/html/app/viewer-source-view.js +150 -0
  207. package/target/main/ts/report/html/app/viewer-source.d.ts +0 -84
  208. package/target/main/ts/report/html/app/viewer-source.js +7 -365
  209. package/target/main/ts/report/html/app/viewer-suggest.d.ts +13 -0
  210. package/target/main/ts/report/html/app/viewer-suggest.js +91 -0
  211. package/target/main/ts/report/html/app/viewer-sunburst.d.ts +5 -0
  212. package/target/main/ts/report/html/app/viewer-sunburst.js +40 -0
  213. package/target/main/ts/report/html/app/viewer-table-cells.d.ts +25 -0
  214. package/target/main/ts/report/html/app/viewer-table-cells.js +129 -0
  215. package/target/main/ts/report/html/app/viewer-table-rows.d.ts +54 -0
  216. package/target/main/ts/report/html/app/viewer-table-rows.js +95 -0
  217. package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +16 -0
  218. package/target/main/ts/report/html/app/viewer-tokenizer.js +192 -0
  219. package/target/main/ts/report/html/app/viewer-totals.d.ts +14 -0
  220. package/target/main/ts/report/html/app/viewer-totals.js +89 -0
  221. package/target/main/ts/report/html/app/viewer-treemap.d.ts +24 -0
  222. package/target/main/ts/report/html/app/viewer-treemap.js +112 -0
  223. package/target/main/ts/report/html/app/viewer-trend-data.d.ts +54 -0
  224. package/target/main/ts/report/html/app/viewer-trend-data.js +109 -0
  225. package/target/main/ts/report/html/app/viewer-trend-nav.d.ts +5 -0
  226. package/target/main/ts/report/html/app/viewer-trend-nav.js +85 -0
  227. package/target/main/ts/report/html/app/viewer-trend-points.d.ts +30 -0
  228. package/target/main/ts/report/html/app/viewer-trend-points.js +128 -0
  229. package/target/main/ts/report/html/app/viewer-trend-series.d.ts +26 -0
  230. package/target/main/ts/report/html/app/viewer-trend-series.js +98 -0
  231. package/target/main/ts/report/html/app/viewer-trends.d.ts +2 -70
  232. package/target/main/ts/report/html/app/viewer-trends.js +41 -392
  233. package/target/main/ts/report/html/app/viewer.js +152 -663
  234. package/target/main/ts/report/html/site/export-site.d.ts +3 -4
  235. package/target/main/ts/report/html/site/export-site.js +24 -41
  236. package/target/main/ts/report/html/site/exported-server.js +2 -1
  237. package/target/main/ts/report/html/site/local-server.d.ts +1 -1
  238. package/target/main/ts/report/html/site/local-server.js +13 -19
  239. package/target/main/ts/report/html/site/projects.js +8 -17
  240. package/target/main/ts/report/json/projections/commit-summary.d.ts +2 -2
  241. package/target/main/ts/report/json/projections/commit-summary.js +18 -19
  242. package/target/main/ts/report/json/projections/file-metrics.js +31 -24
  243. package/target/main/ts/report/json/projections/inspection-context.js +10 -1
  244. package/target/main/ts/report/json/projections/inspection-details.d.ts +1 -1
  245. package/target/main/ts/report/json/projections/inspection-details.js +2 -2
  246. package/target/main/ts/report/json/projections/metric-values.d.ts +1 -0
  247. package/target/main/ts/report/json/projections/metric-values.js +15 -5
  248. package/target/main/ts/report/json/store/local-store.js +2 -12
  249. package/target/main/ts/report/json/store/operation-cache.d.ts +8 -0
  250. package/target/main/ts/report/json/store/operation-cache.js +32 -0
  251. package/target/main/ts/report/json/store/pull-review-store.js +1 -2
  252. package/target/main/ts/report/json/store/replace-file.d.ts +1 -0
  253. package/target/main/ts/report/json/store/replace-file.js +14 -0
  254. package/target/main/ts/report/json/validation/report.d.ts +1 -1
  255. package/target/main/ts/report/json/validation/report.js +10 -8
  256. package/target/main/ts/report/json/validation/summary-validation.js +1 -3
  257. package/target/main/ts/report/json/wire/file-metrics-model.d.ts +2 -0
  258. package/target/main/ts/report/json/wire/inspection-details-model.d.ts +0 -5
  259. package/target/main/ts/report/json/wire/public-history-model.d.ts +0 -6
  260. package/target/main/ts/report/json/wire/public-history-model.js +0 -1
  261. package/target/main/ts/report.d.ts +3 -3
  262. package/target/main/ts/report.js +2 -2
  263. package/target/main/resources/report/json/inspection-context-v1.schema.json +0 -172
  264. package/target/main/resources/report/json/public-history-v1.schema.json +0 -50
  265. package/target/main/resources/report/json/quality-history-v1.schema.json +0 -51
  266. package/target/main/resources/report/json/report-v1.schema.json +0 -65
  267. package/target/main/resources/report/json/viewer-details-v1.schema.json +0 -346
  268. package/target/main/ts/report/json/projections/public-history.d.ts +0 -4
  269. package/target/main/ts/report/json/projections/public-history.js +0 -17
@@ -1,3 +1,18 @@
1
+ export function isMergedLineRanges(value) {
2
+ if (!Array.isArray(value))
3
+ return false;
4
+ let previous = -1;
5
+ for (const range of value) {
6
+ if (!Array.isArray(range) || range.length !== 2)
7
+ return false;
8
+ const [first, last] = range;
9
+ if (typeof first !== 'number' || typeof last !== 'number' || !Number.isSafeInteger(first)
10
+ || !Number.isSafeInteger(last) || first <= previous + 1 || last < first)
11
+ return false;
12
+ previous = last;
13
+ }
14
+ return true;
15
+ }
1
16
  export const maxClaimedFileBytes = 1024 * 1024;
2
17
  export function isClaimedText(bytes) {
3
18
  return bytes.byteLength <= maxClaimedFileBytes && !bytes.subarray(0, 8192).includes(0);
@@ -0,0 +1,18 @@
1
+ import type { SourceFile } from '../model/source.js';
2
+ export interface ToolInvocation {
3
+ readonly argv: readonly string[];
4
+ readonly files: readonly SourceFile[];
5
+ readonly stdin?: Uint8Array;
6
+ readonly timeoutMs: number;
7
+ readonly maxOutputBytes: number;
8
+ }
9
+ export interface ToolResult {
10
+ readonly exitCode: number;
11
+ readonly stdout: Uint8Array;
12
+ readonly stderr: Uint8Array;
13
+ }
14
+ export interface ToolRunner {
15
+ readonly network: 'none';
16
+ readonly implementation?: string;
17
+ run(invocation: ToolInvocation): Promise<ToolResult>;
18
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tool-runner.js.map
@@ -1,6 +1,6 @@
1
1
  import { isDeepStrictEqual } from 'node:util';
2
2
  import { isRecord } from '../engine/plugin.js';
3
- import { definitions } from '../model/measurement.js';
3
+ import { canonicalMetricId, definitions } from '../model/measurement.js';
4
4
  import { comparePaths } from '../model/snapshot.js';
5
5
  import { comparisonSchema } from '../model/comparison.js';
6
6
  export { comparisonSchema } from '../model/comparison.js';
@@ -44,8 +44,8 @@ function observe(report, metric) {
44
44
  return observeCoverage(report);
45
45
  const maximum = metric.definition === definitions.complexity;
46
46
  const target = maximum ? 'function' : 'file';
47
- const rows = report.measurements.filter(row => row.definition === metric.definition && row.target === target);
48
- const partial = report.scope.parsed < report.scope.files || hasDiagnostic(report, metric.operation, 'babel-syntax/parse');
47
+ const rows = report.measurements.filter(row => row.target === target && canonicalMetricId(row.definition) === metric.definition);
48
+ const partial = report.scope.parsed < report.scope.files || hasDiagnostic(report, metric.operation) || hasParserDiagnostic(report);
49
49
  const expected = maximum ? fileCount(report.measurements, definitions.functions, report.scope.files) : report.scope.files;
50
50
  const value = integerAggregate(rows, maximum);
51
51
  if (partial)
@@ -90,6 +90,17 @@ function integerAggregate(rows, maximum) {
90
90
  function hasDiagnostic(report, ...operations) {
91
91
  return report.diagnostics.some(item => operations.includes(item.operation));
92
92
  }
93
+ function hasParserDiagnostic(report) {
94
+ const references = parserReferences(report);
95
+ if (references.size === 0)
96
+ return hasDiagnostic(report, 'babel-syntax/parse');
97
+ const operations = new Set(references.values());
98
+ return report.diagnostics.some(({ path, operation }) => path === undefined
99
+ ? operations.has(operation) : references.get(path) === operation);
100
+ }
101
+ function parserReferences(report) {
102
+ return new Map((report.pluginData?.inventory ?? []).flatMap(({ path, provider }) => provider === undefined ? [] : [[path, provider]]));
103
+ }
93
104
  function sourceScope(report) {
94
105
  const { source, profile } = report.appliedConfig;
95
106
  if (!isRecord(source))
@@ -98,10 +109,11 @@ function sourceScope(report) {
98
109
  const defaults = orderedStrings(source.defaultExclusions ?? []);
99
110
  const directories = orderedStrings(source.excludedDirectories);
100
111
  const extensions = orderedStrings(source.extensions);
112
+ const globs = orderedStrings(source.globs ?? []);
101
113
  const excludedOutput = source.excludedOutput;
102
- if (!paths || !defaults || !directories || !extensions || (excludedOutput !== null && typeof excludedOutput !== 'string'))
114
+ if (!paths || !defaults || !directories || !extensions || !globs || (excludedOutput !== null && typeof excludedOutput !== 'string'))
103
115
  return null;
104
- return { kind: report.subject.kind, paths: orderedStrings([...paths, ...defaults]), directories, extensions, excludedOutput,
116
+ return { kind: report.subject.kind, paths: orderedStrings([...paths, ...defaults]), directories, extensions, globs, excludedOutput,
105
117
  generatedSourcePolicy: source.generatedSourcePolicy ?? null };
106
118
  }
107
119
  function orderedStrings(value) {
@@ -110,23 +122,55 @@ function orderedStrings(value) {
110
122
  return [...new Set(value)].sort(comparePaths);
111
123
  }
112
124
  function method(report, metric) {
113
- const definition = report.definitions[metric.definition];
114
- const { plugins, operations, parser, coverage } = report.appliedConfig;
115
- const importsCoverage = metric.definition === definitions.coverage;
116
- const pluginIds = importsCoverage ? ['lcov'] : ['babel-syntax', 'structure'];
117
- const operationKeys = importsCoverage ? [metric.operation] : ['babel-syntax/parse', metric.operation];
118
- const toolchain = recordedEntries(plugins, 'id', pluginIds);
119
- const bindings = recordedEntries(operations, 'key', operationKeys);
120
- const settings = importsCoverage ? coverage : parser;
121
- if (typeof definition !== 'string' || !toolchain || !bindings || !isRecord(settings))
125
+ const definition = report.definitions[metric.definition] ?? Object.entries(report.definitions)
126
+ .find(([id]) => canonicalMetricId(id) === metric.definition)?.[1];
127
+ if (typeof definition !== 'string')
122
128
  return null;
123
- if (importsCoverage && typeof settings.merge !== 'string')
129
+ if (metric.definition !== definitions.coverage) {
130
+ const details = structureMethod(report, metric.operation);
131
+ return details === null ? null : { definition, ...details };
132
+ }
133
+ const { plugins, operations, coverage: settings } = report.appliedConfig;
134
+ const toolchain = recordedEntries(plugins, 'id', ['lcov']);
135
+ const bindings = recordedEntries(operations, 'key', [metric.operation]);
136
+ if (!toolchain || !bindings || !isRecord(settings) || typeof settings.merge !== 'string')
124
137
  return null;
125
- if (!importsCoverage)
126
- return { definition, toolchain, bindings, settings };
127
138
  const { inputDigest, inputDigests, pathBase, ...importSettings } = settings;
128
139
  return { definition, toolchain, bindings, settings: importSettings };
129
140
  }
141
+ function structureMethod(report, operation) {
142
+ const { plugins, operations, parser } = report.appliedConfig;
143
+ if (!Array.isArray(operations))
144
+ return null;
145
+ const scopes = new Set(parserReferences(report).values());
146
+ const candidates = operations.filter(isRecord).filter(entry => entry.key === operation);
147
+ const bindings = [];
148
+ const providerKeys = new Set();
149
+ for (const candidate of candidates) {
150
+ const port = isRecord(candidate.inputs) ? candidate.inputs.syntax : undefined;
151
+ if (!isRecord(port))
152
+ return null;
153
+ const provider = typeof candidate.syntaxProvider === 'string' ? candidate.syntaxProvider : port.operation;
154
+ if (typeof provider !== 'string' || !provider.includes('/'))
155
+ return null;
156
+ if (scopes.size && !scopes.has(provider))
157
+ continue;
158
+ providerKeys.add(provider);
159
+ bindings.push(candidate);
160
+ }
161
+ if (providerKeys.size === 0 || [...scopes].some(provider => !providerKeys.has(provider)))
162
+ return null;
163
+ const providerBindings = recordedEntries(operations, 'key', [...providerKeys].sort(comparePaths));
164
+ const pluginIds = [...new Set([operation, ...providerKeys].map(key => key.slice(0, key.indexOf('/'))))].sort(comparePaths);
165
+ const toolchain = recordedEntries(plugins, 'id', pluginIds);
166
+ if (!providerBindings || !toolchain)
167
+ return null;
168
+ // The original reports carried the Babel configuration at report level.
169
+ const configured = toolchain.map(({ id, version, api, tools, settings }) => ({
170
+ id, version, api, tools, settings: id === 'babel-syntax' && isRecord(parser) ? parser : settings ?? null,
171
+ }));
172
+ return { toolchain: configured, bindings: [...providerBindings, ...bindings.sort((a, b) => comparePaths(JSON.stringify(a), JSON.stringify(b)))] };
173
+ }
130
174
  function recordedEntries(value, key, names) {
131
175
  if (!Array.isArray(value))
132
176
  return null;
@@ -2,7 +2,7 @@ import { isDeepStrictEqual } from 'node:util';
2
2
  import { isRecord } from '../engine/plugin.js';
3
3
  import { normalizeFindingIgnore, partitionFindings } from '../model/finding-ignore.js';
4
4
  import { reportSchema } from '../model/report.js';
5
- import { digest, isSourcePath } from '../model/snapshot.js';
5
+ import { digest } from '../model/snapshot.js';
6
6
  import { normalizeExclusions, sourceExclusionMatcher } from '../profile/exclusions.js';
7
7
  export async function executeInspection(options, ports) {
8
8
  const excludedPaths = normalizeExclusions(options.exclude ?? []);
@@ -28,7 +28,7 @@ export async function executeInspection(options, ports) {
28
28
  appliedConfig: { ...findings.appliedConfig, findingIgnore: ignore },
29
29
  ...(findings.findings === undefined ? {} : partitionFindings(findings.findings, ignore)) };
30
30
  const result = snapshot.subject.kind === 'commit' && ports.recordChurn
31
- ? await ports.recordChurn(filtered, root, snapshot.files.filter(file => isSourcePath(file.path)).map(file => file.path)) : filtered;
31
+ ? await ports.recordChurn(filtered, root, snapshot.files.map(file => file.path)) : filtered;
32
32
  await source.save(result);
33
33
  return result;
34
34
  }
@@ -1,14 +1,21 @@
1
1
  export { pluginApi } from './core/engine/plugin.js';
2
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';
3
+ export type { FileClaims, MetricDescriptor, MetricScope, PluginKind, ProductDeclaration } from './core/engine/plugin.js';
4
+ export type { OperationCache, OperationCacheOptions } from './core/engine/operation-cache.js';
5
+ export { codeStructure, codeStructures } from './core/model/code-structure.js';
5
6
  export type { CodeStructure, FunctionComplexity, StructuralCheck, StructuralObservation } from './core/model/code-structure.js';
7
+ export type { LanguageDisplay, ProvidedLanguage } from './core/model/language.js';
6
8
  export type { Candidate, CloneSource } from './core/model/clone-source.js';
7
- export { sourceFile } from './core/model/snapshot.js';
9
+ export { sourceFile, sourceFiles } from './core/model/snapshot.js';
8
10
  export type { InventoryFile, SourceFile, SourceSnapshot } from './core/model/source.js';
9
11
  export { measurements } from './core/model/measurement.js';
10
12
  export type { Measurement } from './core/model/measurement.js';
11
13
  export { findingResult } from './core/model/finding.js';
12
14
  export type { Finding, FindingResult } from './core/model/finding.js';
13
15
  export type { SourceContext, SourcePlugin, SourceProvider } from './core/ports/source-provider.js';
16
+ export type { ToolInvocation, ToolResult, ToolRunner } from './core/ports/tool-runner.js';
17
+ export { DockerToolRunner } from './api/process/docker-tool-runner.js';
18
+ export type { DockerToolLimits } from './api/process/docker-tool-runner.js';
19
+ export { processPlugin, processPluginProtocol } from './api/process/plugin.js';
20
+ export type { ProcessOperation, ProcessPluginManifest } from './api/process/plugin.js';
14
21
  export type { SourceLocator } from './core/model/source-locator.js';
@@ -1,6 +1,8 @@
1
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';
2
+ export { codeStructure, codeStructures } from './core/model/code-structure.js';
3
+ export { sourceFile, sourceFiles } from './core/model/snapshot.js';
4
4
  export { measurements } from './core/model/measurement.js';
5
5
  export { findingResult } from './core/model/finding.js';
6
+ export { DockerToolRunner } from './api/process/docker-tool-runner.js';
7
+ export { processPlugin, processPluginProtocol } from './api/process/plugin.js';
6
8
  //# sourceMappingURL=plugin.js.map
@@ -1,11 +1,13 @@
1
1
  import type { DataContract, Plugin } from '../../core/engine/plugin.js';
2
2
  import type { Measurement } from '../../core/model/measurement.js';
3
- import type { LineCoverage } from '../../core/model/line-coverage.js';
3
+ import type { FunctionCallCount, LineCoverage } from '../../core/model/line-coverage.js';
4
+ import type { SourceLineRange } from '../../core/model/source.js';
4
5
  export interface CoverageInput {
5
6
  readonly text: string;
6
7
  readonly root: string;
7
8
  readonly sourceLines: ReadonlyMap<string, number>;
8
9
  readonly codeLines?: ReadonlyMap<string, ReadonlySet<number>>;
10
+ readonly functionBodies?: ReadonlyMap<string, readonly SourceLineRange[]>;
9
11
  readonly excludes?: (path: string) => boolean;
10
12
  }
11
13
  interface CoverageResult {
@@ -22,7 +24,8 @@ export declare const coverage: Plugin;
22
24
  export declare function mapCoverage({ text, root, sourceLines, codeLines, excludes }: CoverageInput): {
23
25
  files: Map<string, Map<number, number>>;
24
26
  branches: Map<string, Map<string, number>>;
25
- functions: Map<string, Map<string, boolean>>;
27
+ functions: Map<string, Map<string, number>>;
28
+ functionCalls: Map<string, readonly FunctionCallCount[]>;
26
29
  gaps: Map<string, string>;
27
30
  };
28
31
  export {};
@@ -9,6 +9,7 @@ export const lcovInput = {
9
9
  accepts: (value) => isRecord(value) && typeof value.text === 'string'
10
10
  && typeof value.root === 'string' && value.sourceLines instanceof Map
11
11
  && (value.codeLines === undefined || value.codeLines instanceof Map)
12
+ && (value.functionBodies === undefined || value.functionBodies instanceof Map)
12
13
  && (value.excludes === undefined || typeof value.excludes === 'function'),
13
14
  };
14
15
  export const coverageResult = {
@@ -37,7 +38,8 @@ export const coverage = {
37
38
  { id: definitions.coverableFunctions, label: 'Measured functions', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Coverage' },
38
39
  ] }, { contract: lcovLines.id, persistence: 'report',
39
40
  schema: { ...reportSchema.$defs.lcovLines,
40
- $defs: { lcovLineRanges: reportSchema.$defs.lcovLineRanges, lcovHitRuns: reportSchema.$defs.lcovHitRuns } } }],
41
+ $defs: { lcovLineRanges: reportSchema.$defs.lcovLineRanges, lcovHitRuns: reportSchema.$defs.lcovHitRuns,
42
+ lcovFunctionCalls: reportSchema.$defs.lcovFunctionCalls } } }],
41
43
  operations: [{
42
44
  id: 'import',
43
45
  role: 'inspection',
@@ -55,7 +57,7 @@ export const coverage = {
55
57
  export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
56
58
  const files = new Map();
57
59
  // Branches by line, block and branch. Functions by name and its occurrence in the record: tools such as c8 repeat a
58
- // name for different functions and list FNDA in FN order. Several reports merge by any hit.
60
+ // name for different functions and list FNDA in FN order.
59
61
  const branches = new Map();
60
62
  const declared = new Map();
61
63
  const called = new Map();
@@ -111,7 +113,7 @@ export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
111
113
  if (ignored || !files.has(active))
112
114
  continue;
113
115
  const branch = /^BRDA:([1-9]\d*),([^,]+),([^,]+),(\d+|-)$/.exec(line);
114
- const declaration = /^FN:[1-9]\d*(?:,[1-9]\d*)?,(.+)$/.exec(line);
116
+ const declaration = /^FN:([1-9]\d*)(?:,[1-9]\d*)?,(.+)$/.exec(line);
115
117
  const call = /^FNDA:(\d+),(.+)$/.exec(line);
116
118
  if (branch) {
117
119
  const taken = branch[4] === '-' ? 0 : Number(branch[4]);
@@ -121,12 +123,19 @@ export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
121
123
  branches.set(active, file);
122
124
  }
123
125
  else if (declaration) {
124
- declared.set(active, (declared.get(active) ?? new Set()).add(occurrence(occurrences.declared, declaration[1])));
126
+ const number = Number(declaration[1]);
127
+ if (!Number.isSafeInteger(number))
128
+ throw new Error(`Invalid LCOV function line at line ${index + 1}`);
129
+ const key = occurrence(occurrences.declared, declaration[2]);
130
+ const file = declared.get(active) ?? new Map();
131
+ if (!file.has(key))
132
+ file.set(key, number);
133
+ declared.set(active, file);
125
134
  }
126
135
  else if (call) {
127
136
  const key = occurrence(occurrences.called, call[2]);
128
137
  const file = called.get(active) ?? new Map();
129
- file.set(key, (file.get(key) ?? false) || Number(call[1]) > 0);
138
+ addHits(file, key, Number(call[1]), index + 1);
130
139
  called.set(active, file);
131
140
  }
132
141
  else {
@@ -143,8 +152,21 @@ export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
143
152
  throw new Error('Unterminated LCOV source record');
144
153
  if (!sawSource && text.trim() !== '')
145
154
  throw new Error('LCOV contains no source records');
146
- const functions = new Map([...declared].map(([path, names]) => [path, new Map([...names].map(name => [name, called.get(path)?.get(name) ?? false]))]));
147
- return { files, branches, functions, gaps };
155
+ const functions = new Map();
156
+ const functionCalls = new Map();
157
+ for (const [path, declarations] of declared) {
158
+ const hits = called.get(path);
159
+ functions.set(path, new Map([...declarations.keys()].map(key => [key, hits?.get(key) ?? 0])));
160
+ const counts = [];
161
+ for (const [key, first] of declarations) {
162
+ const count = hits?.get(key);
163
+ if (count !== undefined && first <= sourceLines.get(path))
164
+ counts.push([first, count]);
165
+ }
166
+ if (counts.length)
167
+ functionCalls.set(path, counts.sort(([left], [right]) => left - right));
168
+ }
169
+ return { files, branches, functions, functionCalls, gaps };
148
170
  }
149
171
  function addHits(hits, key, count, record) {
150
172
  const total = (hits.get(key) ?? 0) + count;
@@ -153,7 +175,7 @@ function addHits(hits, key, count, record) {
153
175
  hits.set(key, total);
154
176
  }
155
177
  function importCoverage(input) {
156
- const { files, branches, functions, gaps } = mapCoverage(input);
178
+ const { files, branches, functions, functionCalls, gaps } = mapCoverage(input);
157
179
  const rows = [];
158
180
  const lineCoverage = [];
159
181
  let totalCovered = 0;
@@ -166,11 +188,14 @@ function importCoverage(input) {
166
188
  (hit ? hitLines : missedLines).push(line);
167
189
  const partialHits = partiallyCoveredLines(branches.get(path), input.sourceLines.get(path), input.codeLines?.get(path));
168
190
  const partial = mergedRanges([...partialHits.keys()]);
169
- if (hits.size || partial.length) {
191
+ const calls = functionCalls.get(path);
192
+ const bodies = input.functionBodies?.get(path);
193
+ if (hits.size || partial.length || calls !== undefined) {
170
194
  // A BRDA-only partial line has at least as many hits as its most frequently taken branch.
171
195
  const measured = new Map([...partialHits, ...hits]);
172
196
  lineCoverage.push([path, { covered: mergedRanges(hitLines), uncovered: mergedRanges(missedLines),
173
- ...(partial.length ? { partial } : {}), hits: mergedHits(measured) }]);
197
+ ...(partial.length ? { partial } : {}), hits: mergedHits(measured),
198
+ ...(calls === undefined ? {} : { functionCalls: calls }), ...(bodies === undefined ? {} : { functionBodies: bodies }) }]);
174
199
  }
175
200
  const covered = hitLines.length;
176
201
  totalCovered += covered;
@@ -5,7 +5,7 @@ import { definitions } from '../../core/model/measurement.js';
5
5
  import { isCloneSource } from '../../core/model/clone-source.js';
6
6
  import { duplicationSettings } from '../../core/profile/maintainability.js';
7
7
  const cloneSources = {
8
- id: 'repometry.clone-sources-babel/v1',
8
+ id: 'repometry.clone-sources/v1',
9
9
  accepts: (value) => Array.isArray(value) && value.every(isCloneSource),
10
10
  };
11
11
  export const duplication = {
@@ -22,8 +22,14 @@ export const duplication = {
22
22
  };
23
23
  export const duplicationInput = cloneSources;
24
24
  function detectClones(sources) {
25
- const byFingerprint = new Map();
26
- for (const { path, candidates } of sources) {
25
+ const schemes = new Map();
26
+ for (const { path, candidates, scheme } of sources) {
27
+ const name = scheme ?? 'babel-syntax';
28
+ let byFingerprint = schemes.get(name);
29
+ if (!byFingerprint) {
30
+ byFingerprint = new Map();
31
+ schemes.set(name, byFingerprint);
32
+ }
27
33
  for (const candidate of candidates) {
28
34
  const occurrences = byFingerprint.get(candidate.similar);
29
35
  const occurrence = { ...candidate, path };
@@ -33,7 +39,7 @@ function detectClones(sources) {
33
39
  byFingerprint.set(candidate.similar, [occurrence]);
34
40
  }
35
41
  }
36
- const groups = [...byFingerprint.values()].filter(group => group.length > 1)
42
+ const groups = [...schemes.values()].flatMap(byFingerprint => [...byFingerprint.values()].filter(group => group.length > 1))
37
43
  .sort((left, right) => right[0].nodes - left[0].nodes || comparePaths(left[0].similar, right[0].similar));
38
44
  const matched = new Map(sources.map(source => [source.path, []]));
39
45
  const findings = [];
@@ -3,11 +3,12 @@ import { extname } from 'node:path';
3
3
  import { parse } from '@babel/parser';
4
4
  import { pluginApi } from '../../core/engine/plugin.js';
5
5
  import { codeStructure } from '../../core/model/code-structure.js';
6
- import { physicalLines, sourceExtensions, sourceFile, utf8 } from '../../core/model/snapshot.js';
6
+ import { physicalLines, sourceFile, utf8 } from '../../core/model/snapshot.js';
7
7
  import { cloneCandidates } from './clone-candidates.js';
8
8
  import { classifyLines } from './code-lines.js';
9
9
  import { functionFacts } from './function-facts.js';
10
10
  import { structuralObservations } from './structural-observations.js';
11
+ import { javaScriptExtensions, jsTsExtensions, typeScriptExtensions } from './extensions.js';
11
12
  const require = createRequire(import.meta.url);
12
13
  export const parserDefaults = { sourceType: 'unambiguous', errorRecovery: false, attachComment: false };
13
14
  export const babelTypes = { '@babel/types': require('@babel/types/package.json').version };
@@ -16,7 +17,12 @@ export const babelProvider = {
16
17
  version: '1.0.0',
17
18
  api: pluginApi,
18
19
  kinds: ['language'],
19
- claims: { extensions: sourceExtensions, languages: ['javascript', 'typescript'] },
20
+ claims: { extensions: jsTsExtensions, languages: ['javascript', 'typescript'] },
21
+ providesLanguages: [
22
+ { id: 'javascript', label: 'JavaScript', color: '#f1e05a', extensions: javaScriptExtensions },
23
+ { id: 'typescript', label: 'TypeScript', color: '#3178c6', extensions: typeScriptExtensions },
24
+ ],
25
+ settings: parserDefaults,
20
26
  produces: [{ contract: codeStructure.id, persistence: 'transient' }],
21
27
  tools: { '@babel/parser': require('@babel/parser/package.json').version },
22
28
  operations: [{
@@ -0,0 +1,3 @@
1
+ export declare const javaScriptExtensions: readonly ['.js', '.mjs', '.cjs', '.jsx'];
2
+ export declare const typeScriptExtensions: readonly ['.ts', '.mts', '.cts', '.tsx'];
3
+ export declare const jsTsExtensions: readonly [".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".tsx"];
@@ -0,0 +1,4 @@
1
+ export const javaScriptExtensions = ['.js', '.mjs', '.cjs', '.jsx'];
2
+ export const typeScriptExtensions = ['.ts', '.mts', '.cts', '.tsx'];
3
+ export const jsTsExtensions = [...javaScriptExtensions, ...typeScriptExtensions];
4
+ //# sourceMappingURL=extensions.js.map
@@ -3,6 +3,7 @@ import type { FunctionComplexity } from '../../core/model/code-structure.js';
3
3
  export declare function functionFacts(ast: Node): {
4
4
  functions: number;
5
5
  cyclomaticFunctions: FunctionComplexity[];
6
+ functionBodies: [number, number][];
6
7
  };
7
8
  export declare function children(node: Node): Iterable<Node>;
8
9
  export declare function functionName(node: BabelFunction): string;
@@ -1,13 +1,20 @@
1
- import { VISITOR_KEYS, isFunction, isIdentifier, isStringLiteral } from '@babel/types';
1
+ import { VISITOR_KEYS, isBlockStatement, isFunction, isIdentifier, isStringLiteral } from '@babel/types';
2
2
  const decisionNodes = new Set(['IfStatement', 'ConditionalExpression', 'ForStatement', 'ForInStatement', 'ForOfStatement',
3
3
  'WhileStatement', 'DoWhileStatement', 'CatchClause', 'LogicalExpression']);
4
4
  export function functionFacts(ast) {
5
5
  let functions = 0;
6
- walk(ast, node => { if (isFunction(node) && node.body)
7
- functions++; });
6
+ const bodyRanges = [];
7
+ walk(ast, node => {
8
+ if (!isFunction(node) || !node.body)
9
+ return;
10
+ functions++;
11
+ const range = bodyRange(node.body);
12
+ if (range)
13
+ bodyRanges.push(range);
14
+ });
8
15
  const cyclomaticFunctions = [];
9
16
  visit(ast, undefined);
10
- return { functions, cyclomaticFunctions };
17
+ return { functions, cyclomaticFunctions, functionBodies: mergeBodyRanges(bodyRanges) };
11
18
  function visit(node, frame) {
12
19
  if (isFunction(node) && node.body) {
13
20
  const own = { value: 1 };
@@ -26,6 +33,25 @@ export function functionFacts(ast) {
26
33
  visit(child, frame);
27
34
  }
28
35
  }
36
+ function bodyRange(body) {
37
+ if (!isBlockStatement(body))
38
+ return body.loc ? [body.loc.start.line, body.loc.end.line] : undefined;
39
+ const first = body.directives[0] ?? body.body[0];
40
+ const last = body.body.at(-1) ?? body.directives.at(-1);
41
+ if (first?.loc && last?.loc)
42
+ return [first.loc.start.line, last.loc.end.line];
43
+ }
44
+ function mergeBodyRanges(ranges) {
45
+ const merged = [];
46
+ for (const [first, last] of ranges.sort(([left], [right]) => left - right)) {
47
+ const previous = merged.at(-1);
48
+ if (previous && first <= previous[1] + 1)
49
+ previous[1] = Math.max(previous[1], last);
50
+ else
51
+ merged.push([first, last]);
52
+ }
53
+ return merged;
54
+ }
29
55
  export function* children(node) {
30
56
  const properties = node;
31
57
  for (const key of VISITOR_KEYS[node.type] ?? []) {
@@ -3,7 +3,8 @@ import { extname } from 'node:path';
3
3
  import { parse } from '@babel/parser';
4
4
  import { pluginApi } from '../../core/engine/plugin.js';
5
5
  import { findingResult } from '../../core/model/finding.js';
6
- import { sourceExtensions, sourceFile, utf8 } from '../../core/model/snapshot.js';
6
+ import { sourceFile, utf8 } from '../../core/model/snapshot.js';
7
+ import { jsTsExtensions } from './extensions.js';
7
8
  import { babelTypes, parserDefaults } from './babel-provider.js';
8
9
  import { children } from './function-facts.js';
9
10
  const require = createRequire(import.meta.url);
@@ -42,7 +43,7 @@ export const jsSecurity = {
42
43
  version: '1.0.0',
43
44
  api: pluginApi,
44
45
  kinds: ['security'],
45
- claims: { extensions: sourceExtensions },
46
+ claims: { extensions: jsTsExtensions },
46
47
  produces: [{ contract: findingResult.id, persistence: 'report' }],
47
48
  tools: { '@babel/parser': require('@babel/parser/package.json').version, ...babelTypes },
48
49
  rules: jsSecurityRules,
@@ -0,0 +1,11 @@
1
+ import type { ChartPoint } from './viewer-chart-points.js';
2
+ import type { Layout } from './viewer-chart-svg.js';
3
+ export interface BarOptions {
4
+ readonly format: (value: number) => string;
5
+ readonly compact: boolean;
6
+ /** Positive values are bad news (for example, added debt). */
7
+ readonly upIsWorse: boolean;
8
+ /** Round tick values to this unit, as for line charts. */
9
+ readonly tickUnit?: number | undefined;
10
+ }
11
+ export declare function barChart(svg: SVGSVGElement, layout: Layout, points: readonly ChartPoint[], options: BarOptions): void;
@@ -0,0 +1,54 @@
1
+ import { markBoundaries, measuredValues, pointLink } from './viewer-chart-points.js';
2
+ import { yAxis } from './viewer-chart-scale.js';
3
+ import { centredText, line, setAttributes, svgNode } from './viewer-chart-svg.js';
4
+ import { placeX } from './viewer-chart-x.js';
5
+ /** The room beside a bar: the distance to the nearer neighbour. */
6
+ function room(x, count, index) {
7
+ const before = index > 0 ? x(index) - x(index - 1) : Infinity;
8
+ const after = index < count - 1 ? x(index + 1) - x(index) : Infinity;
9
+ return Math.min(before, after);
10
+ }
11
+ /** A bar from zero to the value, labelled where the label fits or the commit is the selected one. */
12
+ function bar({ points, x, y, format, upIsWorse }, index, width, space) {
13
+ const point = points[index];
14
+ const value = point.value;
15
+ const worse = upIsWorse ? value > 0 : value < 0;
16
+ const rect = svgNode('rect', `tc-bar ${worse ? 'tc-bar-worse' : 'tc-bar-better'}${point.current ? ' tc-bar-current' : ''}`);
17
+ setAttributes(rect, { x: x(index) - width / 2, y: Math.min(y(value), y(0)), width, height: Math.max(1, Math.abs(y(value) - y(0))) });
18
+ if (!point.current && format(value).length * 7.6 >= space)
19
+ return [rect];
20
+ const at = value > 0 ? y(value) - 7 : y(value) + 16;
21
+ return [rect, centredText(format(value), point.current ? 'tc-value tc-value-current' : 'tc-value', x(index), at)];
22
+ }
23
+ /** A point's marks: its bar, a flat mark for no change, or a tick on the zero line where nothing was measured. */
24
+ function barMarks(context, index) {
25
+ const { points, x, y } = context;
26
+ const value = points[index].value;
27
+ const space = room(x, points.length, index);
28
+ const width = Math.max(2, Math.min(28, Number.isFinite(space) ? space * .62 : 28));
29
+ const cx = x(index);
30
+ if (value === null)
31
+ return [line('tc-missing-mark', { x1: cx, x2: cx, y1: y(0) - 3.5, y2: y(0) + 3.5 })];
32
+ if (value === 0)
33
+ return [line('tc-zero-mark', { x1: cx - width / 2, x2: cx + width / 2, y1: y(0), y2: y(0) })];
34
+ return bar(context, index, width, space);
35
+ }
36
+ export function barChart(svg, layout, points, options) {
37
+ svg.classList.add('tc-bars');
38
+ const y = yAxis(svg, layout, { values: measuredValues(points.map(point => point.value)), ratio: false, count: options.compact ? 3 : 4,
39
+ format: options.format, tickUnit: options.tickUnit ?? 1, zero: true });
40
+ placeX(svg, layout, points);
41
+ markBoundaries(svg, layout, points);
42
+ const x = (index) => layout.xs[index];
43
+ layout.ys = points.map(point => point.value === null ? null : y(point.value));
44
+ // In a long history the zero line already says "no change" and "not measured"; only bars that moved are drawn.
45
+ const dense = layout.xs.some((at, index) => index > 0 && at - layout.xs[index - 1] < 7);
46
+ const context = { ...options, points, x, y };
47
+ for (const [index, point] of points.entries()) {
48
+ const link = pointLink(point, index);
49
+ const quiet = !point.current && !point.value;
50
+ if (!dense || !quiet)
51
+ link.append(...barMarks(context, index));
52
+ svg.append(link);
53
+ }
54
+ }
@@ -0,0 +1,15 @@
1
+ import type { ChartPoint } from './viewer-chart-points.js';
2
+ export interface LabelContext {
3
+ readonly points: readonly ChartPoint[];
4
+ readonly x: (index: number) => number;
5
+ readonly y: (value: number) => number;
6
+ readonly format: (value: number) => string;
7
+ /** The y of the plot's bottom edge. */
8
+ readonly axis: number;
9
+ }
10
+ /**
11
+ * The value of the labelled point. A flag on this point or one just beside it takes the space above, so the value
12
+ * moves left of the pole; a label pushed far from its point would sit on the line, so it goes under the point instead,
13
+ * where a flag never is.
14
+ */
15
+ export declare function valueLabel(context: LabelContext, index: number): SVGTextElement;
@@ -0,0 +1,43 @@
1
+ import { text } from './viewer-chart-svg.js';
2
+ /** The x of every flag whose pole and pennant a label between `left` and `anchor` at `top` would cover. */
3
+ function flagsCrossed({ points, x, y }, left, anchor, top) {
4
+ return points.flatMap((other, at) => {
5
+ if (!other.flag || other.value === null)
6
+ return [];
7
+ const foot = y(other.value) - 4;
8
+ const across = x(at) >= left && x(at) <= anchor + 11;
9
+ return across && top > foot - 22 && top - 14 < foot ? [x(at)] : [];
10
+ });
11
+ }
12
+ /** The label runs left from its anchor; it steps left of every flag it would cross, so it never covers one. */
13
+ function clearOfFlags(context, start, top, width) {
14
+ let anchor = start;
15
+ let poles = [];
16
+ for (let pass = 0; pass < 4; pass += 1) {
17
+ const crossed = flagsCrossed(context, anchor - width - 4, anchor, top);
18
+ if (!crossed.length || Math.min(...crossed) - 7 >= anchor)
19
+ break;
20
+ poles = crossed;
21
+ anchor = Math.min(...crossed) - 7;
22
+ }
23
+ return { anchor, poles };
24
+ }
25
+ /**
26
+ * The value of the labelled point. A flag on this point or one just beside it takes the space above, so the value
27
+ * moves left of the pole; a label pushed far from its point would sit on the line, so it goes under the point instead,
28
+ * where a flag never is.
29
+ */
30
+ export function valueLabel(context, index) {
31
+ const { points, x, y, format, axis } = context;
32
+ const point = points[index];
33
+ const value = point.value;
34
+ const last = index === points.length - 1;
35
+ const top = y(value) - 11;
36
+ const cleared = clearOfFlags(context, x(index), top, format(value).length * 7.2);
37
+ const below = x(index) - cleared.anchor > 40 && y(value) + 22 <= axis;
38
+ const anchor = below ? x(index) + (last ? 4 : 0) : cleared.anchor;
39
+ const label = text(format(value), point.current ? 'tc-value tc-value-current' : 'tc-value', anchor, below ? y(value) + 21 : top);
40
+ const flush = (cleared.poles.length > 0 && !below) || (last && points.length > 1);
41
+ label.setAttribute('text-anchor', flush ? 'end' : 'middle');
42
+ return label;
43
+ }