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
@@ -7,14 +7,13 @@ export function expandLocator(template, { revision, path, line }) {
7
7
  const fragment = hash < 0 ? '' : template.slice(hash);
8
8
  const base = hash < 0 ? template : template.slice(0, hash);
9
9
  const kept = line === undefined && fragment.includes('{line}') ? '' : fragment;
10
- return (base + kept).replace(/\{(revision|path:component|path|line)\}/g, (_, name) => {
11
- switch (name) {
12
- case 'revision': return encodeURIComponent(revision);
13
- case 'path:component': return encodeURIComponent(path);
14
- case 'path': return path.split('/').map(encodeURIComponent).join('/');
15
- default: return String(line);
16
- }
17
- });
10
+ const values = {
11
+ revision: encodeURIComponent(revision),
12
+ 'path:component': encodeURIComponent(path),
13
+ path: path.split('/').map(encodeURIComponent).join('/'),
14
+ line: String(line),
15
+ };
16
+ return (base + kept).replace(/\{(revision|path:component|path|line)\}/g, (_, name) => values[name]);
18
17
  }
19
18
  /** A locator the viewer can use: a fetch URL that is web or site-relative, and a page link only over http(s). */
20
19
  export function sourceLocator(value) {
@@ -56,360 +55,3 @@ export function sourcePage(sha, path, line) {
56
55
  const name = providerNames[locator.provider.toLowerCase()] ?? locator.provider.charAt(0).toUpperCase() + locator.provider.slice(1);
57
56
  return { href: expandLocator(locator.web, { revision: sha, path, line }), provider: name };
58
57
  }
59
- export function isSourceLayer(value) {
60
- return value === 'issues' || value === 'coverage';
61
- }
62
- /**
63
- * Each line's coverage, by line number; a line no range names was not measured. Where ranges overlap, the worse
64
- * state wins: a line a test missed is never shown as covered.
65
- */
66
- export function lineStates(coverage) {
67
- const states = new Map();
68
- const lay = (ranges, state) => {
69
- for (const [from, to] of ranges ?? [])
70
- for (let line = Math.max(1, from); line <= to; line++)
71
- states.set(line, state);
72
- };
73
- lay(coverage.covered, 'covered');
74
- lay(coverage.partial, 'partial');
75
- lay(coverage.uncovered, 'uncovered');
76
- return states;
77
- }
78
- /** How often tests ran each line, where the report carries the counts; an older report has none. */
79
- export function lineHits(coverage) {
80
- const hits = new Map();
81
- for (const [from, to, count] of coverage.hits ?? [])
82
- for (let line = Math.max(1, from); line <= to; line++)
83
- hits.set(line, count);
84
- return hits;
85
- }
86
- // Two figures are enough for a glance; the tooltip has the whole count.
87
- const compactCount = new Intl.NumberFormat('en', { notation: 'compact', maximumSignificantDigits: 2 });
88
- const fullCount = new Intl.NumberFormat();
89
- /** A count short enough for the gutter: 3×, 980×, 1.2K×, 45K×, 270K×, 3.4M×. */
90
- export function hitLabel(count) {
91
- return `${count < 1000 ? count : compactCount.format(count)}×`;
92
- }
93
- /** What a measured line says to a pointer and a screen reader: its state, and how often it ran where that is known. */
94
- export function lineCoverageText(state, count) {
95
- if (count === undefined || state === 'uncovered')
96
- return lineStateNames[state];
97
- return `${lineStateNames[state]}. Ran ${fullCount.format(count)} ${count === 1 ? 'time' : 'times'}`;
98
- }
99
- const lineStateNames = {
100
- covered: 'Covered', partial: 'Partly covered: some branches missed', uncovered: 'Not covered',
101
- };
102
- /** Switches a rendered source between its findings and its coverage, without drawing it again. */
103
- export function setSourceLayer(container, layer) {
104
- const code = container.querySelector(':scope > .src');
105
- if (code)
106
- code.dataset.layer = layer;
107
- }
108
- /** The source as numbered lines; returns a function that brings a line into view and marks it. */
109
- export function renderSource(container, text, options) {
110
- const lines = text.replace(/\r\n?/g, '\n').replace(/\n$/, '').split('\n');
111
- // Tokenized up front, in order, since a comment's state carries from line to line.
112
- const tokenize = tokenizer(options.path);
113
- const tokens = lines.map(line => tokenize(line));
114
- const bridged = options.coverage ? bridgeStates(options.coverage, tokens.map(codeless)) : new Map();
115
- const starts = new Map(options.functions.map(entry => [entry.line, entry]));
116
- const notes = new Map();
117
- for (const note of options.notes)
118
- notes.set(note.line, [...notes.get(note.line) ?? [], note]);
119
- const code = element('div', 'src');
120
- code.dataset.layer = options.layer ?? 'issues';
121
- code.setAttribute('role', 'region');
122
- code.setAttribute('aria-label', `Source of ${options.path}`);
123
- const rows = [];
124
- const fragment = document.createDocumentFragment();
125
- for (const [index, line] of lines.entries()) {
126
- const number = index + 1;
127
- const row = element('div', 'src-line');
128
- row.id = `L${number}`;
129
- const mark = element('span', 'src-mark');
130
- const start = starts.get(number);
131
- if (start) {
132
- const badge = element('span', `src-complexity src-band-${start.complexity >= 20 ? 3 : start.complexity >= 10 ? 2 : start.complexity >= 5 ? 1 : 0}`, String(start.complexity));
133
- badge.title = `Cyclomatic complexity ${start.complexity}`;
134
- mark.append(badge);
135
- }
136
- // The coverage layer tints each measured line's gutter cell and writes in it how often the line ran; a miss's red says it.
137
- // Nothing runs on a blank or comment line: where a tool counts one anyway, or it sits inside a run of one state, it
138
- // keeps the strip's tint and says nothing.
139
- const runs = tokens[index];
140
- const own = options.coverage?.get(number);
141
- const state = own ?? bridged.get(number);
142
- if (state && (!own || codeless(runs))) {
143
- const cell = element('span', `src-cov src-cov-mark-${state}`);
144
- cell.setAttribute('aria-hidden', 'true');
145
- mark.append(cell);
146
- }
147
- else if (state) {
148
- const count = options.hits?.get(number);
149
- const cell = element('span', `src-cov src-cov-mark-${state}`, count === undefined || state === 'uncovered' ? '' : hitLabel(count));
150
- cell.setAttribute('role', 'img');
151
- cell.setAttribute('aria-label', lineCoverageText(state, count));
152
- cell.title = lineCoverageText(state, count);
153
- mark.append(cell);
154
- }
155
- const anchor = element('a', 'src-number', String(number));
156
- anchor.href = `#L${number}`;
157
- anchor.addEventListener('click', event => {
158
- event.preventDefault();
159
- reveal(number, false);
160
- options.choose(number);
161
- });
162
- const content = element('code', 'src-code');
163
- content.append(...runs.map(([kind, value]) => kind ? element('span', `tok-${kind}`, value) : document.createTextNode(value)));
164
- if (notes.has(number))
165
- row.classList.add('src-flagged');
166
- row.append(mark, anchor, content);
167
- fragment.append(row);
168
- rows.push(row);
169
- for (const note of notes.get(number) ?? []) {
170
- const box = element('div', `src-note src-note-${note.level}`);
171
- box.append(element('strong', '', note.title), element('span', '', note.message));
172
- fragment.append(box);
173
- }
174
- }
175
- rows[0]?.classList.add('src-first');
176
- rows.at(-1)?.classList.add('src-last');
177
- code.append(fragment);
178
- container.replaceChildren(code);
179
- function reveal(line, scroll = true) {
180
- for (const row of code.querySelectorAll('.src-target'))
181
- row.classList.remove('src-target');
182
- const row = rows[line - 1];
183
- if (!row)
184
- return;
185
- row.classList.add('src-target');
186
- if (scroll)
187
- row.scrollIntoView({ block: 'center' });
188
- }
189
- if (options.line)
190
- requestAnimationFrame(() => reveal(options.line));
191
- return reveal;
192
- }
193
- /**
194
- * A few lines of source around a finding, bounded so a 160-line function stays a card: one line of context,
195
- * the head of the flagged range marked, then a link to the rest.
196
- */
197
- export function renderExcerpt(text, options) {
198
- const lines = text.replace(/\r\n?/g, '\n').replace(/\n$/, '').split('\n');
199
- const end = Math.min(lines.length, Math.max(options.line, options.endLine ?? options.line));
200
- const from = Math.max(1, options.line - 1);
201
- const to = Math.min(end, from + (options.size ?? 6) - 1, lines.length);
202
- const highlight = highlighter(options.path);
203
- const box = element('div', 'src src-excerpt');
204
- for (const [index, line] of lines.entries()) {
205
- // Highlighting runs from the top so a comment or template opened above the excerpt keeps its colour.
206
- const nodes = highlight(line);
207
- const number = index + 1;
208
- if (number < from)
209
- continue;
210
- if (number > to)
211
- break;
212
- const row = element('div', number >= options.line && number <= end ? 'src-line src-range' : 'src-line');
213
- const code = element('code', 'src-code');
214
- code.append(...nodes);
215
- row.append(element('span', 'src-mark'), element('span', 'src-number', String(number)), code);
216
- box.append(row);
217
- }
218
- if (end > to) {
219
- const rest = element(options.more ? 'a' : 'span', 'src-more', `⋯ ${end - to} more ${end - to === 1 ? 'line' : 'lines'}, to line ${end}`);
220
- if (options.more && rest instanceof HTMLAnchorElement)
221
- rest.href = options.more(to + 1);
222
- box.append(rest);
223
- }
224
- return box;
225
- }
226
- /** The first code on a line, trimmed: a name for an anonymous function that says which one it is. */
227
- export function lineSnippet(text, line, limit = 60) {
228
- const found = text.split('\n')[line - 1]?.trim();
229
- if (!found)
230
- return null;
231
- return found.length > limit ? `${found.slice(0, limit - 1)}…` : found;
232
- }
233
- /** A single line of code, coloured as the source view colours it; for a snippet that stands on its own. */
234
- export function highlightCode(path, line) {
235
- return highlighter(path)(line);
236
- }
237
- const keywords = new Set(('abstract as async await break case catch class const continue debugger declare default delete do else enum export '
238
- + 'extends false finally for from function get if implements import in instanceof interface let new null of package private protected '
239
- + 'public readonly return satisfies set static super switch this throw true try type typeof undefined var void while with yield').split(' '));
240
- /** Words after which a slash opens a regular expression rather than divides. */
241
- const beforeRegex = new Set('return typeof instanceof in of new delete void throw case do else yield await'.split(' '));
242
- /**
243
- * Splits lines of JavaScript or TypeScript into coloured runs: comments, strings, regular expressions, numbers and
244
- * keywords. It is a scanner, not a parser, but it honours escapes and character classes, and it tells a regular
245
- * expression from a division by what comes before the slash. State carries across lines, so a block comment or a
246
- * template literal stays coloured to its end. Other languages come back as plain text.
247
- */
248
- export function tokenizer(path) {
249
- if (!/\.(m|c)?[jt]sx?$/.test(path))
250
- return line => [['', line]];
251
- let open = '';
252
- let regexAllowed = true;
253
- return line => {
254
- const runs = [];
255
- let plain = '';
256
- const push = (kind, value) => {
257
- if (!value)
258
- return;
259
- if (!kind) {
260
- plain += value;
261
- return;
262
- }
263
- if (plain) {
264
- runs.push(['', plain]);
265
- plain = '';
266
- }
267
- runs.push([kind, value]);
268
- };
269
- // Past an escape: the index after the closing quote, or the line's end when it stays open.
270
- const close = (from, quote) => {
271
- let at = from;
272
- while (at < line.length && line[at] !== quote)
273
- at += line[at] === '\\' ? 2 : 1;
274
- return at < line.length ? [at + 1, true] : [line.length, false];
275
- };
276
- let at = 0;
277
- while (at < line.length) {
278
- if (open === 'comment') {
279
- const end = line.indexOf('*/', at);
280
- const stop = end < 0 ? line.length : end + 2;
281
- push('c', line.slice(at, stop));
282
- at = stop;
283
- if (end >= 0)
284
- open = '';
285
- continue;
286
- }
287
- if (open === 'template') {
288
- const [stop, closed] = close(at, '`');
289
- push('s', line.slice(at, stop));
290
- at = stop;
291
- if (closed) {
292
- open = '';
293
- regexAllowed = false;
294
- }
295
- continue;
296
- }
297
- const char = line[at];
298
- const next = line[at + 1];
299
- if (char === '/' && next === '/') {
300
- push('c', line.slice(at));
301
- break;
302
- }
303
- if (char === '/' && next === '*') {
304
- push('c', '/*');
305
- at += 2;
306
- open = 'comment';
307
- continue;
308
- }
309
- if (char === '`') {
310
- push('s', '`');
311
- at += 1;
312
- open = 'template';
313
- continue;
314
- }
315
- if (char === '"' || char === "'") {
316
- const [stop] = close(at + 1, char);
317
- push('s', line.slice(at, stop));
318
- at = stop;
319
- regexAllowed = false;
320
- continue;
321
- }
322
- if (char === '/' && regexAllowed) {
323
- let end = at + 1;
324
- let inClass = false;
325
- while (end < line.length) {
326
- const current = line[end];
327
- if (current === '\\') {
328
- end += 2;
329
- continue;
330
- }
331
- if (inClass) {
332
- if (current === ']')
333
- inClass = false;
334
- }
335
- else if (current === '[')
336
- inClass = true;
337
- else if (current === '/')
338
- break;
339
- end += 1;
340
- }
341
- if (end < line.length) {
342
- end += 1;
343
- while (end < line.length && /[a-z]/i.test(line[end]))
344
- end += 1;
345
- push('s', line.slice(at, end));
346
- at = end;
347
- regexAllowed = false;
348
- continue;
349
- }
350
- }
351
- const word = /^[A-Za-z_$][\w$]*/.exec(line.slice(at))?.[0];
352
- if (word) {
353
- push(keywords.has(word) ? 'k' : '', word);
354
- regexAllowed = beforeRegex.has(word);
355
- at += word.length;
356
- continue;
357
- }
358
- const number = /^(?:0x[\da-f_]+n?|\d[\d_]*(?:\.\d[\d_]*)?(?:e[+-]?\d+)?n?)/i.exec(line.slice(at))?.[0];
359
- if (number) {
360
- push('n', number);
361
- regexAllowed = false;
362
- at += number.length;
363
- continue;
364
- }
365
- push('', char);
366
- // After a closing bracket a slash divides; after any other punctuation it opens a regular expression.
367
- if (!/\s/.test(char))
368
- regexAllowed = char !== ')' && char !== ']';
369
- at += 1;
370
- }
371
- if (plain)
372
- runs.push(['', plain]);
373
- return runs;
374
- };
375
- }
376
- /**
377
- * The tint a gap of blank and comment lines takes so the strip has no breaks: the state of the measured line above it,
378
- * which the gap closes, or for a gap at the file's start, of the line below. A gap beside a line that was not measured
379
- * takes its other neighbour, and one with no measured neighbour stays plain.
380
- */
381
- export function bridgeStates(states, codeless) {
382
- const bridged = new Map();
383
- let line = 1;
384
- while (line <= codeless.length) {
385
- if (states.has(line) || !codeless[line - 1]) {
386
- line += 1;
387
- continue;
388
- }
389
- let end = line;
390
- while (end < codeless.length && !states.has(end + 1) && codeless[end])
391
- end += 1;
392
- const state = states.get(line - 1) ?? states.get(end + 1);
393
- if (state)
394
- for (let at = line; at <= end; at++)
395
- bridged.set(at, state);
396
- line = end + 1;
397
- }
398
- return bridged;
399
- }
400
- /** A line with no code: blank, or nothing but comment. */
401
- export function codeless(runs) {
402
- return runs.every(([kind, value]) => kind === 'c' || !value.trim());
403
- }
404
- function highlighter(path) {
405
- const tokenize = tokenizer(path);
406
- return line => tokenize(line).map(([kind, value]) => kind ? element('span', `tok-${kind}`, value) : document.createTextNode(value));
407
- }
408
- function element(tag, className, text) {
409
- const node = document.createElement(tag);
410
- if (className)
411
- node.className = className;
412
- if (text !== undefined)
413
- node.textContent = text;
414
- return node;
415
- }
@@ -0,0 +1,13 @@
1
+ import type { FileMetricsReport } from '../../json/wire/file-metrics-model.js';
2
+ import type { Clause, FileFacts } from './viewer-filter.js';
3
+ type FileEntry = FileMetricsReport['files'][number];
4
+ export interface Suggestion {
5
+ readonly group: string;
6
+ readonly label: string;
7
+ readonly detail?: string;
8
+ readonly clause: Clause;
9
+ readonly color?: string;
10
+ }
11
+ /** What the field offers for the typed text: the facets of this codebase first, then conditions, then the path. */
12
+ export declare function suggest(text: string, files: readonly FileEntry[], facts: FileFacts, chosen: readonly Clause[]): Suggestion[];
13
+ export {};
@@ -0,0 +1,91 @@
1
+ import { clauseLabel, parseWord, pluginMeasureList, sameClause } from './viewer-filter.js';
2
+ import { isIgnored, isLockfile, languageColor, languageOf, lockfilesLabel } from './viewer-languages.js';
3
+ /** Ready-made conditions offered before anything is typed: the questions people ask of a codebase most. */
4
+ const presets = [
5
+ { text: 'complexity>10', label: 'Complex functions' },
6
+ { text: 'coverage<80%', label: 'Under 80% covered' },
7
+ { text: 'duplication>0', label: 'Has duplication' },
8
+ { text: 'remediation>0', label: 'Has technical debt' },
9
+ { text: 'changes>0', label: 'Changed recently' },
10
+ { text: 'has:findings', label: 'Has findings' },
11
+ ];
12
+ /** The kinds of clause that read as a condition when typed out whole. */
13
+ const conditionKinds = new Set(['measure', 'has', 'analysed', 'lockfile']);
14
+ function quantity(total) {
15
+ return `${total.toLocaleString()} ${total === 1 ? 'file' : 'files'}`;
16
+ }
17
+ /** A facet is offered while nothing is typed, or when the text is in its name or begins its key. */
18
+ function offered(typing, name, key) {
19
+ return !typing.query || name.toLowerCase().includes(typing.query) || key.startsWith(typing.query);
20
+ }
21
+ function tallied(names) {
22
+ const counts = new Map();
23
+ for (const name of names)
24
+ counts.set(name, (counts.get(name) ?? 0) + 1);
25
+ return counts;
26
+ }
27
+ function languageSuggestions(files, typing) {
28
+ const counts = [...tallied(files.map(file => languageOf(file.path)))].sort((a, b) => b[1] - a[1]);
29
+ return counts.flatMap(([language, total]) => {
30
+ const clause = { kind: 'lang', value: language };
31
+ if (typing.taken(clause) || !offered(typing, language, 'lang'))
32
+ return [];
33
+ return [{ group: 'Languages', label: language, detail: quantity(total), clause, color: languageColor(language) }];
34
+ });
35
+ }
36
+ function componentSuggestions(facts, typing) {
37
+ return [...tallied([...facts.components.values()].flat())].flatMap(([name, total]) => {
38
+ const clause = { kind: 'component', value: name };
39
+ if (typing.taken(clause) || !offered(typing, name, 'component'))
40
+ return [];
41
+ return [{ group: 'Components', label: name, detail: quantity(total), clause }];
42
+ });
43
+ }
44
+ /** Files only counted, never read by a plugin, and lockfiles, are one condition away once the text names them. */
45
+ function categorySuggestions(files, typing) {
46
+ const { query } = typing;
47
+ const named = (words) => query.length >= 3
48
+ && words.some(phrase => phrase.startsWith(query) || (phrase.includes(' ') && phrase.includes(query)));
49
+ const categories = [
50
+ { label: 'Ignored files', clause: { kind: 'analysed', value: 'no' }, total: files.filter(isIgnored).length,
51
+ words: ['ignored files', 'ignored:yes', 'not analysed', 'analysed:no'] },
52
+ { label: lockfilesLabel, clause: { kind: 'lockfile', value: 'yes' }, total: files.filter(file => isLockfile(file.path)).length,
53
+ words: ['lockfiles', 'lockfile:yes'] },
54
+ ];
55
+ return categories.flatMap(({ label, clause, total, words }) => total && !typing.taken(clause) && named(words) ? [{ group: 'Conditions', label, detail: quantity(total), clause }] : []);
56
+ }
57
+ /** Other plugins' metrics are offered once the typed text names them; the presets stay Repometry's own. */
58
+ function conditionSuggestions(typing) {
59
+ const { query, taken } = typing;
60
+ const plugins = query ? pluginMeasureList().flatMap(([key, { label }]) => {
61
+ const clause = { kind: 'measure', measure: key, operator: '>', value: 0 };
62
+ if (taken(clause) || !(key.startsWith(query) || label.toLowerCase().includes(query)))
63
+ return [];
64
+ return [{ group: 'Conditions', label: `${label} above zero`, detail: `${label} > 0`, clause }];
65
+ }) : [];
66
+ const ready = presets.flatMap(preset => {
67
+ const clause = parseWord(preset.text);
68
+ const { key, value } = clauseLabel(clause);
69
+ const fits = !query || preset.label.toLowerCase().includes(query) || preset.text.startsWith(query) || key.toLowerCase().includes(query);
70
+ return !taken(clause) && fits ? [{ group: 'Conditions', label: preset.label, detail: `${key} ${value}`, clause }] : [];
71
+ });
72
+ return [...plugins, ...ready];
73
+ }
74
+ /** A condition typed out whole is offered as itself; otherwise the plugins' metrics and the presets are. */
75
+ function typedSuggestions(typed, typing) {
76
+ if (!typed || !conditionKinds.has(typed.kind) || typing.taken(typed))
77
+ return conditionSuggestions(typing);
78
+ const { key, value } = clauseLabel(typed);
79
+ return [{ group: 'Conditions', label: `${key} ${value}`, clause: typed }];
80
+ }
81
+ /** What the field offers for the typed text: the facets of this codebase first, then conditions, then the path. */
82
+ export function suggest(text, files, facts, chosen) {
83
+ const trimmed = text.trim();
84
+ const typing = { query: trimmed.toLowerCase(), taken: clause => chosen.some(other => sameClause(other, clause)) };
85
+ const typed = typing.query ? parseWord(trimmed) : null;
86
+ // A path is offered for any text that reads as no other kind of chip.
87
+ const path = typing.query && (!typed || typed.kind === 'path')
88
+ ? [{ group: 'Path', label: `Path contains “${trimmed}”`, clause: { kind: 'path', value: trimmed } }] : [];
89
+ return [...languageSuggestions(files, typing), ...componentSuggestions(facts, typing), ...categorySuggestions(files, typing),
90
+ ...typedSuggestions(typed, typing), ...path];
91
+ }
@@ -0,0 +1,5 @@
1
+ import type { Branch, MapDraw } from './viewer-map-shape.js';
2
+ /** The tree as rings: each level one ring further out, each wedge as wide as its share of its parent's lines. */
3
+ export declare function drawRings(map: MapDraw, children: readonly Branch[], first: number, last: number, level: number): void;
4
+ /** The ring's hole holds the total the map is sized by. */
5
+ export declare function centerLabel(total: number, units: string): SVGGElement;
@@ -0,0 +1,40 @@
1
+ import { count, svgElement } from './viewer-dom.js';
2
+ import { chartCenter, innerRadius, outerRadius, sectorPath } from './viewer-map-shape.js';
3
+ /** Wedges thinner than this angle, or past this many, are left out: they could be neither seen nor pointed at. */
4
+ const thinnest = 0.018;
5
+ const mostWedges = 144;
6
+ /** The tree as rings: each level one ring further out, each wedge as wide as its share of its parent's lines. */
7
+ export function drawRings(map, children, first, last, level) {
8
+ if (level >= map.depth)
9
+ return;
10
+ const ring = (outerRadius - innerRadius) / map.depth;
11
+ const total = children.reduce((sum, branch) => sum + branch.area, 0);
12
+ const scale = (last - first) / total;
13
+ let start = first;
14
+ for (const branch of children) {
15
+ const end = start + branch.area * scale;
16
+ if (end - start >= thinnest && map.drawn < mostWedges) {
17
+ const radius = innerRadius + level * ring;
18
+ map.tile(branch, sectorPath(radius, radius + ring, start, end));
19
+ drawRings(map, map.byParent.get(branch.entry.path) ?? [], start, end, level + 1);
20
+ }
21
+ start = end;
22
+ }
23
+ }
24
+ /** The ring's hole holds the total the map is sized by. */
25
+ export function centerLabel(total, units) {
26
+ const center = svgElement('g');
27
+ center.setAttribute('aria-hidden', 'true');
28
+ const value = svgElement('text');
29
+ value.setAttribute('x', String(chartCenter));
30
+ value.setAttribute('y', String(chartCenter + 1));
31
+ value.classList.add('fx-sunburst-value');
32
+ value.textContent = count(total);
33
+ const label = svgElement('text');
34
+ label.setAttribute('x', String(chartCenter));
35
+ label.setAttribute('y', String(chartCenter + 21));
36
+ label.classList.add('fx-sunburst-unit');
37
+ label.textContent = units;
38
+ center.append(value, label);
39
+ return center;
40
+ }
@@ -0,0 +1,25 @@
1
+ import type { ColumnSettings, Columns, MetricColumn } from './viewer-columns.js';
2
+ import type { Group, Row } from './viewer-table-rows.js';
3
+ export interface RowContext {
4
+ readonly group: Group;
5
+ readonly columns: readonly MetricColumn[];
6
+ readonly linkTo: (options?: {
7
+ directory?: string;
8
+ file?: string;
9
+ }) => string;
10
+ readonly selected?: string | undefined;
11
+ }
12
+ /** One row of the Metrics table: its name, with what it is and how many files it holds, then its figures. */
13
+ export declare function metricsRow(row: Row, context: RowContext, open?: () => void): HTMLTableRowElement;
14
+ /** Names a list as people say it: "a, b and c". */
15
+ export declare function spokenList(parts: readonly string[]): string;
16
+ /** The fold at the end of the list: how many entries no plugin read, opening and closing in place. */
17
+ export declare function unreadRow(entries: readonly Row[], span: number, expanded: boolean, toggle: () => void): HTMLTableRowElement;
18
+ /** The table with a sort button per column; a click on the sorted column reverses it. */
19
+ export declare function sortableTable(columns: Columns, settings: ColumnSettings, sorted: () => void): {
20
+ table: HTMLTableElement;
21
+ headers: HTMLTableCellElement[];
22
+ body: HTMLTableSectionElement;
23
+ };
24
+ /** Shows the chosen columns' headers and marks the one the table is sorted by. */
25
+ export declare function markSort(headers: readonly HTMLTableCellElement[], isVisible: (index: number) => boolean, settings: ColumnSettings): void;