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,162 @@
1
+ import { columnMenu, tableColumns } from './viewer-columns.js';
2
+ import { navigationButtons, pressSegment, segmented } from './viewer-controls.js';
3
+ import { count, element, inside, scrollableTable } from './viewer-dom.js';
4
+ import { directorySummary, fileDetails } from './viewer-file-aside.js';
5
+ import { formatQuery, matches, parseQuery } from './viewer-filter.js';
6
+ import { pageSize } from './viewer-inspection.js';
7
+ import { renderLanguages } from './viewer-language-bar.js';
8
+ import { isLockfile } from './viewer-languages.js';
9
+ import { breadcrumbs, splitter } from './viewer-layout.js';
10
+ import { findingIndex } from './viewer-locations.js';
11
+ import { labelOf } from './viewer-metrics.js';
12
+ import { queryField } from './viewer-query-field.js';
13
+ import { suggest } from './viewer-suggest.js';
14
+ import { markSort, metricsRow, sortableTable, unreadRow } from './viewer-table-cells.js';
15
+ import { componentRows, entryRange, filteredFolderRows, folderRows, foldUnread, isGroup, listSummary, notInComponent, sortRows } from './viewer-table-rows.js';
16
+ import { aggregate, componentIndex, unreadFolders } from './viewer-totals.js';
17
+ const groupChoices = [['folders', 'Folders'], ['files', 'Files'], ['components', 'Components']];
18
+ function tableNote(columns) {
19
+ const effort = labelOf('effort');
20
+ return 'A dash marks an unavailable measurement. Totals include measured files.'
21
+ + (columns.some(column => column.label === effort) ? ` ${effort} is assigned to each finding’s primary file.` : '');
22
+ }
23
+ function componentHint(hint) {
24
+ hint.hidden = false;
25
+ hint.replaceChildren('No components are defined for this repository. Group paths into components in ', element('code', '', '.repometry/components.json'), ' to compare them here.');
26
+ }
27
+ /** The Metrics page: a query, a grouping and columns over the folder's files, their languages, and the totals beside. */
28
+ export function metricsView(details, navigation, settings, directory, selectedFile) {
29
+ const view = element('div', 'fx-view');
30
+ const { metrics } = details;
31
+ const columns = tableColumns();
32
+ const scopeFiles = metrics.files.filter(entry => inside(entry.path, directory));
33
+ const components = details.components ?? [];
34
+ const facts = { components: componentIndex(components), findings: findingIndex(details.findings ?? []) };
35
+ const state = {
36
+ clauses: parseQuery(navigation.query ?? ''), text: '', page: 0,
37
+ group: isGroup(navigation.group) ? navigation.group : settings.mode === 'tree' ? 'folders' : 'files',
38
+ };
39
+ // Every link out of the view carries the query and the grouping, so a file opened from a selection keeps it.
40
+ const linkTo = (options = {}) => navigation.href('metrics', { ...options, query: formatQuery(state.clauses), group: state.group });
41
+ const trail = element('div');
42
+ view.append(trail);
43
+ const split = element('div', 'fx-split');
44
+ const main = element('div', 'fx-main');
45
+ split.append(main, splitter(split));
46
+ view.append(split);
47
+ const restart = () => {
48
+ state.page = 0;
49
+ remember();
50
+ refresh();
51
+ };
52
+ const field = queryField(state.clauses, {
53
+ suggestions: typed => suggest(typed, scopeFiles, facts, state.clauses),
54
+ change: (next, typed) => {
55
+ state.clauses = next;
56
+ state.text = typed;
57
+ restart();
58
+ },
59
+ });
60
+ const grouping = segmented('Group by', groupChoices, state.group, value => {
61
+ state.group = value;
62
+ settings.mode = state.group === 'folders' ? 'tree' : 'list';
63
+ restart();
64
+ });
65
+ const resort = () => {
66
+ state.page = 0;
67
+ refresh();
68
+ };
69
+ const { menu, isVisible } = columnMenu(columns, settings, { totals: aggregate(directory, scopeFiles), files: scopeFiles }, resort);
70
+ const tools = element('div', 'fx-tools fx-metrics-tools');
71
+ tools.append(field.element, grouping, menu);
72
+ const languages = element('div', 'fx-languages');
73
+ const hint = element('p', 'fx-hint');
74
+ hint.hidden = true;
75
+ const result = element('p', 'fx-note fx-results');
76
+ result.setAttribute('aria-live', 'polite');
77
+ const table = sortableTable(columns, settings, resort);
78
+ const pages = navigationButtons('File pages', () => { state.page--; refresh(); }, () => { state.page++; refresh(); });
79
+ // The count of what the list holds stands with the page buttons, under the table it counts.
80
+ const pager = element('div', 'fx-pager');
81
+ pager.append(result, pages.section);
82
+ const tableWrap = scrollableTable(table.table, 'File and directory metrics');
83
+ const note = element('p', 'fx-note');
84
+ main.append(tools, languages, hint, tableWrap, pager, note);
85
+ let aside = element('aside');
86
+ split.append(aside);
87
+ /** The URL follows the query, without a new history entry per keystroke. */
88
+ function remember() {
89
+ history.replaceState(history.state, '', navigation.href('metrics', {
90
+ directory, ...(selectedFile ? { file: selectedFile.path } : {}), query: formatQuery(state.clauses), group: state.group
91
+ }));
92
+ }
93
+ function selected(...except) {
94
+ const kept = state.clauses.filter(clause => !except.includes(clause.kind));
95
+ return scopeFiles.filter(entry => matches(entry, kept, facts, state.text));
96
+ }
97
+ function groupedRows(files, filtering) {
98
+ hint.hidden = true;
99
+ if (state.group === 'files')
100
+ return files.map(entry => ({ entry, kind: 'file' }));
101
+ if (state.group === 'folders')
102
+ return filtering ? filteredFolderRows(files, directory) : folderRows(metrics.directories, files, directory);
103
+ if (components.length)
104
+ return componentRows(components, files, filtering);
105
+ componentHint(hint);
106
+ return [];
107
+ }
108
+ /** A component's name opens its files as a list, filtered by it. */
109
+ function opener(row) {
110
+ if (row.kind !== 'component' || row.entry.path === notInComponent)
111
+ return undefined;
112
+ return () => {
113
+ state.group = 'files';
114
+ settings.mode = 'list';
115
+ pressSegment(grouping, 'Files');
116
+ field.set([...state.clauses.filter(clause => clause.kind !== 'component'), { kind: 'component', value: row.entry.path }]);
117
+ };
118
+ }
119
+ function toggleFold() {
120
+ settings.unanalysed = !settings.unanalysed;
121
+ refresh();
122
+ }
123
+ /** Only the side panel is swapped: moving the list column would take focus out of the query field. */
124
+ function showAside(files, filtering) {
125
+ const next = selectedFile
126
+ ? fileDetails(details, selectedFile, { ...navigation, href: (target, options) => target === 'metrics' ? linkTo(options) : navigation.href(target, options) })
127
+ : directorySummary(aggregate(directory, files), { analysed: files.filter(entry => entry.analysed !== false).length,
128
+ lockfiles: files.filter(entry => isLockfile(entry.path)).length,
129
+ selection: filtering ? `${count(files.length)} of ${count(scopeFiles.length)} files selected` : undefined });
130
+ aside.replaceWith(next);
131
+ aside = next;
132
+ }
133
+ function refresh() {
134
+ const files = selected();
135
+ const filtering = state.clauses.length > 0 || state.text !== '';
136
+ trail.replaceChildren(breadcrumbs('metrics', { href: (_, options) => linkTo(options) }, directory));
137
+ renderLanguages(languages, selected('lang', 'analysed'), state.clauses, next => field.set(next));
138
+ const sort = columns[settings.sort] ?? columns[0];
139
+ const rows = sortRows(groupedRows(files, filtering), settings.sort === 0, sort.value, settings.ascending);
140
+ markSort(table.headers, isVisible, settings);
141
+ table.headers[0].querySelector('button').textContent = state.group === 'components' ? 'Component' : 'Path';
142
+ const keep = state.clauses.some(clause => clause.kind === 'analysed' || clause.kind === 'lockfile');
143
+ const { display, folded } = foldUnread(rows, unreadFolders(scopeFiles), keep, settings.unanalysed);
144
+ const first = state.page * pageSize;
145
+ const visible = display.slice(first, first + pageSize);
146
+ const visibleColumns = columns.slice(1).filter((_, index) => isVisible(index + 1));
147
+ const context = { group: state.group, columns: visibleColumns, linkTo, selected: selectedFile?.path };
148
+ table.body.replaceChildren(...visible.map(row => row.kind === 'unread'
149
+ ? unreadRow(folded, visibleColumns.length + 1, settings.unanalysed, toggleFold) : metricsRow(row, context, opener(row))));
150
+ result.textContent = listSummary(state.group, { rows: rows.length, display: display.length, files: files.length, scope: scopeFiles.length,
151
+ range: entryRange(display, first, visible.length) }, filtering, !hint.hidden);
152
+ tableWrap.hidden = rows.length === 0;
153
+ pager.hidden = !result.textContent;
154
+ pages.section.hidden = display.length <= pageSize;
155
+ pages.update(state.page, Math.ceil(display.length / pageSize));
156
+ note.hidden = rows.length === 0;
157
+ note.textContent = tableNote(visibleColumns);
158
+ showAside(files, filtering);
159
+ }
160
+ refresh();
161
+ return view;
162
+ }
@@ -2,6 +2,7 @@ import type { InspectionContext } from '../../json/wire/inspection-context-model
2
2
  import type { QualitySummary } from '../../json/wire/domain-types.js';
3
3
  import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
4
4
  import type { MetricDescriptor } from '../../json/wire/summary-model.js';
5
+ import * as metricFormat from './viewer-metric-format.js';
5
6
  import type { MetricSpec } from './viewer-metric-registry.js';
6
7
  export type BuiltinMetric = 'coverage' | 'lines' | 'files' | 'functions' | 'complexity' | 'cognitive' | 'duplication' | 'debt' | 'effort' | 'smells' | 'code-lines' | 'classes' | 'comments' | 'security' | 'coverable-lines' | 'covered-lines' | 'uncovered-lines' | 'security-high' | 'security-medium' | 'security-low';
7
8
  /** Another plugin's metric, by the key the registry gives it. */
@@ -18,6 +19,8 @@ export declare const metricLabels: Record<BuiltinMetric, string>;
18
19
  */
19
20
  export declare const securityGrades: readonly ['A', 'B', 'C', 'D', 'F'];
20
21
  export declare const securityRisks: readonly ['No findings', 'Low risk', 'Medium risk', 'High risk', 'Critical risk'];
22
+ /** Line coverage as a letter, coloured as the coverage badge colours it. */
23
+ export declare function coverageGrade(ratio: number): (typeof securityGrades)[number];
21
24
  export declare const metricDefinitions: Record<BuiltinMetric, string>;
22
25
  export declare function useCatalog(catalog: readonly MetricDescriptor[] | undefined): void;
23
26
  /** A detail's own catalog may name metrics the history does not, as when its inspection is newer than the summary. */
@@ -29,13 +32,15 @@ export declare function labelOf(metric: Metric): string;
29
32
  export declare function definitionOf(metric: Metric): string;
30
33
  /** Which way is better: the green and red of changes and the flags on a chart follow it. */
31
34
  export declare function betterOf(metric: Metric): 'lower' | 'higher' | 'none';
35
+ /** A metric's value at a commit; null where the commit has no such measurement. */
32
36
  export declare function metricValue(report: PublicHistoryEntry, metric: Metric, quality: QualitySummary | undefined, context?: InspectionContext): number | null;
33
37
  export declare function isPercent(metric: Metric): boolean;
34
38
  export declare function formatMetric(value: number, metric: Metric): string;
35
39
  /** A size in bytes, in binary units named the way code hosts name them: 512 B, 4.8 KB, 340 KB, 1.2 MB. */
36
40
  export declare function size(bytes: number | null | undefined): string;
37
41
  export declare function count(value: number | null): string;
38
- export declare function duration(minutes: number): string;
42
+ /** Remediation time in hours and minutes: 45 min, 2 h, 3 h 20 min. */
43
+ export declare const duration: typeof metricFormat.duration;
39
44
  export type Direction = 'better' | 'worse' | 'same' | 'neutral';
40
45
  /** Signed change between two values of one metric, in percentage points for ratios. */
41
46
  export declare function difference(value: number, before: number, metric: Metric): {
@@ -1,3 +1,4 @@
1
+ import * as metricFormat from './viewer-metric-format.js';
1
2
  import * as registry from './viewer-metric-registry.js';
2
3
  /** One name per metric, for every page: Trends, the Overview figures, the Metrics and Issues summaries and columns. */
3
4
  export const metricLabels = {
@@ -15,6 +16,12 @@ export const metricLabels = {
15
16
  */
16
17
  export const securityGrades = ['A', 'B', 'C', 'D', 'F'];
17
18
  export const securityRisks = ['No findings', 'Low risk', 'Medium risk', 'High risk', 'Critical risk'];
19
+ /** The lowest line coverage of each grade, in the steps of the coverage badge: A from 90%, F below 60%. */
20
+ const coverageSteps = [[.9, 'A'], [.8, 'B'], [.7, 'C'], [.6, 'D']];
21
+ /** Line coverage as a letter, coloured as the coverage badge colours it. */
22
+ export function coverageGrade(ratio) {
23
+ return coverageSteps.find(([lowest]) => ratio >= lowest)?.[1] ?? 'F';
24
+ }
18
25
  export const metricDefinitions = {
19
26
  coverage: 'Share of measured lines executed by tests, read from LCOV.',
20
27
  lines: 'All lines in inspected source files, including blanks and comments.',
@@ -87,32 +94,38 @@ export function betterOf(metric) {
87
94
  return spec.descriptor.better;
88
95
  return lowerIsBetter.has(metric) ? 'lower' : metric === 'coverage' ? 'higher' : 'none';
89
96
  }
97
+ function securityTotal(context) {
98
+ return context?.security ? Object.values(context.security).reduce((total, value) => total + value, 0) : null;
99
+ }
100
+ /** Where each of Repometry's own metrics is read: the history entry, its quality summary, or its scanner context. */
101
+ const readers = {
102
+ coverage: report => report.lineCoverage && report.lineCoverage.total > 0 ? report.lineCoverage.covered / report.lineCoverage.total : null,
103
+ lines: report => report.lines,
104
+ files: report => report.files,
105
+ functions: report => report.functions,
106
+ complexity: report => report.maxComplexity,
107
+ cognitive: (_, quality) => quality?.cognitiveComplexity,
108
+ duplication: (_, quality) => quality?.duplication?.ratio,
109
+ debt: (_, quality) => quality?.maintainability?.debtRatio,
110
+ effort: (_, quality) => quality?.maintainability?.effortMinutes,
111
+ smells: (_, quality) => quality?.maintainability?.smells,
112
+ 'code-lines': (_, quality) => quality?.codeLines,
113
+ classes: (_, quality) => quality?.classes,
114
+ comments: (_, quality) => quality?.comments,
115
+ security: (_, __, context) => securityTotal(context),
116
+ 'coverable-lines': report => report.lineCoverage?.total,
117
+ 'covered-lines': report => report.lineCoverage?.covered,
118
+ 'uncovered-lines': report => report.lineCoverage ? report.lineCoverage.total - report.lineCoverage.covered : null,
119
+ 'security-high': (_, __, context) => context?.security?.high,
120
+ 'security-medium': (_, __, context) => context?.security?.medium,
121
+ 'security-low': (_, __, context) => context?.security?.low,
122
+ };
123
+ /** A metric's value at a commit; null where the commit has no such measurement. */
90
124
  export function metricValue(report, metric, quality, context) {
91
125
  const spec = pluginSpec(metric);
92
126
  if (spec)
93
127
  return registry.commitValue(historyIndex, report, spec);
94
- switch (metric) {
95
- case 'coverage': return report.lineCoverage && report.lineCoverage.total > 0 ? report.lineCoverage.covered / report.lineCoverage.total : null;
96
- case 'lines': return report.lines;
97
- case 'files': return report.files;
98
- case 'functions': return report.functions;
99
- case 'complexity': return report.maxComplexity;
100
- case 'cognitive': return quality?.cognitiveComplexity ?? null;
101
- case 'duplication': return quality?.duplication?.ratio ?? null;
102
- case 'debt': return quality?.maintainability?.debtRatio ?? null;
103
- case 'effort': return quality?.maintainability?.effortMinutes ?? null;
104
- case 'smells': return quality?.maintainability?.smells ?? null;
105
- case 'code-lines': return quality?.codeLines ?? null;
106
- case 'classes': return quality?.classes ?? null;
107
- case 'comments': return quality?.comments ?? null;
108
- case 'security': return context?.security ? Object.values(context.security).reduce((total, value) => total + value, 0) : null;
109
- case 'coverable-lines': return report.lineCoverage?.total ?? null;
110
- case 'covered-lines': return report.lineCoverage?.covered ?? null;
111
- case 'uncovered-lines': return report.lineCoverage ? report.lineCoverage.total - report.lineCoverage.covered : null;
112
- case 'security-high': return context?.security?.high ?? null;
113
- case 'security-medium': return context?.security?.medium ?? null;
114
- case 'security-low': return context?.security?.low ?? null;
115
- }
128
+ return readers[metric]?.(report, quality, context) ?? null;
116
129
  }
117
130
  export function isPercent(metric) {
118
131
  const spec = pluginSpec(metric);
@@ -123,7 +136,7 @@ export function isPercent(metric) {
123
136
  export function formatMetric(value, metric) {
124
137
  const spec = pluginSpec(metric);
125
138
  if (spec)
126
- return registry.format(spec, value);
139
+ return metricFormat.format(spec, value);
127
140
  if (isPercent(metric))
128
141
  return percent.format(value);
129
142
  return metric === 'effort' ? duration(value) : count(value);
@@ -148,25 +161,30 @@ export function size(bytes) {
148
161
  export function count(value) {
149
162
  return value === null ? '—' : integers.format(value);
150
163
  }
151
- export function duration(minutes) {
152
- const rounded = Math.round(minutes);
153
- if (rounded < 60)
154
- return `${count(rounded)} min`;
155
- const hours = Math.floor(rounded / 60);
156
- const rest = rounded % 60;
157
- return rest ? `${count(hours)} h ${count(rest)} min` : `${count(hours)} h`;
158
- }
164
+ /** Remediation time in hours and minutes: 45 min, 2 h, 3 h 20 min. */
165
+ export const duration = metricFormat.duration;
159
166
  /** Signed change between two values of one metric, in percentage points for ratios. */
160
167
  export function difference(value, before, metric) {
161
168
  const spec = pluginSpec(metric);
162
169
  if (spec)
163
- return registry.difference(spec, value, before);
170
+ return metricFormat.difference(spec, value, before);
164
171
  const percentPoints = isPercent(metric);
165
172
  const raw = percentPoints ? (value - before) * 100 : value - before;
166
173
  const rounded = percentPoints ? Math.round(raw * 10) / 10 : Math.round(raw);
167
174
  if (rounded === 0)
168
175
  return { text: 'No change', direction: 'same' };
169
- const magnitude = percentPoints ? `${decimal.format(Math.abs(rounded))} pp` : metric === 'effort' ? duration(Math.abs(rounded)) : count(Math.abs(rounded));
170
- const better = lowerIsBetter.has(metric) ? rounded < 0 : metric === 'coverage' ? rounded > 0 : null;
171
- return { text: `${rounded > 0 ? '+' : '−'}${magnitude}`, direction: better === null ? 'neutral' : better ? 'better' : 'worse' };
176
+ return { text: `${rounded > 0 ? '+' : '−'}${magnitudeText(metric, Math.abs(rounded), percentPoints)}`, direction: changeDirection(metric, rounded) };
177
+ }
178
+ function magnitudeText(metric, magnitude, percentPoints) {
179
+ if (percentPoints)
180
+ return `${decimal.format(magnitude)} pp`;
181
+ return metric === 'effort' ? duration(magnitude) : count(magnitude);
182
+ }
183
+ /** Whether a change is good news: down for what is better lower, up for coverage; other metrics are neutral. */
184
+ function changeDirection(metric, change) {
185
+ if (lowerIsBetter.has(metric))
186
+ return change < 0 ? 'better' : 'worse';
187
+ if (metric !== 'coverage')
188
+ return 'neutral';
189
+ return change > 0 ? 'better' : 'worse';
172
190
  }
@@ -0,0 +1,12 @@
1
+ import type { InspectionContext } from '../../json/wire/inspection-context-model.js';
2
+ import type { QualitySummary } from '../../json/wire/domain-types.js';
3
+ import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
4
+ /** A detail that counts something leads to exactly what it counts, where the report has a page for it. */
5
+ export declare function detailText(id: string, text: string, link?: string): void;
6
+ /** Where each Overview figure leads: the findings it counts, the files it ranks, the function it names. */
7
+ export declare function smellsLink(sha: string): string;
8
+ export declare function securityLink(sha: string, level?: string): string;
9
+ export declare function uncoveredLink(sha: string): string;
10
+ export declare function renderInspection(report: PublicHistoryEntry): void;
11
+ export declare function renderQuality(report: PublicHistoryEntry, quality: QualitySummary | undefined): void;
12
+ export declare function renderScannerContext(context: InspectionContext | undefined, sha: string): void;
@@ -0,0 +1,118 @@
1
+ import { byId, count, percent, quantity } from './viewer-dom.js';
2
+ import { codeSmellCategories, securityCategories } from './viewer-files.js';
3
+ import { coverageGrade, formatMetric, metricValue, pluginSpec, securityGrades, securityRisks } from './viewer-metrics.js';
4
+ import { href } from './viewer-route.js';
5
+ /** Coverage kinds beyond lines, by their registry keys, in the words the Overview card uses for them. */
6
+ const coverageKinds = [['branch-coverage', 'Branches'], ['function-coverage', 'Functions']];
7
+ /** A detail that counts something leads to exactly what it counts, where the report has a page for it. */
8
+ export function detailText(id, text, link) {
9
+ if (link === undefined) {
10
+ byId(id).textContent = text;
11
+ return;
12
+ }
13
+ const anchor = document.createElement('a');
14
+ anchor.href = link;
15
+ anchor.textContent = text;
16
+ byId(id).replaceChildren(anchor);
17
+ }
18
+ /** Where each Overview figure leads: the findings it counts, the files it ranks, the function it names. */
19
+ export function smellsLink(sha) {
20
+ return href({ page: 'issues', sha, category: codeSmellCategories.join(',') });
21
+ }
22
+ export function securityLink(sha, level) {
23
+ return href({ page: 'issues', sha, category: securityCategories.join(','), ...level ? { level } : {} });
24
+ }
25
+ export function uncoveredLink(sha) {
26
+ return href({ page: 'hotspots', sha, rank: 'missedLines' });
27
+ }
28
+ /** A small progress ring for a ratio; an empty ring when there is no value. */
29
+ function ring(ratio) {
30
+ const namespace = 'http://www.w3.org/2000/svg';
31
+ const svg = document.createElementNS(namespace, 'svg');
32
+ svg.setAttribute('viewBox', '0 0 40 40');
33
+ const track = document.createElementNS(namespace, 'circle');
34
+ const arc = document.createElementNS(namespace, 'circle');
35
+ for (const circle of [track, arc]) {
36
+ circle.setAttribute('cx', '20');
37
+ circle.setAttribute('cy', '20');
38
+ circle.setAttribute('r', '16');
39
+ }
40
+ track.setAttribute('class', 'ring-track');
41
+ arc.setAttribute('class', 'ring-arc');
42
+ const length = 2 * Math.PI * 16;
43
+ arc.setAttribute('stroke-dasharray', `${(ratio ?? 0) * length} ${length}`);
44
+ // Flat ends keep the gap true to the value: a round cap would close 95.9% into a full circle and turn
45
+ // a zero into a dot. An unknown or zero ratio shows the track alone.
46
+ svg.append(...(ratio !== null && ratio > 0 ? [track, arc] : [track]));
47
+ return svg;
48
+ }
49
+ /** Line coverage leads; the other kinds the coverage report carries follow on a quieter line. */
50
+ function renderCoverageKinds(report) {
51
+ const kinds = coverageKinds.flatMap(([key, name]) => {
52
+ const metric = key;
53
+ const value = pluginSpec(metric) ? metricValue(report, metric, undefined) : null;
54
+ if (value === null)
55
+ return [];
56
+ // Each kind keeps its number; a narrow card wraps between kinds, never inside one.
57
+ const kind = document.createElement('span');
58
+ kind.textContent = `${name} ${formatMetric(value, metric)}`;
59
+ return [kind];
60
+ });
61
+ byId('coverage-kinds').replaceChildren(...kinds.flatMap((kind, index) => index ? [' · ', kind] : [kind]));
62
+ byId('coverage-kinds').hidden = kinds.length === 0;
63
+ }
64
+ export function renderInspection(report) {
65
+ const lines = report.lineCoverage;
66
+ const coverage = lines && lines.total > 0 ? lines.covered / lines.total : null;
67
+ if (coverage === null)
68
+ detailText('coverage-detail', 'No coverage report');
69
+ else
70
+ detailText('coverage-detail', `${percent(coverage)} of ${count(lines.total)} lines`, coverage < 1 ? uncoveredLink(report.sha) : undefined);
71
+ const mark = byId('coverage-mark');
72
+ mark.replaceChildren(ring(coverage));
73
+ // The ring is coloured by the grade the coverage badge gives it.
74
+ if (coverage === null)
75
+ delete mark.dataset.grade;
76
+ else
77
+ mark.dataset.grade = coverageGrade(coverage);
78
+ renderCoverageKinds(report);
79
+ }
80
+ export function renderQuality(report, quality) {
81
+ const maintainability = quality?.maintainability ?? null;
82
+ const grade = byId('maintainability');
83
+ grade.textContent = maintainability?.grade ?? '–';
84
+ grade.dataset.grade = maintainability?.grade ?? 'none';
85
+ if (!maintainability)
86
+ detailText('maintainability-detail', 'Not measured');
87
+ else
88
+ detailText('maintainability-detail', quantity(maintainability.smells, 'code smell'), maintainability.smells > 0 ? smellsLink(report.sha) : undefined);
89
+ }
90
+ /** The words of the five steps, as every grade has them: clear A, low B, medium C, high D, critical F. */
91
+ const severities = ['clear', 'low', 'medium', 'high', 'critical'];
92
+ /** A grade like maintainability's, by the worst finding: 4 critical, 3 high, 2 medium, 1 anything else, 0 none. */
93
+ function securityStep(security) {
94
+ const worst = [security.critical ?? 0, security.high, security.medium].findIndex(amount => amount > 0);
95
+ if (worst >= 0)
96
+ return 4 - worst;
97
+ return security.low + security.unknown > 0 ? 1 : 0;
98
+ }
99
+ function securityText(security) {
100
+ if (!security)
101
+ return { text: 'No scanner report', counted: false };
102
+ const levels = [['critical', security.critical ?? 0], ['high', security.high], ['medium', security.medium], ['low', security.low],
103
+ ['unclassified', security.unknown]].filter(([, amount]) => amount > 0);
104
+ if (levels.length === 0)
105
+ return { text: 'No findings', counted: false };
106
+ return { text: levels.map(([name, amount]) => `${count(amount)} ${name}`).join(' · '), counted: true };
107
+ }
108
+ export function renderScannerContext(context, sha) {
109
+ const security = context?.security;
110
+ const mark = byId('security-mark');
111
+ const step = security ? securityStep(security) : null;
112
+ mark.textContent = step === null ? '–' : securityGrades[step];
113
+ mark.title = step === null ? '' : `Security ${securityGrades[step]}: ${securityRisks[step].toLowerCase()}`;
114
+ mark.dataset.severity = step === null ? 'none' : severities[step];
115
+ // The mark carries the level; the text gives the counts by severity.
116
+ const { text, counted } = securityText(security);
117
+ detailText('security-detail', text, counted ? securityLink(sha) : undefined);
118
+ }
@@ -0,0 +1,9 @@
1
+ import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
2
+ import type { BuiltinMetric } from './viewer-metrics.js';
3
+ /** The Overview's hotspot column for the selected quality area: the compact map and the top five files. */
4
+ export declare function renderOverviewHotspots(details: InspectionDetails, sha: string, area: BuiltinMetric, scanned: boolean): void;
5
+ /**
6
+ * The hotspot column while the inspection loads. A map and ranking already on screen stay, dimmed, until the next ones
7
+ * replace them; on a first visit placeholders of the same size hold the column, so nothing beside it moves.
8
+ */
9
+ export declare function overviewStub(sha: string): void;
@@ -0,0 +1,173 @@
1
+ import { renderSunburst } from './viewer-code-map.js';
2
+ import { byId, count, notice, parentPath, quantity } from './viewer-dom.js';
3
+ import { hotspotScore } from './viewer-file-figures.js';
4
+ import { securityCategories } from './viewer-files.js';
5
+ import { band, bandLimits } from './viewer-map-scale.js';
6
+ import { mapStub } from './viewer-map-shape.js';
7
+ import { securityGrades, securityRisks } from './viewer-metrics.js';
8
+ import { href } from './viewer-route.js';
9
+ const titles = {
10
+ complexity: 'Maintainability hotspots',
11
+ cognitive: 'Cognitive complexity hotspots',
12
+ duplication: 'Duplication hotspots',
13
+ missedLines: 'Coverage hotspots',
14
+ };
15
+ /** What the Overview ranks for each quality area: coverage by uncovered lines, the rest by complexity. */
16
+ function hotspotOf(area) {
17
+ if (area === 'coverage')
18
+ return 'missedLines';
19
+ return area === 'cognitive' || area === 'duplication' ? area : 'complexity';
20
+ }
21
+ /** The ranking's heading and link show only when there is something to rank. */
22
+ function listHeading(visible) {
23
+ byId('overview-hotspots-title').parentElement.hidden = !visible;
24
+ }
25
+ /** Nothing measured: the grey map stands alone; the quality area's tab already says what is missing. */
26
+ function unranked() {
27
+ listHeading(false);
28
+ byId('overview-hotspot-list').replaceChildren();
29
+ }
30
+ function allLink(target, visible) {
31
+ const all = document.querySelector('#all-hotspots');
32
+ all.href = target;
33
+ all.hidden = !visible;
34
+ }
35
+ /** The compact map, drawn again in place when its shape changes. */
36
+ function overviewMap(details, sha, options) {
37
+ const chart = byId('overview-sunburst');
38
+ const map = () => chart.replaceChildren(renderSunburst(details, {
39
+ ...options, compact: true, href: (page, link) => href({ page, sha, ...link }), reshape: map,
40
+ }));
41
+ map();
42
+ }
43
+ /** A ranked file: its name over its folder, linked, with its score in a chip. A file in the root has no folder to name. */
44
+ function hotspotRow(path, target, chip) {
45
+ const link = document.createElement('a');
46
+ link.href = target;
47
+ const label = document.createElement('span');
48
+ label.className = 'hotspot-name';
49
+ const name = document.createElement('strong');
50
+ name.textContent = path.slice(path.lastIndexOf('/') + 1);
51
+ label.append(name);
52
+ const directory = parentPath(path);
53
+ if (directory) {
54
+ const parent = document.createElement('small');
55
+ parent.textContent = directory;
56
+ label.append(parent);
57
+ }
58
+ link.append(label, chip);
59
+ const row = document.createElement('li');
60
+ row.append(link);
61
+ return row;
62
+ }
63
+ function hotspotList(rows) {
64
+ const list = document.createElement('ol');
65
+ list.className = 'overview-hotspot-list';
66
+ list.append(...rows);
67
+ return list;
68
+ }
69
+ function rankedFiles(details, metric) {
70
+ const byPath = new Map(details.metrics.files.map(file => [file.path, file]));
71
+ return (details.metrics.hotspots[metric] ?? []).slice(0, 5).map(path => {
72
+ const entry = byPath.get(path);
73
+ return { path, value: entry ? hotspotScore(entry, metric) : null, entry };
74
+ });
75
+ }
76
+ /** The Overview's hotspot column for the selected quality area: the compact map and the top five files. */
77
+ export function renderOverviewHotspots(details, sha, area, scanned) {
78
+ const aside = byId('overview-hotspots');
79
+ aside.removeAttribute('aria-busy');
80
+ aside.classList.remove('overview-stale');
81
+ listHeading(true);
82
+ if (area === 'security') {
83
+ renderSecurityHotspots(details, sha, scanned);
84
+ return;
85
+ }
86
+ const metric = hotspotOf(area);
87
+ byId('overview-hotspots-title').textContent = titles[metric];
88
+ overviewMap(details, sha, { metric });
89
+ allLink(href({ page: 'hotspots', sha }), true);
90
+ const top = rankedFiles(details, metric);
91
+ const peak = Math.max(1, ...top.map(item => item.value ?? 0));
92
+ const rows = top.map(({ path, value, entry }) => {
93
+ const score = document.createElement('span');
94
+ score.className = 'chip';
95
+ score.textContent = count(value);
96
+ if (value !== null && entry)
97
+ score.dataset.band = String(band(entry, metric, value, peak, bandLimits(details, metric)));
98
+ return hotspotRow(path, href({ page: 'metrics', sha, file: path, directory: parentPath(path) }), score);
99
+ });
100
+ const output = byId('overview-hotspot-list');
101
+ if (rows.length)
102
+ output.replaceChildren(hotspotList(rows));
103
+ else if (metric === 'missedLines' && !details.metrics.files.some(file => file.lineCoverage))
104
+ unranked();
105
+ else
106
+ notice(output, 'No files in this ranking.');
107
+ }
108
+ /** Each file's worst finding, in the steps of the security mark; until findings carry a critical level, high is the top. */
109
+ const levelSteps = { low: 1, unknown: 1, medium: 2, high: 3 };
110
+ function securityFindings(details) {
111
+ const sensitive = new Set(securityCategories);
112
+ return (details.findings ?? []).filter((finding) => sensitive.has(finding.category) && Boolean(finding.path));
113
+ }
114
+ /**
115
+ * Security has no measure of its own on the map: the map shows sizes in grey, and the list ranks files by their
116
+ * scanner findings. Without a scanner report there is nothing to rank, and the grey map says so.
117
+ */
118
+ function renderSecurityHotspots(details, sha, scanned) {
119
+ byId('overview-hotspots-title').textContent = 'Security hotspots';
120
+ const findings = securityFindings(details);
121
+ const levels = new Map();
122
+ const counts = new Map();
123
+ for (const finding of findings) {
124
+ levels.set(finding.path, Math.max(levels.get(finding.path) ?? 0, levelSteps[finding.level]));
125
+ counts.set(finding.path, (counts.get(finding.path) ?? 0) + 1);
126
+ }
127
+ overviewMap(details, sha, { metric: 'complexity', ...scanned ? { levels } : { muted: true } });
128
+ allLink(href({ page: 'issues', sha }), scanned);
129
+ if (!scanned) {
130
+ unranked();
131
+ return;
132
+ }
133
+ // The worst level first, then the most findings; the chip names the level, as the map colours it.
134
+ const top = [...levels].sort((a, b) => b[1] - a[1] || counts.get(b[0]) - counts.get(a[0]) || a[0].localeCompare(b[0])).slice(0, 5);
135
+ const output = byId('overview-hotspot-list');
136
+ if (!top.length) {
137
+ notice(output, 'No security findings.');
138
+ return;
139
+ }
140
+ output.replaceChildren(hotspotList(top.map(([path, level]) => {
141
+ const score = document.createElement('span');
142
+ score.className = 'chip chip-level';
143
+ score.dataset.level = String(level);
144
+ score.textContent = securityGrades[level];
145
+ score.title = `${securityRisks[level]} · ${quantity(counts.get(path), 'finding')}`;
146
+ return hotspotRow(path, href({ page: 'issues', sha, query: path }), score);
147
+ })));
148
+ }
149
+ /**
150
+ * The hotspot column while the inspection loads. A map and ranking already on screen stay, dimmed, until the next ones
151
+ * replace them; on a first visit placeholders of the same size hold the column, so nothing beside it moves.
152
+ */
153
+ export function overviewStub(sha) {
154
+ const chart = byId('overview-sunburst');
155
+ const output = byId('overview-hotspot-list');
156
+ allLink(href({ page: 'hotspots', sha }), true);
157
+ const aside = byId('overview-hotspots');
158
+ aside.setAttribute('aria-busy', 'true');
159
+ listHeading(true);
160
+ if (chart.querySelector('.fx-sunburst:not(.fx-map-stub)') && output.querySelector('.overview-hotspot-list')) {
161
+ aside.classList.add('overview-stale');
162
+ return;
163
+ }
164
+ chart.replaceChildren(mapStub());
165
+ const list = document.createElement('ol');
166
+ list.className = 'overview-hotspot-list overview-hotspot-stub';
167
+ for (let row = 0; row < 5; row++) {
168
+ const item = document.createElement('li');
169
+ item.innerHTML = '<span><span class="stub-line"></span><span class="stub-line stub-line-short"></span></span><span class="stub-chip"></span>';
170
+ list.append(item);
171
+ }
172
+ output.replaceChildren(list);
173
+ }