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,12 @@
1
+ import type { InspectionContext } from '../../json/wire/inspection-context-model.js';
2
+ import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
3
+ import type { QualitySummary } from '../../json/wire/domain-types.js';
4
+ import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
5
+ import type { BuiltinMetric } from './viewer-metrics.js';
6
+ interface History {
7
+ readonly quality: Record<string, QualitySummary>;
8
+ readonly context: Record<string, InspectionContext> | null;
9
+ }
10
+ /** The figures under the Overview's chart for the selected area, each with its change since the inspection before. */
11
+ export declare function renderLead(reports: readonly PublicHistoryEntry[], selected: PublicHistoryEntry, history: History, area: BuiltinMetric, details?: InspectionDetails): void;
12
+ export {};
@@ -0,0 +1,116 @@
1
+ import { byId, parentPath } from './viewer-dom.js';
2
+ import { difference, formatMetric, labelOf, metricValue } from './viewer-metrics.js';
3
+ import { securityLink, smellsLink, uncoveredLink } from './viewer-overview-cards.js';
4
+ import { href } from './viewer-route.js';
5
+ import { commitTime } from './viewer-trend-data.js';
6
+ const dateTime = new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' });
7
+ /**
8
+ * Each quality area brings its own figures under the chart, and a second series drawn in grey behind the first:
9
+ * maintainability pairs the debt ratio with the remediation time, coverage pairs the ratio with the uncovered lines.
10
+ */
11
+ const areas = {
12
+ debt: ['debt', 'effort', 'duplication', 'complexity'],
13
+ coverage: ['coverage', 'coverable-lines', 'covered-lines', 'uncovered-lines'],
14
+ security: ['security', 'security-high', 'security-medium', 'security-low'],
15
+ complexity: ['complexity', 'functions', 'cognitive', 'code-lines'],
16
+ };
17
+ const emptyAreas = {
18
+ coverage: 'No coverage report for this commit.',
19
+ security: 'No security scanner report for this commit.',
20
+ };
21
+ /** The figures that count findings lead to them; uncovered lines lead to the files that hold them. */
22
+ const findingLinks = {
23
+ effort: smellsLink,
24
+ duplication: sha => href({ page: 'issues', sha, category: 'duplication' }),
25
+ 'uncovered-lines': uncoveredLink,
26
+ security: sha => securityLink(sha),
27
+ 'security-high': sha => securityLink(sha, 'high'),
28
+ 'security-medium': sha => securityLink(sha, 'medium'),
29
+ 'security-low': sha => securityLink(sha, 'low'),
30
+ };
31
+ /** The most complex function's line, where the details name a function of that complexity. */
32
+ function functionLink(value, sha, details) {
33
+ const top = details?.functions.find(item => item.complexity === value);
34
+ if (!top)
35
+ return undefined;
36
+ return href({ page: 'metrics', sha, file: top.path, directory: parentPath(top.path), ...top.line ? { line: top.line } : {} });
37
+ }
38
+ /**
39
+ * Where a lead figure leads, when it counts things the report lists: remediation time to the code smells it prices,
40
+ * duplication to the duplicated code, uncovered lines to the files that hold them, security counts to the findings,
41
+ * and the most complex function to its line. Ratios and sizes lead nowhere.
42
+ */
43
+ function figureLink(metric, value, sha, details) {
44
+ if (metric === 'complexity')
45
+ return functionLink(value, sha, details);
46
+ return findingLinks[metric]?.(sha);
47
+ }
48
+ /** What a change is measured from: the commit's time where it has one, else the inspection's. */
49
+ function sinceWhen(previous) {
50
+ const time = previous ? commitTime(previous) : null;
51
+ if (time !== null)
52
+ return `the commit of ${dateTime.format(time)}`;
53
+ const inspectedAt = Date.parse(previous?.generatedAt ?? '');
54
+ return Number.isFinite(inspectedAt) ? `the inspection of ${dateTime.format(inspectedAt)}` : 'the previous inspection';
55
+ }
56
+ /** A figure shows its change only when it moved, and only against an inspection under the same profile. */
57
+ function leadFigures(selected, previous, area, history) {
58
+ const read = (report, metric) => metricValue(report, metric, history.quality[report.sha], history.context?.[report.sha]);
59
+ const comparable = previous !== undefined && history.context?.[selected.sha]?.boundary !== 'changed';
60
+ return (areas[area] ?? areas.debt).map(metric => {
61
+ const value = read(selected, metric);
62
+ const prior = comparable ? read(previous, metric) : null;
63
+ return { metric, value, change: value !== null && prior !== null ? difference(value, prior, metric) : null };
64
+ });
65
+ }
66
+ function figureValue(figure, sha, details) {
67
+ const shown = document.createElement('dd');
68
+ shown.className = 'figure-value';
69
+ const { metric, value } = figure;
70
+ if (value === null) {
71
+ shown.textContent = '—';
72
+ return shown;
73
+ }
74
+ const destination = value > 0 ? figureLink(metric, value, sha, details) : undefined;
75
+ if (!destination) {
76
+ shown.textContent = formatMetric(value, metric);
77
+ return shown;
78
+ }
79
+ const anchor = document.createElement('a');
80
+ anchor.href = destination;
81
+ anchor.textContent = formatMetric(value, metric);
82
+ shown.append(anchor);
83
+ return shown;
84
+ }
85
+ function figureDelta(figure, since) {
86
+ const text = figure.change && figure.change.direction !== 'same' ? figure.change.text : '';
87
+ const delta = document.createElement('dd');
88
+ delta.className = 'figure-delta';
89
+ delta.textContent = text;
90
+ delta.dataset.direction = figure.change?.direction ?? 'none';
91
+ if (text)
92
+ delta.title = since;
93
+ return delta;
94
+ }
95
+ /** The figures under the Overview's chart for the selected area, each with its change since the inspection before. */
96
+ export function renderLead(reports, selected, history, area, details) {
97
+ const previous = reports[reports.indexOf(selected) + 1];
98
+ const figures = leadFigures(selected, previous, area, history);
99
+ // An area with nothing measured at this commit says so once, instead of a row of dashes.
100
+ if (figures.every(entry => entry.value === null)) {
101
+ const empty = document.createElement('p');
102
+ empty.className = 'lead-empty';
103
+ empty.textContent = emptyAreas[area] ?? 'Not measured for this commit.';
104
+ byId('lead').replaceChildren(empty);
105
+ return;
106
+ }
107
+ const since = previous ? `Since ${sinceWhen(previous)} (${previous.sha.slice(0, 7)})` : '';
108
+ byId('lead').replaceChildren(...figures.map(figure => {
109
+ const node = document.createElement('div');
110
+ node.className = 'figure';
111
+ const label = document.createElement('dt');
112
+ label.textContent = labelOf(figure.metric);
113
+ node.append(label, figureValue(figure, selected.sha, details), figureDelta(figure, since));
114
+ return node;
115
+ }));
116
+ }
@@ -0,0 +1,11 @@
1
+ import type { InspectionContext } from '../../json/wire/inspection-context-model.js';
2
+ import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
3
+ import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
4
+ import type { QualitySummary } from '../../json/wire/domain-types.js';
5
+ export interface Latest {
6
+ readonly report: PublicHistoryEntry;
7
+ readonly quality: QualitySummary | undefined;
8
+ readonly context: InspectionContext | undefined;
9
+ }
10
+ /** The badges as a README shows them: each with the scale it grades by, and the snippet that embeds it. */
11
+ export declare function badges(latest: Latest, details: InspectionDetails | undefined): HTMLElement;
@@ -0,0 +1,119 @@
1
+ import { segmented } from './viewer-controls.js';
2
+ import { copyIcon, copyOnClick } from './viewer-copy.js';
3
+ import { count, element, store, stored } from './viewer-dom.js';
4
+ import { securityGrades, securityRisks } from './viewer-metrics.js';
5
+ const formatKey = 'repometry.badge-format';
6
+ /** The security step by the worst finding: 4 critical, 3 high, 2 medium, 1 anything else, 0 none. */
7
+ function securityStep(security) {
8
+ const worst = [security.critical ?? 0, security.high, security.medium].findIndex(amount => amount > 0);
9
+ if (worst >= 0)
10
+ return 4 - worst;
11
+ return security.low || security.unknown ? 1 : 0;
12
+ }
13
+ function step(value, limits, reached) {
14
+ return value == null ? null : limits.findIndex(limit => reached(value, limit));
15
+ }
16
+ function areas({ report, quality, context }) {
17
+ const lines = report.lineCoverage;
18
+ const coverage = lines && lines.total > 0 ? lines.covered / lines.total : null;
19
+ const security = context?.security;
20
+ return [
21
+ { name: 'maintainability', label: 'Maintainability', steps: [['A', '<5%'], ['B', '<10%'], ['C', '<20%'], ['D', '<50%'], ['F', '50%+']],
22
+ current: step(quality?.maintainability?.debtRatio, [.05, .1, .2, .5, Infinity], (value, limit) => value < limit), published: true },
23
+ { name: 'coverage', label: 'Coverage', steps: [['A', '90%+'], ['B', '80%+'], ['C', '70%+'], ['D', '60%+'], ['F', '<60%']],
24
+ current: step(coverage, [.9, .8, .7, .6, -Infinity], (value, limit) => value >= limit), published: true },
25
+ { name: 'security', label: 'Security', steps: securityGrades.map((grade, index) => [grade, securityRisks[index]]),
26
+ current: security ? securityStep(security) : null, published: security !== undefined },
27
+ ];
28
+ }
29
+ /** The scale as one strip in the grade colours, the latest inspection's step at full strength. */
30
+ function scale(steps, current) {
31
+ const box = element('div', 'profile-scale');
32
+ const strip = element('div', 'profile-scale-strip');
33
+ const words = element('div', 'profile-scale-words');
34
+ for (const [index, [grade, range, word]] of steps.entries()) {
35
+ const segment = element('span', 'profile-scale-grade', word ?? grade);
36
+ segment.dataset.grade = grade;
37
+ if (index === current)
38
+ segment.setAttribute('aria-current', 'true');
39
+ strip.append(segment);
40
+ words.append(element('span', '', range));
41
+ }
42
+ box.append(strip, words);
43
+ return box;
44
+ }
45
+ /** Copies the snippet; without clipboard access the snippet is selected, ready for the copy shortcut. */
46
+ function copyButton(label, text) {
47
+ const button = element('button', 'fx-copy profile-copy');
48
+ button.type = 'button';
49
+ button.title = label;
50
+ button.setAttribute('aria-label', label);
51
+ button.append(copyIcon());
52
+ copyOnClick(button, text, {
53
+ copied: () => undefined,
54
+ reset: () => undefined,
55
+ refused: () => {
56
+ const range = document.createRange();
57
+ range.selectNodeContents(button.previousElementSibling);
58
+ getSelection()?.removeAllRanges();
59
+ getSelection()?.addRange(range);
60
+ },
61
+ });
62
+ return button;
63
+ }
64
+ function snippetText(format, label, url, home) {
65
+ return format === 'markdown' ? `[![${label}](${url})](${home})` : `<a href="${home}"><img src="${url}" alt="${label}"></a>`;
66
+ }
67
+ /** One badge: its image, its scale, and the snippet that embeds it in the chosen format. */
68
+ function badgeArea(area, format, snippets) {
69
+ const { name, label, steps, current, published } = area;
70
+ const section = element('section', 'fx-aside-section profile-badge-area');
71
+ section.append(element('h3', '', label));
72
+ if (!published) {
73
+ section.append(scale(steps, current), element('p', 'fx-note', 'No scanner report, so no badge.'));
74
+ return section;
75
+ }
76
+ const image = element('img', 'profile-badge');
77
+ image.src = `./${name}.svg`;
78
+ image.alt = `${label} badge`;
79
+ image.height = 22;
80
+ const url = new URL(`./${name}.svg`, location.href).href;
81
+ const home = new URL('./', location.href).href;
82
+ const box = element('div', 'profile-snippet');
83
+ const text = element('code');
84
+ box.append(text, copyButton(`Copy the ${label.toLowerCase()} badge snippet`, () => text.textContent ?? ''));
85
+ const update = () => { text.textContent = snippetText(format(), label, url, home); };
86
+ update();
87
+ snippets.push(update);
88
+ section.append(image, scale(steps, current), box);
89
+ return section;
90
+ }
91
+ /** How the maintainability grade's ratio is made: remediation time over the time the debt model gives the code. */
92
+ function debtNote(model) {
93
+ if (!model)
94
+ return 'Debt ratio: remediation time over the estimated time to write the code.';
95
+ const name = model.name === 'basic-cocomo-organic' ? 'basic COCOMO (organic)' : model.name;
96
+ return `Debt ratio: remediation time over the time to write the code, by ${name}: ${model.scale} × KLOC^${model.exponent} person-months of ${count(Math.round(model.minutesPerPersonMonth / 60))} hours.`;
97
+ }
98
+ /** The badges as a README shows them: each with the scale it grades by, and the snippet that embeds it. */
99
+ export function badges(latest, details) {
100
+ const panel = element('aside', 'fx-aside profile-aside');
101
+ panel.setAttribute('aria-label', 'Badges');
102
+ const heading = element('div', 'fx-aside-heading');
103
+ heading.append(element('h2', '', 'Badges'));
104
+ let format = stored(() => localStorage, formatKey) === 'html' ? 'html' : 'markdown';
105
+ const snippets = [];
106
+ const toggle = segmented('Snippet format', [['markdown', 'Markdown'], ['html', 'HTML']], format, value => {
107
+ format = value;
108
+ store(() => localStorage, formatKey, value);
109
+ for (const update of snippets)
110
+ update();
111
+ });
112
+ toggle.classList.add('profile-format');
113
+ heading.append(toggle);
114
+ panel.append(heading, ...areas(latest).map(area => badgeArea(area, () => format, snippets)));
115
+ // Footnotes close the sidebar, under the last badge: how the maintainability grade's ratio is made, and what badges show.
116
+ panel.append(element('p', 'fx-note profile-badge-note', debtNote(details?.profile?.debtModel)));
117
+ panel.append(element('p', 'fx-note profile-footnote', 'Badges show the latest inspection; their links work once the report is hosted.'));
118
+ return panel;
119
+ }
@@ -0,0 +1,29 @@
1
+ export interface Column<T> {
2
+ readonly label: string;
3
+ readonly numeric?: boolean;
4
+ readonly cell: (row: T) => Node | string;
5
+ readonly sort: (row: T) => string | number;
6
+ }
7
+ export interface TableSpec<T> {
8
+ readonly label: string;
9
+ readonly noun: readonly [string, string];
10
+ readonly rows: readonly T[];
11
+ readonly columns: readonly Column<T>[];
12
+ readonly search: (row: T) => string;
13
+ readonly facet?: {
14
+ readonly text: string;
15
+ readonly all: string;
16
+ readonly plural: string;
17
+ readonly key: (row: T) => string;
18
+ };
19
+ readonly empty: string;
20
+ /** Search and filter even while the list is short: the rules grow with every plugin and stack. */
21
+ readonly controls?: boolean;
22
+ }
23
+ /** The count beside the page buttons, as in Metrics: the page's range, how many the search kept, or how many there are. */
24
+ export declare function tableSummary(noun: readonly [string, string], shown: number, total: number, first: number, visible: number): string;
25
+ /**
26
+ * A list searched, narrowed by one facet, sorted by any column, and paged, with the count beside the page buttons as
27
+ * in Metrics. Only the page in view is built.
28
+ */
29
+ export declare function pagedTable<T>(spec: TableSpec<T>): HTMLElement;
@@ -0,0 +1,124 @@
1
+ // A list that may run to tens of thousands of rows, as a profile's rules and patterns do in a monorepo.
2
+ import { multiChoice, navigationButtons, searchField } from './viewer-controls.js';
3
+ import { count, element } from './viewer-dom.js';
4
+ const tableSize = 50;
5
+ const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
6
+ /** Orders by a column: numbers by value, anything else as people read it. */
7
+ function byColumn(sort, ascending) {
8
+ const direction = ascending ? 1 : -1;
9
+ return (a, b) => {
10
+ const left = sort(a);
11
+ const right = sort(b);
12
+ return direction * (typeof left === 'number' && typeof right === 'number' ? left - right : collator.compare(String(left), String(right)));
13
+ };
14
+ }
15
+ /** The count beside the page buttons, as in Metrics: the page's range, how many the search kept, or how many there are. */
16
+ export function tableSummary(noun, shown, total, first, visible) {
17
+ const [one, many] = noun;
18
+ if (shown === 0)
19
+ return `No ${many} match.`;
20
+ if (shown > tableSize)
21
+ return `${count(first + 1)}–${count(first + visible)} of ${count(shown)} ${many}`;
22
+ if (shown !== total)
23
+ return `${count(shown)} of ${count(total)} ${many}`;
24
+ return `${count(shown)} ${shown === 1 ? one : many}`;
25
+ }
26
+ /** The facet's values with how many rows each has, by name. */
27
+ function facetOptions(rows, key) {
28
+ const counts = new Map();
29
+ for (const row of rows)
30
+ counts.set(key(row), (counts.get(key(row)) ?? 0) + 1);
31
+ return [...counts].sort((a, b) => collator.compare(a[0], b[0])).map(([value, total]) => [value, value, total]);
32
+ }
33
+ function tableRow(row, columns) {
34
+ const line = element('tr');
35
+ for (const column of columns) {
36
+ const cell = element('td', column.numeric ? 'numeric' : '');
37
+ cell.append(column.cell(row));
38
+ line.append(cell);
39
+ }
40
+ return line;
41
+ }
42
+ /**
43
+ * A list searched, narrowed by one facet, sorted by any column, and paged, with the count beside the page buttons as
44
+ * in Metrics. Only the page in view is built.
45
+ */
46
+ export function pagedTable(spec) {
47
+ const box = element('div', 'profile-table');
48
+ if (!spec.rows.length) {
49
+ box.append(element('p', 'detail', spec.empty));
50
+ return box;
51
+ }
52
+ const haystacks = spec.rows.map(row => spec.search(row).toLowerCase());
53
+ const state = { page: 0, sortBy: -1, ascending: true };
54
+ const reset = () => { state.page = 0; render(); };
55
+ const tools = element('div', 'fx-tools profile-table-tools');
56
+ const search = searchField(`Search ${spec.noun[1]}`, `Search ${spec.noun[1]}`);
57
+ search.label.classList.add('fx-field-bare');
58
+ search.input.addEventListener('input', reset);
59
+ const facet = spec.facet && multiChoice(spec.facet, facetOptions(spec.rows, spec.facet.key), reset);
60
+ // A short list needs no controls: it is read at a glance.
61
+ if (spec.controls || spec.rows.length > 10)
62
+ tools.append(search.label);
63
+ if (facet && !facet.element.hidden)
64
+ tools.append(facet.element);
65
+ const table = element('table', 'fx-table profile-list');
66
+ table.setAttribute('aria-label', spec.label);
67
+ const head = element('tr');
68
+ const headers = spec.columns.map((column, index) => {
69
+ const cell = element('th', column.numeric ? 'numeric' : '');
70
+ cell.scope = 'col';
71
+ const button = element('button', 'fx-sort', column.label);
72
+ button.type = 'button';
73
+ button.addEventListener('click', () => {
74
+ state.ascending = state.sortBy === index ? !state.ascending : !column.numeric;
75
+ state.sortBy = index;
76
+ reset();
77
+ });
78
+ cell.append(button);
79
+ head.append(cell);
80
+ return cell;
81
+ });
82
+ const thead = element('thead');
83
+ thead.append(head);
84
+ const body = element('tbody');
85
+ table.append(thead, body);
86
+ const frame = element('div', 'table-scroll fx-table-scroll');
87
+ frame.append(table);
88
+ const pager = element('div', 'fx-pager');
89
+ const result = element('p', 'fx-note fx-results');
90
+ result.setAttribute('aria-live', 'polite');
91
+ const buttons = navigationButtons(`${spec.label} pages`, () => { state.page -= 1; render(); }, () => { state.page += 1; render(); });
92
+ pager.append(result, buttons.section);
93
+ if (tools.childElementCount)
94
+ box.append(tools);
95
+ box.append(frame, pager);
96
+ function selected() {
97
+ const words = search.input.value.trim().toLowerCase().split(/\s+/).filter(Boolean);
98
+ const chosen = facet ? facet.values : new Set();
99
+ const inFacet = (row) => chosen.size === 0 || chosen.has(spec.facet.key(row));
100
+ return spec.rows.filter((row, index) => inFacet(row) && words.every(word => haystacks[index].includes(word)));
101
+ }
102
+ function render() {
103
+ const shown = selected();
104
+ if (state.sortBy >= 0)
105
+ shown.sort(byColumn(spec.columns[state.sortBy].sort, state.ascending));
106
+ for (const [index, cell] of headers.entries()) {
107
+ if (index === state.sortBy)
108
+ cell.setAttribute('aria-sort', state.ascending ? 'ascending' : 'descending');
109
+ else
110
+ cell.removeAttribute('aria-sort');
111
+ }
112
+ const pages = Math.max(1, Math.ceil(shown.length / tableSize));
113
+ state.page = Math.min(state.page, pages - 1);
114
+ const first = state.page * tableSize;
115
+ const visible = shown.slice(first, first + tableSize);
116
+ body.replaceChildren(...visible.map(row => tableRow(row, spec.columns)));
117
+ frame.hidden = shown.length === 0;
118
+ result.textContent = tableSummary(spec.noun, shown.length, spec.rows.length, first, visible.length);
119
+ buttons.section.hidden = shown.length <= tableSize;
120
+ buttons.update(state.page, pages);
121
+ }
122
+ render();
123
+ return box;
124
+ }
@@ -1,17 +1,13 @@
1
1
  import type { InspectionContext } from '../../json/wire/inspection-context-model.js';
2
2
  import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
3
3
  import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
4
- import type { QualitySummary } from '../../json/wire/domain-types.js';
4
+ import type { Latest } from './viewer-profile-badges.js';
5
5
  export interface ProfileData {
6
6
  readonly report: PublicHistoryEntry;
7
7
  readonly context: InspectionContext | undefined;
8
8
  /** Present in local and private views: the applied profile travels with them. */
9
9
  readonly details: InspectionDetails | undefined;
10
10
  /** The newest inspection, which the badges show, with its quality and context. */
11
- readonly latest: {
12
- readonly report: PublicHistoryEntry;
13
- readonly quality: QualitySummary | undefined;
14
- readonly context: InspectionContext | undefined;
15
- };
11
+ readonly latest: Latest;
16
12
  }
17
13
  export declare function renderProfile(container: HTMLElement, data: ProfileData): void;