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,72 @@
1
+ import { element, percent } from './viewer-dom.js';
2
+ import { sameClause } from './viewer-filter.js';
3
+ import { ignoredLabel, languageColor, languageShares, lockfilesLabel } from './viewer-languages.js';
4
+ import { labelOf } from './viewer-metrics.js';
5
+ /** Lockfiles and the files no plugin read stand at the end in muted tones: categories, not languages. */
6
+ const categories = new Map([
7
+ [lockfilesLabel, { clause: { kind: 'lockfile', value: 'yes' }, color: 'var(--lockfile)', className: 'fx-language-lockfile' }],
8
+ [ignoredLabel, { clause: { kind: 'analysed', value: 'no' }, color: 'var(--grade-none)', className: 'fx-language-unread' }],
9
+ ]);
10
+ /** The clause a language's chip stands for. */
11
+ function clauseOf(language) {
12
+ return categories.get(language)?.clause ?? { kind: 'lang', value: language };
13
+ }
14
+ /** Whether the query holds a language's clause: a language by name in any case, a category exactly. */
15
+ function holds(clauses, language) {
16
+ const clause = clauseOf(language);
17
+ if (clause.kind !== 'lang')
18
+ return clauses.some(other => sameClause(other, clause));
19
+ return clauses.some(other => other.kind === 'lang' && other.value.toLowerCase() === language.toLowerCase());
20
+ }
21
+ /** The query with a language's chip pressed or released. */
22
+ export function toggleLanguage(clauses, language) {
23
+ const clause = clauseOf(language);
24
+ if (!holds(clauses, language))
25
+ return [...clauses, clause];
26
+ if (clause.kind !== 'lang')
27
+ return clauses.filter(other => other.kind !== clause.kind);
28
+ return clauses.filter(other => !(other.kind === 'lang' && other.value.toLowerCase() === language.toLowerCase()));
29
+ }
30
+ function chip(language, share, color, pressed) {
31
+ const category = categories.get(language);
32
+ const toggle = element('button', category ? `fx-language ${category.className}` : 'fx-language');
33
+ toggle.type = 'button';
34
+ toggle.setAttribute('aria-pressed', String(pressed));
35
+ const dot = element('span', 'fx-language-dot');
36
+ dot.style.background = color;
37
+ toggle.append(dot, element('span', 'fx-language-name', language), element('span', 'fx-language-share', share));
38
+ return toggle;
39
+ }
40
+ /**
41
+ * The languages of the selection as one bar, with a legend whose names toggle their chips in the query. Nothing shows
42
+ * for a single language or no weight at all.
43
+ */
44
+ export function renderLanguages(container, files, clauses, set) {
45
+ const { measure, shares } = languageShares(files);
46
+ const total = shares.reduce((sum, [, weight]) => sum + weight, 0);
47
+ container.hidden = shares.length < 2 || total === 0;
48
+ if (container.hidden)
49
+ return;
50
+ // Any language in the query dims the rest of the bar, even one this selection does not hold.
51
+ const anyPicked = clauses.some(clause => clause.kind === 'lang') || [...categories.keys()].some(name => holds(clauses, name));
52
+ const bar = element('div', 'fx-language-bar');
53
+ bar.setAttribute('aria-hidden', 'true');
54
+ const legend = element('div', 'fx-language-legend');
55
+ legend.setAttribute('role', 'group');
56
+ const measured = measure === 'bytes' ? 'size' : labelOf(measure).toLowerCase();
57
+ legend.setAttribute('aria-label', `Languages by ${measured}`);
58
+ for (const [language, weight] of shares) {
59
+ const pressed = holds(clauses, language);
60
+ const color = categories.get(language)?.color ?? languageColor(language);
61
+ const segment = element('span', !anyPicked || pressed ? 'fx-language-segment' : 'fx-language-segment fx-off');
62
+ segment.style.flexGrow = String(weight);
63
+ segment.style.background = color;
64
+ bar.append(segment);
65
+ const toggle = chip(language, percent(weight / total), color, pressed);
66
+ toggle.addEventListener('click', () => set(toggleLanguage(clauses, language)));
67
+ legend.append(toggle);
68
+ }
69
+ // The bar says what it weighs, so its shares can be checked against a column of the table.
70
+ legend.append(element('span', 'fx-language-measure', `Share of ${measured}`));
71
+ container.replaceChildren(bar, legend);
72
+ }
@@ -0,0 +1,27 @@
1
+ import type { FileMetricsReport } from '../../json/wire/file-metrics-model.js';
2
+ type FileEntry = FileMetricsReport['files'][number];
3
+ /**
4
+ * Dependency lockfiles, by exact file name. They are generated, often the largest files in a repository, and no
5
+ * plugin reads them: the language bar and the Metrics list give them a category of their own beside the ignored files.
6
+ */
7
+ export declare const lockfileNames: ReadonlySet<string>;
8
+ /** Whether a path names a lockfile: its file name, at any depth, exactly as the tools write it. */
9
+ export declare function isLockfile(path: string): boolean;
10
+ /** Whether no plugin read a file and it is not a lockfile: what the interface calls ignored. */
11
+ export declare function isIgnored(entry: Pick<FileEntry, 'path' | 'analysed'>): boolean;
12
+ /** The language bar's names for the two categories that are not languages. */
13
+ export declare const lockfilesLabel = "Lockfiles";
14
+ export declare const ignoredLabel = "Ignored";
15
+ /** What the language bar weighs: size in bytes, physical lines, or code lines. */
16
+ export type ShareMeasure = 'bytes' | 'lines' | 'code-lines';
17
+ /** Whether every file carries its size: inspections made before sizes were recorded carry none. */
18
+ export declare function sized(files: readonly Pick<FileEntry, 'bytes'>[]): boolean;
19
+ type Weighed = Pick<FileEntry, 'path' | 'analysed' | 'lines' | 'quality' | 'bytes'>;
20
+ /** What the language bar weighs, largest language first, then lockfiles, then the ignored files. */
21
+ export declare function languageShares(files: readonly Weighed[]): {
22
+ readonly measure: ShareMeasure;
23
+ readonly shares: readonly (readonly [string, number])[];
24
+ };
25
+ export declare function languageOf(path: string): string;
26
+ export declare function languageColor(language: string): string;
27
+ export {};
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Dependency lockfiles, by exact file name. They are generated, often the largest files in a repository, and no
3
+ * plugin reads them: the language bar and the Metrics list give them a category of their own beside the ignored files.
4
+ */
5
+ export const lockfileNames = new Set([
6
+ 'package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lock', 'bun.lockb', 'deno.lock',
7
+ 'Cargo.lock', 'Gemfile.lock', 'composer.lock', 'poetry.lock', 'Pipfile.lock', 'uv.lock', 'go.sum', 'flake.lock',
8
+ 'mix.lock', 'pubspec.lock', 'packages.lock.json', 'gradle.lockfile',
9
+ ]);
10
+ /** Whether a path names a lockfile: its file name, at any depth, exactly as the tools write it. */
11
+ export function isLockfile(path) {
12
+ return lockfileNames.has(path.slice(path.lastIndexOf('/') + 1));
13
+ }
14
+ /** Whether no plugin read a file and it is not a lockfile: what the interface calls ignored. */
15
+ export function isIgnored(entry) {
16
+ return entry.analysed === false && !isLockfile(entry.path);
17
+ }
18
+ /** The language bar's names for the two categories that are not languages. */
19
+ export const lockfilesLabel = 'Lockfiles';
20
+ export const ignoredLabel = 'Ignored';
21
+ /** Whether every file carries its size: inspections made before sizes were recorded carry none. */
22
+ export function sized(files) {
23
+ return files.length > 0 && files.every(entry => entry.bytes !== undefined);
24
+ }
25
+ const weights = {
26
+ bytes: entry => entry.bytes,
27
+ lines: entry => entry.lines,
28
+ 'code-lines': entry => entry.quality?.codeLines ?? entry.lines,
29
+ };
30
+ /**
31
+ * Size in bytes when every file has it: one measure for code, lockfiles and ignored files alike, untouched by
32
+ * formatting. Without sizes, physical lines where any file is only counted (the one line measure all files have),
33
+ * otherwise code lines.
34
+ */
35
+ function shareMeasure(files) {
36
+ if (sized(files))
37
+ return 'bytes';
38
+ return files.some(entry => entry.analysed === false || isLockfile(entry.path)) ? 'lines' : 'code-lines';
39
+ }
40
+ /** Where a file's weight goes on the bar: its language, or one of the two categories. */
41
+ function shareOf(entry) {
42
+ if (isLockfile(entry.path))
43
+ return lockfilesLabel;
44
+ return entry.analysed === false ? ignoredLabel : languageOf(entry.path);
45
+ }
46
+ /** What the language bar weighs, largest language first, then lockfiles, then the ignored files. */
47
+ export function languageShares(files) {
48
+ const measure = shareMeasure(files);
49
+ const totals = new Map();
50
+ for (const entry of files)
51
+ totals.set(shareOf(entry), (totals.get(shareOf(entry)) ?? 0) + (weights[measure](entry) ?? 0));
52
+ const categories = [lockfilesLabel, ignoredLabel];
53
+ const shares = [...totals].filter(([name, weight]) => weight > 0 && !categories.includes(name)).sort((a, b) => b[1] - a[1]);
54
+ for (const name of categories) {
55
+ const weight = totals.get(name) ?? 0;
56
+ if (weight > 0)
57
+ shares.push([name, weight]);
58
+ }
59
+ return { measure, shares };
60
+ }
61
+ const languages = {
62
+ ts: 'TypeScript', tsx: 'TypeScript', mts: 'TypeScript', cts: 'TypeScript',
63
+ js: 'JavaScript', jsx: 'JavaScript', mjs: 'JavaScript', cjs: 'JavaScript',
64
+ py: 'Python', go: 'Go', rs: 'Rust', java: 'Java', kt: 'Kotlin', kts: 'Kotlin', rb: 'Ruby', php: 'PHP', cs: 'C#',
65
+ c: 'C', h: 'C', cc: 'C++', cpp: 'C++', cxx: 'C++', hpp: 'C++', hh: 'C++', swift: 'Swift', scala: 'Scala',
66
+ vue: 'Vue', svelte: 'Svelte', sh: 'Shell', bash: 'Shell', css: 'CSS', scss: 'SCSS', less: 'Less', html: 'HTML',
67
+ yaml: 'YAML', yml: 'YAML', json: 'JSON', dockerfile: 'Dockerfile',
68
+ };
69
+ /** Files a name alone types: Dockerfile and Containerfile, with or without a suffix such as Dockerfile.dev. */
70
+ const namedLanguages = [[/^(?:dockerfile|containerfile)(?:\..+)?$/i, 'Dockerfile']];
71
+ /** Language colours follow the conventions people already know from code hosts. */
72
+ const languageColors = {
73
+ TypeScript: '#3178c6', JavaScript: '#f1e05a', Python: '#3572a5', Go: '#00add8', Rust: '#dea584', Java: '#b07219',
74
+ Kotlin: '#a97bff', Ruby: '#701516', PHP: '#4f5d95', 'C#': '#178600', C: '#555555', 'C++': '#f34b7d', Swift: '#f05138',
75
+ Scala: '#c22d40', Vue: '#41b883', Svelte: '#ff3e00', Shell: '#89e051', CSS: '#663399', SCSS: '#c6538c', Less: '#1d365d',
76
+ HTML: '#e34c26',
77
+ // Configuration reads beside the code, so it takes quieter tones than the code hosts give it.
78
+ YAML: '#c47d84', JSON: '#9b86b5', Dockerfile: '#4f9a94',
79
+ };
80
+ export function languageOf(path) {
81
+ const name = path.slice(path.lastIndexOf('/') + 1);
82
+ const named = namedLanguages.find(([pattern]) => pattern.test(name));
83
+ if (named)
84
+ return named[1];
85
+ const dot = name.lastIndexOf('.');
86
+ const extension = dot > 0 ? name.slice(dot + 1).toLowerCase() : '';
87
+ if (!extension)
88
+ return 'Other';
89
+ return languages[extension] ?? extension.toUpperCase();
90
+ }
91
+ export function languageColor(language) {
92
+ return languageColors[language] ?? 'var(--neutral-2)';
93
+ }
@@ -0,0 +1,14 @@
1
+ import type { Navigation } from './viewer-inspection.js';
2
+ /**
3
+ * The handle between a list and its side panel: a line that shows on hover and drags the panel wider or narrower.
4
+ * Arrow keys move it too, a double click restores the default, and the width is remembered for this viewer.
5
+ */
6
+ export declare function splitter(split: HTMLElement): HTMLElement;
7
+ /**
8
+ * Raises a side column so its heading stands on the page title's baseline: the list and its summary read as one
9
+ * row of headings. What sits between the title and the panel (a folder path, a toolbar) varies, so the distance is
10
+ * measured, and measured again whenever the page above the panel changes height. One column on a narrow screen: no lift.
11
+ */
12
+ export declare function liftToTitle(split: HTMLElement, headingSelector: string): void;
13
+ /** The folder trail above a list: each folder a link, the current one a label, nothing at the root. */
14
+ export declare function breadcrumbs(view: 'metrics' | 'hotspots', navigation: Pick<Navigation, 'href'>, directory: string): HTMLElement;
@@ -0,0 +1,134 @@
1
+ import { element, link, store, stored } from './viewer-dom.js';
2
+ const asideKey = 'repometry.aside';
3
+ /**
4
+ * The handle between a list and its side panel: a line that shows on hover and drags the panel wider or narrower.
5
+ * Arrow keys move it too, a double click restores the default, and the width is remembered for this viewer.
6
+ */
7
+ export function splitter(split) {
8
+ const handle = element('div', 'fx-splitter');
9
+ handle.tabIndex = 0;
10
+ handle.setAttribute('role', 'separator');
11
+ handle.setAttribute('aria-orientation', 'vertical');
12
+ handle.setAttribute('aria-label', 'Resize the side panel');
13
+ handle.title = 'Drag to resize; double-click to reset';
14
+ const apply = (width) => {
15
+ if (width === null) {
16
+ split.style.removeProperty('--aside');
17
+ return;
18
+ }
19
+ const clamped = Math.round(Math.min(Math.max(224, split.clientWidth * .55), Math.max(224, width)));
20
+ split.style.setProperty('--aside', `${clamped}px`);
21
+ handle.setAttribute('aria-valuenow', String(clamped));
22
+ };
23
+ const save = (width) => store(() => localStorage, asideKey, width === null ? null : String(Math.round(width)));
24
+ const current = () => split.lastElementChild instanceof HTMLElement && split.lastElementChild !== handle
25
+ ? split.lastElementChild.getBoundingClientRect().width : 320;
26
+ const remembered = Number(stored(() => localStorage, asideKey));
27
+ if (remembered > 0)
28
+ requestAnimationFrame(() => apply(remembered));
29
+ handle.addEventListener('pointerdown', event => {
30
+ event.preventDefault();
31
+ handle.setPointerCapture(event.pointerId);
32
+ split.classList.add('fx-resizing');
33
+ const right = split.getBoundingClientRect().right;
34
+ const move = (next) => apply(right - next.clientX - handle.offsetWidth / 2);
35
+ const stop = () => {
36
+ split.classList.remove('fx-resizing');
37
+ save(current());
38
+ handle.removeEventListener('pointermove', move);
39
+ handle.removeEventListener('pointerup', stop);
40
+ handle.removeEventListener('pointercancel', stop);
41
+ };
42
+ handle.addEventListener('pointermove', move);
43
+ handle.addEventListener('pointerup', stop);
44
+ handle.addEventListener('pointercancel', stop);
45
+ });
46
+ handle.addEventListener('keydown', event => {
47
+ const step = arrowSteps.get(event.key);
48
+ if (step === undefined)
49
+ return;
50
+ event.preventDefault();
51
+ apply(current() + step);
52
+ save(current());
53
+ });
54
+ handle.addEventListener('dblclick', () => { apply(null); save(null); });
55
+ liftToTitle(split, ':scope > .fx-aside h2');
56
+ return handle;
57
+ }
58
+ /** The side panel sits at the right: the left arrow widens it. */
59
+ const arrowSteps = new Map([['ArrowLeft', 24], ['ArrowRight', -24]]);
60
+ /** Where a text's baseline is: its box ends below the baseline by the descent, about a fifth of its height. */
61
+ function baseline(node) {
62
+ const range = document.createRange();
63
+ range.selectNodeContents(node);
64
+ const box = range.getBoundingClientRect();
65
+ return box.bottom - box.height * .2;
66
+ }
67
+ /** The child of `parent` that holds `node`. */
68
+ function columnOf(node, parent) {
69
+ let column = node;
70
+ while (column.parentElement && column.parentElement !== parent)
71
+ column = column.parentElement;
72
+ return column;
73
+ }
74
+ /**
75
+ * Raises a side column so its heading stands on the page title's baseline: the list and its summary read as one
76
+ * row of headings. What sits between the title and the panel (a folder path, a toolbar) varies, so the distance is
77
+ * measured, and measured again whenever the page above the panel changes height. One column on a narrow screen: no lift.
78
+ */
79
+ export function liftToTitle(split, headingSelector) {
80
+ const measure = () => {
81
+ const title = split.closest('section')?.querySelector(':scope > h2');
82
+ const heading = split.querySelector(headingSelector);
83
+ const columns = getComputedStyle(split).gridTemplateColumns.split(' ').length;
84
+ if (!split.isConnected || !title || !heading || columns < 2) {
85
+ split.style.removeProperty('--lift');
86
+ return;
87
+ }
88
+ // The column may be sticky, and once the page scrolls its box no longer sits where the layout put it. So the
89
+ // heading is measured inside its column, and the column's place is taken from the grid, which never sticks:
90
+ // unlifted, a first-row column starts at the top of the grid's content box.
91
+ const style = getComputedStyle(split);
92
+ const top = split.getBoundingClientRect().top + parseFloat(style.borderTopWidth) + parseFloat(style.paddingTop);
93
+ const offset = baseline(heading) - columnOf(heading, split).getBoundingClientRect().top;
94
+ const current = parseFloat(split.style.getPropertyValue('--lift')) || 0;
95
+ const next = Math.max(0, Math.round(top + offset - baseline(title)));
96
+ if (next !== current)
97
+ split.style.setProperty('--lift', `${next}px`);
98
+ };
99
+ const observer = new ResizeObserver(() => {
100
+ if (split.isConnected)
101
+ measure();
102
+ else
103
+ observer.disconnect();
104
+ });
105
+ requestAnimationFrame(() => {
106
+ measure();
107
+ // The page section, not the view: a view may be laid out through display: contents and never resize itself.
108
+ const page = split.closest('section') ?? split.parentElement;
109
+ if (page)
110
+ observer.observe(page);
111
+ });
112
+ }
113
+ /** The folder trail above a list: each folder a link, the current one a label, nothing at the root. */
114
+ export function breadcrumbs(view, navigation, directory) {
115
+ const nav = element('nav', 'fx-breadcrumbs');
116
+ nav.setAttribute('aria-label', 'Folder path');
117
+ const list = element('ol');
118
+ const segments = directory === '' ? [] : directory.split('/');
119
+ const crumb = (label, target) => {
120
+ const item = element('li');
121
+ if (target === null) {
122
+ item.setAttribute('aria-current', 'location');
123
+ item.textContent = label;
124
+ }
125
+ else
126
+ item.append(link(navigation.href(view, target ? { directory: target } : undefined), label));
127
+ return item;
128
+ };
129
+ list.append(crumb('repo', directory === '' ? null : ''), ...segments.map((part, index) => crumb(part, index === segments.length - 1 ? null : segments.slice(0, index + 1).join('/'))));
130
+ nav.append(list);
131
+ // At the root the trail is a single label that says nothing the page title does not.
132
+ nav.hidden = directory === '';
133
+ return nav;
134
+ }
@@ -0,0 +1,47 @@
1
+ import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
2
+ /** Line ranges of one file's coverage: 1-based, inclusive and merged. Partial lines ran with some branches missed. */
3
+ export type FileLineCoverage = NonNullable<InspectionDetails['lineCoverage']>[string];
4
+ export type LineState = 'covered' | 'partial' | 'uncovered';
5
+ /** What the source view's lines show: the inspection's findings and complexity, or the tests' coverage. */
6
+ export type SourceLayer = 'issues' | 'coverage';
7
+ export declare function isSourceLayer(value: string | null | undefined): value is SourceLayer;
8
+ /** Switches a rendered source between its findings and its coverage, without drawing it again. */
9
+ export declare function setSourceLayer(container: HTMLElement, layer: SourceLayer): void;
10
+ /**
11
+ * Each line's coverage, by line number; a line no range names was not measured. Where ranges overlap, the worse
12
+ * state wins: a line a test missed is never shown as covered.
13
+ */
14
+ export declare function lineStates(coverage: FileLineCoverage): Map<number, LineState>;
15
+ /** Runs of equal hit counts: first and last line, 1-based and inclusive, and how often tests ran them; 0 is a miss. */
16
+ export type HitRun = readonly [first: number, last: number, count: number];
17
+ /** How often tests ran each line, where the report carries the counts; an older report has none. */
18
+ export declare function lineHits(coverage: FileLineCoverage): Map<number, number>;
19
+ /** A count short enough for the gutter: 3×, 980×, 1.2K×, 45K×, 270K×, 3.4M×. */
20
+ export declare function hitLabel(count: number): string;
21
+ /** What a measured line says to a pointer and a screen reader: its state, and how often it ran where that is known. */
22
+ export declare function lineCoverageText(state: LineState, count?: number): string;
23
+ /** What the gutter shows on a measured line: its state, the count it writes, and the words for both. */
24
+ export interface LineReading {
25
+ readonly state: LineState;
26
+ /** How often the line ran, or how often the functions it starts were called; none where no run is counted. */
27
+ readonly count?: number;
28
+ readonly text: string;
29
+ }
30
+ /**
31
+ * A declaration line reads as its functions' calls, not as the line's own count: that is how often the module was
32
+ * loaded. Called is covered; never called is red, with no number; where only some of the functions starting on the
33
+ * line ran, it is partial.
34
+ */
35
+ export declare function callReading(calls: readonly number[]): LineReading;
36
+ /**
37
+ * What each measured line shows. A line that starts functions shows their calls. Inside a function body a line shows
38
+ * how often it ran. Module-level code runs once per load, so its count says nothing about tests: it keeps its tint and
39
+ * shows no number. A report without function bodies cannot tell the two apart, and every line shows its own count.
40
+ */
41
+ export declare function lineReadings(coverage: FileLineCoverage): Map<number, LineReading>;
42
+ /**
43
+ * The tint a gap of blank and comment lines takes so the strip has no breaks: the state of the measured line above it,
44
+ * which the gap closes, or for a gap at the file's start, of the line below. A gap beside a line that was not measured
45
+ * takes its other neighbour, and one with no measured neighbour stays plain.
46
+ */
47
+ export declare function bridgeStates(states: ReadonlyMap<number, LineState>, codeless: readonly boolean[]): Map<number, LineState>;
@@ -0,0 +1,121 @@
1
+ export function isSourceLayer(value) {
2
+ return value === 'issues' || value === 'coverage';
3
+ }
4
+ /** Switches a rendered source between its findings and its coverage, without drawing it again. */
5
+ export function setSourceLayer(container, layer) {
6
+ const code = container.querySelector(':scope > .src');
7
+ if (code)
8
+ code.dataset.layer = layer;
9
+ }
10
+ /** Calls back for each line of each range, from line 1 at the earliest. */
11
+ function eachLine(ranges, visit) {
12
+ for (const range of ranges ?? [])
13
+ for (let line = Math.max(1, range[0]); line <= range[1]; line++)
14
+ visit(line, range);
15
+ }
16
+ /**
17
+ * Each line's coverage, by line number; a line no range names was not measured. Where ranges overlap, the worse
18
+ * state wins: a line a test missed is never shown as covered.
19
+ */
20
+ export function lineStates(coverage) {
21
+ const states = new Map();
22
+ for (const state of ['covered', 'partial', 'uncovered'])
23
+ eachLine(coverage[state], line => states.set(line, state));
24
+ return states;
25
+ }
26
+ /** How often tests ran each line, where the report carries the counts; an older report has none. */
27
+ export function lineHits(coverage) {
28
+ const hits = new Map();
29
+ eachLine(coverage.hits, (line, run) => hits.set(line, run[2]));
30
+ return hits;
31
+ }
32
+ // Two figures are enough for a glance; the tooltip has the whole count.
33
+ const compactCount = new Intl.NumberFormat('en', { notation: 'compact', maximumSignificantDigits: 2 });
34
+ const fullCount = new Intl.NumberFormat();
35
+ /** A count short enough for the gutter: 3×, 980×, 1.2K×, 45K×, 270K×, 3.4M×. */
36
+ export function hitLabel(count) {
37
+ return `${count < 1000 ? count : compactCount.format(count)}×`;
38
+ }
39
+ const lineStateNames = {
40
+ covered: 'Covered', partial: 'Partly covered: some branches missed', uncovered: 'Not covered',
41
+ };
42
+ /** What a measured line says to a pointer and a screen reader: its state, and how often it ran where that is known. */
43
+ export function lineCoverageText(state, count) {
44
+ if (count === undefined || state === 'uncovered')
45
+ return lineStateNames[state];
46
+ return `${lineStateNames[state]}. Ran ${fullCount.format(count)} ${count === 1 ? 'time' : 'times'}`;
47
+ }
48
+ function times(count) {
49
+ return `${fullCount.format(count)} ${count === 1 ? 'time' : 'times'}`;
50
+ }
51
+ /**
52
+ * A declaration line reads as its functions' calls, not as the line's own count: that is how often the module was
53
+ * loaded. Called is covered; never called is red, with no number; where only some of the functions starting on the
54
+ * line ran, it is partial.
55
+ */
56
+ export function callReading(calls) {
57
+ const total = calls.reduce((sum, count) => sum + count, 0);
58
+ const idle = calls.filter(count => count === 0).length;
59
+ if (total === 0)
60
+ return { state: 'uncovered', text: calls.length === 1 ? 'Not called' : `Not called: none of the ${calls.length} functions here ran` };
61
+ if (idle === 0)
62
+ return { state: 'covered', count: total, text: `Called ${times(total)}` };
63
+ return { state: 'partial', count: total, text: `Partly called: ${idle} of the ${calls.length} functions here never ran. Called ${times(total)}` };
64
+ }
65
+ /** The calls of the functions that start on each line. */
66
+ function callsByLine(coverage) {
67
+ const calls = new Map();
68
+ for (const [line, count] of coverage.functionCalls ?? [])
69
+ calls.set(line, [...calls.get(line) ?? [], count]);
70
+ return calls;
71
+ }
72
+ /**
73
+ * What each measured line shows. A line that starts functions shows their calls. Inside a function body a line shows
74
+ * how often it ran. Module-level code runs once per load, so its count says nothing about tests: it keeps its tint and
75
+ * shows no number. A report without function bodies cannot tell the two apart, and every line shows its own count.
76
+ */
77
+ export function lineReadings(coverage) {
78
+ const states = lineStates(coverage);
79
+ const hits = lineHits(coverage);
80
+ const calls = callsByLine(coverage);
81
+ const inBody = new Set();
82
+ eachLine(coverage.functionBodies, line => inBody.add(line));
83
+ const counted = (line) => coverage.functionBodies === undefined || inBody.has(line);
84
+ const readings = new Map();
85
+ for (const [line, state] of states) {
86
+ const count = counted(line) ? hits.get(line) : undefined;
87
+ readings.set(line, { state, ...(count === undefined ? {} : { count }), text: lineCoverageText(state, count) });
88
+ }
89
+ for (const [line, counts] of calls)
90
+ readings.set(line, callReading(counts));
91
+ return readings;
92
+ }
93
+ /** The last line of the gap of codeless, unmeasured lines that starts at `line`. */
94
+ function gapEnd(states, codeless, line) {
95
+ let end = line;
96
+ while (end < codeless.length && !states.has(end + 1) && codeless[end])
97
+ end += 1;
98
+ return end;
99
+ }
100
+ /**
101
+ * The tint a gap of blank and comment lines takes so the strip has no breaks: the state of the measured line above it,
102
+ * which the gap closes, or for a gap at the file's start, of the line below. A gap beside a line that was not measured
103
+ * takes its other neighbour, and one with no measured neighbour stays plain.
104
+ */
105
+ export function bridgeStates(states, codeless) {
106
+ const bridged = new Map();
107
+ let line = 1;
108
+ while (line <= codeless.length) {
109
+ if (states.has(line) || !codeless[line - 1]) {
110
+ line += 1;
111
+ continue;
112
+ }
113
+ const end = gapEnd(states, codeless, line);
114
+ const state = states.get(line - 1) ?? states.get(end + 1);
115
+ if (state)
116
+ for (let at = line; at <= end; at++)
117
+ bridged.set(at, state);
118
+ line = end + 1;
119
+ }
120
+ return bridged;
121
+ }
@@ -0,0 +1,16 @@
1
+ import type { Finding } from '../../json/wire/domain-types.js';
2
+ /** Where a finding points: its primary place first, then the related ones. */
3
+ export interface Location {
4
+ readonly path: string;
5
+ readonly line?: number;
6
+ readonly endLine?: number;
7
+ }
8
+ export declare function allLocations(finding: Finding): readonly Location[];
9
+ /** The distinct files a finding touches. */
10
+ export declare function locationPaths(finding: Finding): Set<string>;
11
+ export declare function atPath(finding: Finding, path: string): boolean;
12
+ export declare function formatLocation(location: Location): string;
13
+ /** How many findings touch each file, a finding with several places in one file counted once. */
14
+ export declare function findingIndex(findings: readonly Finding[]): Map<string, number>;
15
+ /** The line of a file a finding points at, through its related places when its primary one is elsewhere. */
16
+ export declare function lineIn(finding: Finding, path: string): number | undefined;
@@ -0,0 +1,31 @@
1
+ export function allLocations(finding) {
2
+ return [
3
+ ...(finding.path ? [{ path: finding.path, line: finding.line, endLine: finding.endLine }] : []),
4
+ ...(finding.related ?? []),
5
+ ];
6
+ }
7
+ /** The distinct files a finding touches. */
8
+ export function locationPaths(finding) {
9
+ return new Set(allLocations(finding).map(location => location.path));
10
+ }
11
+ export function atPath(finding, path) {
12
+ return finding.path === path || (finding.related?.some(location => location.path === path) ?? false);
13
+ }
14
+ export function formatLocation(location) {
15
+ if (location.line === undefined)
16
+ return location.path;
17
+ const end = location.endLine !== undefined && location.endLine > location.line ? `–${location.endLine}` : '';
18
+ return `${location.path}:${location.line}${end}`;
19
+ }
20
+ /** How many findings touch each file, a finding with several places in one file counted once. */
21
+ export function findingIndex(findings) {
22
+ const index = new Map();
23
+ for (const finding of findings)
24
+ for (const path of locationPaths(finding))
25
+ index.set(path, (index.get(path) ?? 0) + 1);
26
+ return index;
27
+ }
28
+ /** The line of a file a finding points at, through its related places when its primary one is elsewhere. */
29
+ export function lineIn(finding, path) {
30
+ return finding.path === path ? finding.line : finding.related?.find(location => location.path === path)?.line;
31
+ }
@@ -0,0 +1,26 @@
1
+ import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
2
+ import type { HotspotMetric, Metrics } from './viewer-inspection.js';
3
+ /** What a metric is called where files are ranked by it. */
4
+ export declare function rankTitle(metric: HotspotMetric): string;
5
+ export declare function scoreLabel(metric: HotspotMetric): string;
6
+ /** The profile's limits for a metric with a meaningful scale, when they are well formed; otherwise the defaults. */
7
+ export declare function bandLimits(details: Pick<InspectionDetails, 'bands'>, metric: HotspotMetric): readonly number[] | undefined;
8
+ /** What the map's colour shows, said to assistive technology. */
9
+ export declare function meaningOf(metric: HotspotMetric): string;
10
+ /** Maps a score to one of five colour bands: by the profile's limits where the metric has a meaningful scale. */
11
+ export declare function band(entry: Metrics, metric: HotspotMetric, score: number, highest: number, limits?: readonly number[] | undefined): number;
12
+ /** Each file's worst level spread to the folders above it. */
13
+ export declare function spreadLevels(files: ReadonlyMap<string, number>): Map<string, number>;
14
+ /**
15
+ * The top of a relative colour scale, per level: files against files, folders against the folders at their depth. One
16
+ * scale for both would let a folder's sum outshine every file in it, and the map would read hot folders over pale files.
17
+ */
18
+ export declare function relativePeaks(entries: readonly {
19
+ readonly path: string;
20
+ readonly folder: boolean;
21
+ readonly score: number;
22
+ }[]): (path: string, folder: boolean) => number;
23
+ export declare function levelLegend(): HTMLElement;
24
+ export declare function sunburstLegend(metric: HotspotMetric, limits: readonly number[] | undefined): HTMLElement;
25
+ /** The map's colours: grade steps for security, grey for nothing measured, heat where higher is worse, else neutral. */
26
+ export declare function palette(metric: HotspotMetric, levels: boolean, grey: boolean): string;