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
@@ -0,0 +1,60 @@
1
+ import { choice, choices, navigationButtons, searchField } from './viewer-controls.js';
2
+ import { contains, element, link, quantity } from './viewer-dom.js';
3
+ import { fileHref } from './viewer-file-figures.js';
4
+ import { pageSize } from './viewer-inspection.js';
5
+ const diagnosticStates = { failed: 'Failed', blocked: 'Blocked', partial: 'Partial' };
6
+ function diagnosticItem(row, navigation, files) {
7
+ const item = element('li');
8
+ const heading = element('div', 'fx-event-heading');
9
+ const state = element('span', 'fx-state', diagnosticStates[row.state]);
10
+ state.dataset.state = row.state;
11
+ heading.append(element('code', 'fx-path', row.operation), state);
12
+ item.append(heading, element('p', '', row.message));
13
+ if (row.path)
14
+ item.append(files.has(row.path) ? link(fileHref(navigation, row.path), row.path, 'fx-inline-link') : element('code', 'fx-path', row.path));
15
+ return item;
16
+ }
17
+ /** The Diagnostics page: what the analysis could not do, filtered by a search, an operation and a state. */
18
+ export function diagnosticsView(details, navigation) {
19
+ const { diagnostics, metrics } = details;
20
+ const view = element('section', 'fx-view panel fx-events');
21
+ const path = navigation.file;
22
+ const scoped = path ? diagnostics.filter(row => row.path === path) : diagnostics;
23
+ if (path) {
24
+ const scope = element('div', 'fx-file-heading');
25
+ scope.append(element('code', 'fx-path', path), link(navigation.href('diagnostics'), 'All diagnostics', 'fx-inline-link'));
26
+ view.append(scope);
27
+ }
28
+ if (!scoped.length) {
29
+ view.append(element('p', 'fx-note', path ? 'No analysis diagnostics for this file.' : 'No analysis diagnostics for this commit.'));
30
+ return view;
31
+ }
32
+ const search = searchField('Search diagnostics', 'Operation, path or message');
33
+ const operation = choice('Operation', choices('All operations', scoped.map(row => row.operation)), '');
34
+ const state = choice('State', choices('All states', scoped.map(row => row.state), diagnosticStates), '');
35
+ const tools = element('div', 'fx-tools');
36
+ tools.append(search.label, operation.label, state.label);
37
+ const result = element('p', 'fx-note fx-results');
38
+ result.setAttribute('aria-live', 'polite');
39
+ const events = element('ul', 'fx-event-list');
40
+ const nav = navigationButtons('Diagnostic pages', () => { page--; render(); }, () => { page++; render(); });
41
+ view.append(tools, result, events, nav.section);
42
+ const files = new Set(metrics.files.map(entry => entry.path));
43
+ let page = 0;
44
+ const picked = (select, value) => !select.value || select.value === value;
45
+ function render() {
46
+ const query = search.input.value.trim().toLowerCase();
47
+ const matches = scoped.filter(row => picked(state.select, row.state) && picked(operation.select, row.operation)
48
+ && contains(query, [row.operation, row.path, row.message]));
49
+ result.textContent = matches.length ? quantity(matches.length, 'diagnostic') : 'No diagnostics match these filters.';
50
+ events.replaceChildren(...matches.slice(page * pageSize, (page + 1) * pageSize).map(row => diagnosticItem(row, navigation, files)));
51
+ nav.section.hidden = matches.length <= pageSize;
52
+ nav.update(page, Math.ceil(matches.length / pageSize));
53
+ }
54
+ const reset = () => { page = 0; render(); };
55
+ search.input.addEventListener('input', reset);
56
+ operation.select.addEventListener('change', reset);
57
+ state.select.addEventListener('change', reset);
58
+ render();
59
+ return view;
60
+ }
@@ -0,0 +1,27 @@
1
+ /** The DOM building blocks every page of the viewer shares. */
2
+ /** Paths compare as people read them: numbers by value, so file10 follows file9. */
3
+ export declare const collator: Intl.Collator;
4
+ export declare function element<K extends keyof HTMLElementTagNameMap>(tag: K, className?: string, text?: string): HTMLElementTagNameMap[K];
5
+ export declare function svgElement<K extends keyof SVGElementTagNameMap>(tag: K): SVGElementTagNameMap[K];
6
+ export declare function link(href: string, label: string, className?: string): HTMLAnchorElement;
7
+ /** A link that opens another site in a new tab, without handing it this page. */
8
+ export declare function externalLink(href: string, label: string, className?: string): HTMLAnchorElement;
9
+ /** One row of a description list, with a quieter line of context under the value. */
10
+ export declare function fact(label: string, value: string, context?: string): HTMLElement;
11
+ /** A table that scrolls on its own, named so the region can be found and scrolled from the keyboard. */
12
+ export declare function scrollableTable(table: HTMLTableElement, label: string): HTMLElement;
13
+ export declare function count(value: number | null | undefined): string;
14
+ export declare function percent(value: number): string;
15
+ export declare function quantity(amount: number, noun: string): string;
16
+ export declare function parentPath(path: string): string;
17
+ export declare function basename(path: string): string;
18
+ export declare function inside(path: string, directory: string): boolean;
19
+ /** Whether any of the strings holds the lowercased query; an empty query holds everywhere. */
20
+ export declare function contains(query: string, strings: readonly (string | undefined)[]): boolean;
21
+ /** Storage that a private window or a blocked site refuses: reads fall back, writes are forgotten. */
22
+ export declare function stored(storage: () => Storage, key: string): string | null;
23
+ export declare function store(storage: () => Storage, key: string, value: string | null): void;
24
+ /** An element of the page by its id; the page's own markup holds every id the viewer asks for. */
25
+ export declare function byId(id: string): HTMLElement;
26
+ /** A quiet status line in place of a container's content: loading, empty, or failed. */
27
+ export declare function notice(container: HTMLElement, text: string): void;
@@ -0,0 +1,99 @@
1
+ /** The DOM building blocks every page of the viewer shares. */
2
+ const integer = new Intl.NumberFormat();
3
+ const percentFormat = new Intl.NumberFormat(undefined, { style: 'percent', maximumFractionDigits: 1 });
4
+ /** Paths compare as people read them: numbers by value, so file10 follows file9. */
5
+ export const collator = new Intl.Collator(undefined, { numeric: true });
6
+ export function element(tag, className, text) {
7
+ const node = document.createElement(tag);
8
+ if (className)
9
+ node.className = className;
10
+ if (text)
11
+ node.textContent = text;
12
+ return node;
13
+ }
14
+ export function svgElement(tag) {
15
+ return document.createElementNS('http://www.w3.org/2000/svg', tag);
16
+ }
17
+ export function link(href, label, className) {
18
+ const result = element('a', className, label);
19
+ result.href = href;
20
+ return result;
21
+ }
22
+ /** A link that opens another site in a new tab, without handing it this page. */
23
+ export function externalLink(href, label, className) {
24
+ const result = link(href, label, className);
25
+ result.target = '_blank';
26
+ result.rel = 'noopener noreferrer';
27
+ return result;
28
+ }
29
+ /** One row of a description list, with a quieter line of context under the value. */
30
+ export function fact(label, value, context) {
31
+ const pair = element('div');
32
+ pair.append(element('dt', '', label), element('dd', '', value));
33
+ if (context)
34
+ pair.append(element('dd', 'fx-note', context));
35
+ return pair;
36
+ }
37
+ /** A table that scrolls on its own, named so the region can be found and scrolled from the keyboard. */
38
+ export function scrollableTable(table, label) {
39
+ const region = element('div', 'table-scroll fx-table-scroll');
40
+ region.setAttribute('role', 'region');
41
+ region.setAttribute('aria-label', label);
42
+ region.tabIndex = 0;
43
+ region.append(table);
44
+ return region;
45
+ }
46
+ export function count(value) {
47
+ return value == null ? '—' : integer.format(value);
48
+ }
49
+ export function percent(value) {
50
+ return percentFormat.format(value);
51
+ }
52
+ export function quantity(amount, noun) {
53
+ return `${count(amount)} ${noun}${amount === 1 ? '' : 's'}`;
54
+ }
55
+ export function parentPath(path) {
56
+ return path.slice(0, Math.max(0, path.lastIndexOf('/')));
57
+ }
58
+ export function basename(path) {
59
+ return path.slice(path.lastIndexOf('/') + 1);
60
+ }
61
+ export function inside(path, directory) {
62
+ return directory === '' || path.startsWith(`${directory}/`);
63
+ }
64
+ /** Whether any of the strings holds the lowercased query; an empty query holds everywhere. */
65
+ export function contains(query, strings) {
66
+ return query === '' || strings.some(value => value?.toLowerCase().includes(query));
67
+ }
68
+ /** Storage that a private window or a blocked site refuses: reads fall back, writes are forgotten. */
69
+ export function stored(storage, key) {
70
+ try {
71
+ return storage().getItem(key);
72
+ }
73
+ catch {
74
+ return null;
75
+ }
76
+ }
77
+ export function store(storage, key, value) {
78
+ try {
79
+ if (value === null)
80
+ storage().removeItem(key);
81
+ else
82
+ storage().setItem(key, value);
83
+ }
84
+ catch {
85
+ // Without storage the choice lasts for this page only.
86
+ }
87
+ }
88
+ /** An element of the page by its id; the page's own markup holds every id the viewer asks for. */
89
+ export function byId(id) {
90
+ return document.getElementById(id);
91
+ }
92
+ /** A quiet status line in place of a container's content: loading, empty, or failed. */
93
+ export function notice(container, text) {
94
+ const paragraph = document.createElement('p');
95
+ paragraph.className = 'detail empty';
96
+ paragraph.setAttribute('role', 'status');
97
+ paragraph.textContent = text;
98
+ container.replaceChildren(paragraph);
99
+ }
@@ -0,0 +1,19 @@
1
+ import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
2
+ import type { Directory, Metrics, Navigation } from './viewer-inspection.js';
3
+ export interface SelectionCounts {
4
+ /** Files a plugin read, and lockfiles, among the selected ones. */
5
+ readonly analysed: number;
6
+ readonly lockfiles: number;
7
+ /** How the selection reads against its folder, where a query narrowed it. */
8
+ readonly selection?: string | undefined;
9
+ }
10
+ /** The totals of a folder, or of the files a query selected in it. */
11
+ export declare function directorySummary(entry: Directory, { analysed, lockfiles, selection }: SelectionCounts): HTMLElement;
12
+ export interface SourceHooks {
13
+ /** Brings a line of the open source into view. */
14
+ readonly reveal?: (line: number) => void;
15
+ /** The loaded source text, which names anonymous functions by their first line. */
16
+ readonly text?: string;
17
+ }
18
+ /** An open file's figures, the links to what it was charged with, and its functions. */
19
+ export declare function fileDetails(details: InspectionDetails, entry: Metrics, navigation: Navigation, hooks?: SourceHooks): HTMLElement;
@@ -0,0 +1,124 @@
1
+ import { basename, count, element, fact, link, parentPath, quantity } from './viewer-dom.js';
2
+ import { coverageContext, coverageRatio, coverageText, duplicationContext, duplicationText, effortText } from './viewer-file-figures.js';
3
+ import { lockfilesLabel } from './viewer-languages.js';
4
+ import { coverageKinds, localValue, measured, measuredFileMetrics } from './viewer-inspection.js';
5
+ import { atPath } from './viewer-locations.js';
6
+ import { format } from './viewer-metric-format.js';
7
+ import { labelOf, size } from './viewer-metrics.js';
8
+ import { lineSnippet } from './viewer-source-view.js';
9
+ import { highlightCode } from './viewer-tokenizer.js';
10
+ /** A fact where the inspection took the measurement; a measurement it did not take leaves no row behind. */
11
+ function factIf(shown, label, value, context) {
12
+ return shown ? [fact(label, value, context)] : [];
13
+ }
14
+ function panel(label, title, className = 'fx-aside') {
15
+ const aside = element('aside', className);
16
+ aside.setAttribute('aria-label', label);
17
+ const heading = element('div', 'fx-aside-heading');
18
+ heading.append(element('h2', '', title));
19
+ return { panel: aside, heading };
20
+ }
21
+ /** The totals of a folder, or of the files a query selected in it. */
22
+ export function directorySummary(entry, { analysed, lockfiles, selection }) {
23
+ const { panel: aside, heading } = panel(selection ? 'Selection totals' : 'Folder totals', selection ? 'Selection' : basename(entry.path) || 'All files');
24
+ // The breadcrumbs above name the folder; only a selection needs its words here.
25
+ if (selection)
26
+ heading.append(element('p', 'fx-aside-path fx-aside-selection', selection));
27
+ const facts = element('dl', 'fx-kv');
28
+ const quality = entry.quality;
29
+ const partial = analysed !== entry.files;
30
+ facts.append(
31
+ // Every tracked file counts here; Trends counts the analysed ones, so both say which they are.
32
+ fact('Tracked files', count(entry.files)), ...factIf(partial, labelOf('files'), count(analysed)), ...factIf(lockfiles > 0, lockfilesLabel, count(lockfiles)), ...factIf(quality?.codeLines !== undefined, labelOf('code-lines'), count(quality?.codeLines)),
33
+ // Physical lines are what the language bar weighs once some files are ignored, so its total stands here too.
34
+ ...factIf(quality?.codeLines === undefined || partial, labelOf('lines'), count(entry.lines)), ...factIf(entry.bytes !== undefined, 'Size', size(entry.bytes)), ...factIf(entry.functions !== null, labelOf('functions'), count(entry.functions)), fact(labelOf('complexity'), count(entry.complexity?.maximum)), ...factIf(quality?.cognitiveComplexity !== undefined, labelOf('cognitive'), count(quality?.cognitiveComplexity)), ...factIf(quality?.duplication !== undefined, labelOf('duplication'), duplicationText(entry)), ...factIf(quality?.maintainability !== undefined, labelOf('effort'), effortText(quality?.maintainability?.effortMinutes)), ...factIf(coverageRatio(entry) !== null, labelOf('coverage'), coverageText(entry)),
35
+ // Other plugins' totals follow Repometry's own, where this inspection ran them and they roll up; the counts behind
36
+ // a ratio read through it.
37
+ ...measuredFileMetrics().filter(spec => spec.descriptor.aggregate !== 'none' && !spec.ratioPart)
38
+ .map(spec => fact(spec.short, format(spec, localValue(entry, spec)))));
39
+ aside.append(heading, facts);
40
+ return aside;
41
+ }
42
+ function fileFacts(details, entry) {
43
+ const facts = element('dl', 'fx-kv');
44
+ const quality = entry.quality;
45
+ const window = details.metrics.churnWindow;
46
+ const kinds = coverageKinds().flatMap(spec => {
47
+ const value = measured(spec.descriptor) ? localValue(entry, spec) : null;
48
+ return value === null ? [] : [fact(spec.short, format(spec, value))];
49
+ });
50
+ facts.append(...factIf(quality?.codeLines !== undefined, labelOf('code-lines'), count(quality?.codeLines)), fact(labelOf('lines'), count(entry.lines)), ...factIf(entry.bytes !== undefined, 'Size', size(entry.bytes)), ...factIf(quality?.commentLines !== undefined, labelOf('comments'), count(quality?.commentLines)), fact(labelOf('functions'), count(entry.functions)), ...factIf(Boolean(quality?.classes), labelOf('classes'), count(quality?.classes)), fact(labelOf('complexity'), count(entry.complexity?.maximum)), ...factIf(quality?.cognitiveComplexity !== undefined, labelOf('cognitive'), count(quality?.cognitiveComplexity)), fact(labelOf('coverage'), coverageText(entry), coverageContext(entry)), ...kinds, ...factIf(Boolean(quality?.duplication), labelOf('duplication'), duplicationText(entry), duplicationContext(entry)), ...factIf(Boolean(quality?.maintainability), labelOf('effort'), effortText(quality?.maintainability?.effortMinutes)), ...factIf(quality?.churn !== undefined, 'Git changes', count(quality?.churn), window ? `${count(window.lookbackDays)}-day window` : undefined));
51
+ return facts;
52
+ }
53
+ /** Links to the file's findings and diagnostics, where it has some. */
54
+ function fileLinks(details, entry, navigation) {
55
+ const findings = details.findings?.filter(item => atPath(item, entry.path)).length ?? 0;
56
+ const links = element('p', 'fx-aside-links');
57
+ if (findings)
58
+ links.append(link(navigation.href('issues', { file: entry.path }), quantity(findings, 'finding'), 'fx-inline-link'));
59
+ if (entry.diagnosticCount)
60
+ links.append(link(navigation.href('diagnostics', { file: entry.path }), quantity(entry.diagnosticCount, 'diagnostic'), 'fx-inline-link'));
61
+ return links.childElementCount ? [links] : [];
62
+ }
63
+ /** The side column has room for the functions, most complex first; a long file folds the rest away. */
64
+ function functionSection(details, path, hooks) {
65
+ const functions = details.functions.filter(record => record.path === path).sort((a, b) => b.complexity - a.complexity);
66
+ if (!functions.length)
67
+ return [];
68
+ const list = (records) => hooks.reveal ? sourceFunctionList(records, hooks.reveal, hooks.text) : functionList(records);
69
+ const section = element('section', 'fx-aside-section');
70
+ section.append(element('h3', '', 'Functions by complexity'), list(functions.slice(0, 10)));
71
+ if (functions.length > 10) {
72
+ const rest = element('details', 'fx-functions');
73
+ rest.append(element('summary', '', `${functions.length - 10} more`), list(functions.slice(10)));
74
+ section.append(rest);
75
+ }
76
+ return [section];
77
+ }
78
+ /** An open file's figures, the links to what it was charged with, and its functions. */
79
+ export function fileDetails(details, entry, navigation, hooks = {}) {
80
+ // The breadcrumbs above name the folder, so the title is the file alone.
81
+ const { panel: aside, heading } = panel('File details', basename(entry.path), 'fx-aside fx-file');
82
+ const close = link(navigation.href('metrics', { directory: parentPath(entry.path) }), '', 'fx-close');
83
+ close.setAttribute('aria-label', 'Close file details');
84
+ close.title = 'Close file details';
85
+ heading.append(close);
86
+ aside.append(heading, fileFacts(details, entry), ...fileLinks(details, entry, navigation), ...functionSection(details, entry.path, hooks));
87
+ return aside;
88
+ }
89
+ /** Functions as buttons that bring their first line into view; an anonymous one is named by that line's code. */
90
+ function sourceFunctionList(functions, reveal, text) {
91
+ const list = element('ol', 'fx-function-list fx-function-jumps');
92
+ list.append(...functions.map(record => {
93
+ const row = element('li');
94
+ const anonymous = record.name === '(anonymous)' && Boolean(text) && record.line !== null;
95
+ const snippet = anonymous ? lineSnippet(text, record.line) : null;
96
+ const button = element('button', 'fx-function-jump');
97
+ button.type = 'button';
98
+ button.disabled = record.line === null;
99
+ const name = element(snippet ? 'code' : 'span', 'fx-function-name');
100
+ if (snippet)
101
+ name.append(...highlightCode(record.path, snippet));
102
+ else
103
+ name.textContent = record.name;
104
+ button.append(name);
105
+ if (record.line !== null)
106
+ button.append(element('span', 'fx-function-line', `${record.line}`));
107
+ button.addEventListener('click', () => { if (record.line !== null)
108
+ reveal(record.line); });
109
+ row.append(button, element('strong', 'fx-function-score', count(record.complexity)));
110
+ return row;
111
+ }));
112
+ return list;
113
+ }
114
+ function functionList(functions) {
115
+ const list = element('ol', 'fx-function-list');
116
+ list.append(...functions.map(record => {
117
+ const row = element('li');
118
+ const subject = element('div');
119
+ subject.append(element('strong', '', record.line === null ? record.name : `${record.name} · line ${record.line}`));
120
+ row.append(subject, element('strong', 'fx-function-score', count(record.complexity)));
121
+ return row;
122
+ }));
123
+ return list;
124
+ }
@@ -0,0 +1,15 @@
1
+ import type { HotspotMetric, Metrics, Navigation } from './viewer-inspection.js';
2
+ /** How a file's or a folder's figures read: ratios as percentages, a dash for what was not measured. */
3
+ export declare function coverageRatio(entry: Metrics): number | null;
4
+ export declare function coverageText(entry: Metrics): string;
5
+ export declare function coverageContext(entry: Metrics): string | undefined;
6
+ export declare function duplicationRatio(entry: Metrics): number | null;
7
+ export declare function duplicationText(entry: Metrics): string;
8
+ export declare function duplicationContext(entry: Metrics): string | undefined;
9
+ /** Remediation time, or a dash where maintainability was not measured. */
10
+ export declare function effortText(minutes: number | null | undefined): string;
11
+ /** What a file scores on the metric the code map and the ranking show; null where it was not measured. */
12
+ export declare function hotspotScore(entry: Metrics, metric: HotspotMetric): number | null;
13
+ /** Orders two entries by a column, unmeasured last whichever way the column sorts, and by path between equals. */
14
+ export declare function compareEntries(a: Metrics, b: Metrics, measurement: (row: Metrics) => string | number | null, ascending: boolean): number;
15
+ export declare function fileHref(navigation: Pick<Navigation, 'href'>, file: string): string;
@@ -0,0 +1,60 @@
1
+ import { collator, count, parentPath, percent } from './viewer-dom.js';
2
+ import { localValue } from './viewer-inspection.js';
3
+ import { duration, pluginSpec } from './viewer-metrics.js';
4
+ /** How a file's or a folder's figures read: ratios as percentages, a dash for what was not measured. */
5
+ export function coverageRatio(entry) {
6
+ const coverage = entry.lineCoverage;
7
+ return coverage && coverage.total > 0 ? coverage.covered / coverage.total : null;
8
+ }
9
+ export function coverageText(entry) {
10
+ return ratioText(coverageRatio(entry));
11
+ }
12
+ export function coverageContext(entry) {
13
+ const value = entry.lineCoverage;
14
+ return value && value.total > 0 ? `${count(value.covered)} of ${count(value.total)} lines` : undefined;
15
+ }
16
+ export function duplicationRatio(entry) {
17
+ const value = entry.quality?.duplication;
18
+ return value && value.codeLines > 0 ? value.duplicatedLines / value.codeLines : null;
19
+ }
20
+ export function duplicationText(entry) {
21
+ return ratioText(duplicationRatio(entry));
22
+ }
23
+ export function duplicationContext(entry) {
24
+ const value = entry.quality?.duplication;
25
+ return value && value.codeLines > 0 ? `${count(value.duplicatedLines)} of ${count(value.codeLines)} code lines` : undefined;
26
+ }
27
+ function ratioText(value) {
28
+ return value === null ? '—' : percent(value);
29
+ }
30
+ /** Remediation time, or a dash where maintainability was not measured. */
31
+ export function effortText(minutes) {
32
+ return minutes == null ? '—' : duration(minutes);
33
+ }
34
+ const builtinScores = {
35
+ complexity: entry => entry.complexity?.maximum,
36
+ cognitive: entry => entry.quality?.cognitiveComplexity,
37
+ duplication: entry => entry.quality?.duplication?.duplicatedLines,
38
+ churn: entry => entry.quality?.churn,
39
+ missedLines: entry => entry.lineCoverage && entry.lineCoverage.total > 0 ? entry.lineCoverage.total - entry.lineCoverage.covered : null,
40
+ };
41
+ /** What a file scores on the metric the code map and the ranking show; null where it was not measured. */
42
+ export function hotspotScore(entry, metric) {
43
+ const plugin = pluginSpec(metric);
44
+ if (plugin)
45
+ return localValue(entry, plugin);
46
+ // A name that is neither a plugin's nor one of the rankings reads as uncovered lines, the last of them.
47
+ return (builtinScores[metric] ?? builtinScores.missedLines)(entry) ?? null;
48
+ }
49
+ /** Orders two entries by a column, unmeasured last whichever way the column sorts, and by path between equals. */
50
+ export function compareEntries(a, b, measurement, ascending) {
51
+ const left = measurement(a);
52
+ const right = measurement(b);
53
+ if (left === null || right === null)
54
+ return Number(left === null) - Number(right === null) || collator.compare(a.path, b.path);
55
+ const difference = typeof left === 'number' && typeof right === 'number' ? left - right : collator.compare(String(left), String(right));
56
+ return (ascending ? difference : -difference) || collator.compare(a.path, b.path);
57
+ }
58
+ export function fileHref(navigation, file) {
59
+ return navigation.href('metrics', { directory: parentPath(file), file });
60
+ }
@@ -0,0 +1,7 @@
1
+ import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
2
+ import type { Metrics, Navigation } from './viewer-inspection.js';
3
+ /**
4
+ * An open file: its source with the inspection laid on its lines, and its figures and functions beside it. The
5
+ * functions lead into the code, and a chosen line goes into the URL so the place can be shared.
6
+ */
7
+ export declare function fileView(details: InspectionDetails, navigation: Navigation, file: Metrics, load: (path: string) => Promise<string | null>): HTMLElement;
@@ -0,0 +1,119 @@
1
+ import { segmented } from './viewer-controls.js';
2
+ import { copyPathButton } from './viewer-copy.js';
3
+ import { basename, count, element, externalLink, parentPath, store, stored } from './viewer-dom.js';
4
+ import { fileDetails } from './viewer-file-aside.js';
5
+ import { languageColor, languageOf } from './viewer-languages.js';
6
+ import { breadcrumbs, splitter } from './viewer-layout.js';
7
+ import { lineIn } from './viewer-locations.js';
8
+ import { isSourceLayer, lineReadings, setSourceLayer } from './viewer-line-coverage.js';
9
+ import { renderSource } from './viewer-source-view.js';
10
+ /** A file's line coverage, where the inspection's coverage report names the file. */
11
+ function fileCoverage(details, path) {
12
+ const coverage = details.lineCoverage;
13
+ return coverage && Object.hasOwn(coverage, path) ? coverage[path] : undefined;
14
+ }
15
+ const layerKey = 'repometry.source-layer';
16
+ /** The URL's choice of what lines show, else the one made earlier in this session, else the findings. */
17
+ function sourceLayer(requested) {
18
+ if (isSourceLayer(requested))
19
+ return requested;
20
+ const remembered = stored(() => sessionStorage, layerKey);
21
+ return isSourceLayer(remembered) ? remembered : 'issues';
22
+ }
23
+ /** The file's name with its full path a click away; a refused clipboard shows the path in the name's place, selected. */
24
+ function sourceName(path) {
25
+ // The folder is in the breadcrumbs right above; the head names the file alone, with its full path on hover.
26
+ const name = element('code', 'fx-source-path', basename(path));
27
+ name.title = path;
28
+ const named = element('span', 'fx-source-name');
29
+ named.append(name, copyPathButton(path, () => {
30
+ name.textContent = path;
31
+ return name;
32
+ }));
33
+ return named;
34
+ }
35
+ function sourceMeta(file) {
36
+ const language = languageOf(file.path);
37
+ const dot = element('span', 'fx-language-dot');
38
+ dot.style.background = languageColor(language);
39
+ const meta = element('span', 'fx-source-meta');
40
+ meta.append(dot, `${language} · ${count(file.lines)} lines`);
41
+ return meta;
42
+ }
43
+ /** The findings that mark the file's lines, at their place in it. */
44
+ function sourceNotes(details, path) {
45
+ return (details.findings ?? []).flatMap(finding => {
46
+ const line = lineIn(finding, path);
47
+ return line ? [{ line, level: finding.level, title: finding.rule, message: finding.message }] : [];
48
+ });
49
+ }
50
+ /**
51
+ * An open file: its source with the inspection laid on its lines, and its figures and functions beside it. The
52
+ * functions lead into the code, and a chosen line goes into the URL so the place can be shared.
53
+ */
54
+ export function fileView(details, navigation, file, load) {
55
+ const view = element('div', 'fx-view');
56
+ const keep = { query: navigation.query ?? '', group: navigation.group ?? '' };
57
+ const nav = { ...navigation,
58
+ href: (target, options) => target === 'metrics' ? navigation.href('metrics', { ...keep, ...options }) : navigation.href(target, options) };
59
+ view.append(breadcrumbs('metrics', nav, parentPath(file.path)));
60
+ const split = element('div', 'fx-split fx-split-source');
61
+ const main = element('section', 'fx-source panel');
62
+ main.setAttribute('aria-label', 'Source');
63
+ const head = element('div', 'fx-source-head');
64
+ const meta = sourceMeta(file);
65
+ // Lines show the findings, or the tests' coverage where the file has it; without coverage the head stays as it was.
66
+ const coverage = fileCoverage(details, file.path);
67
+ let layer = coverage ? sourceLayer(navigation.layer) : 'issues';
68
+ let line = navigation.line;
69
+ const place = () => nav.href('metrics', { directory: parentPath(file.path), file: file.path, ...line ? { line } : {},
70
+ ...layer === 'coverage' ? { layer } : {} });
71
+ const body = element('div', 'fx-source-body');
72
+ const toggle = coverage ? segmented('Lines show', [['issues', 'Issues'], ['coverage', 'Coverage']], layer, value => {
73
+ layer = value;
74
+ store(() => sessionStorage, layerKey, layer);
75
+ setSourceLayer(body, layer);
76
+ history.replaceState(history.state, '', place());
77
+ }) : null;
78
+ toggle?.classList.add('fx-source-layer');
79
+ const tools = element('div', 'fx-source-tools');
80
+ tools.append(...toggle ? [toggle] : [], meta);
81
+ head.append(sourceName(file.path), tools);
82
+ // The forge's page for the file, at the chosen line, whether or not the text opens here.
83
+ const page = navigation.sourcePage?.(file.path, navigation.line);
84
+ const forge = page ? externalLink(page.href, `View on ${page.provider}`, 'fx-source-forge') : null;
85
+ if (forge)
86
+ meta.append(' · ', forge);
87
+ body.append(element('p', 'fx-note fx-source-wait', 'Loading source…'));
88
+ main.append(head, body);
89
+ let aside = fileDetails(details, file, nav);
90
+ split.append(main, splitter(split), aside);
91
+ view.append(split);
92
+ const functions = details.functions.filter(record => record.path === file.path);
93
+ const choose = (chosen) => {
94
+ line = chosen;
95
+ history.replaceState(history.state, '', place());
96
+ const moved = navigation.sourcePage?.(file.path, chosen);
97
+ if (forge && moved)
98
+ forge.href = moved.href;
99
+ };
100
+ void load(file.path).then(text => {
101
+ if (text === null) {
102
+ // No locator, a private repository, a commit never pushed: one quiet state, and the forge's page when there is one.
103
+ body.replaceChildren(element('p', 'fx-source-missing', 'Source not available'));
104
+ // Nothing to shade: the head is the one a file without coverage has.
105
+ toggle?.remove();
106
+ return;
107
+ }
108
+ const reveal = renderSource(body, text, {
109
+ path: file.path,
110
+ functions: functions.flatMap(record => record.line === null ? [] : [{ line: record.line, complexity: record.complexity, name: record.name }]),
111
+ notes: sourceNotes(details, file.path), line: navigation.line, choose,
112
+ coverage: coverage && lineReadings(coverage), layer,
113
+ });
114
+ const next = fileDetails(details, file, nav, { text, reveal: target => { reveal(target); choose(target); } });
115
+ aside.replaceWith(next);
116
+ aside = next;
117
+ });
118
+ return view;
119
+ }