repometry 0.4.1 → 0.5.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 (190) hide show
  1. package/README.md +4 -0
  2. package/package.json +1 -1
  3. package/target/main/resources/report/json/report-v2.schema.json +13 -1
  4. package/target/main/resources/viewer/files.css +7 -3
  5. package/target/main/resources/viewer/styles.css +2 -2
  6. package/target/main/ts/api/git/git.d.ts +1 -0
  7. package/target/main/ts/api/git/git.js +12 -0
  8. package/target/main/ts/api/git/inspection-source.js +2 -8
  9. package/target/main/ts/api/git/local.d.ts +1 -1
  10. package/target/main/ts/api/git/local.js +39 -5
  11. package/target/main/ts/api/process/docker-tool-runner.d.ts +13 -0
  12. package/target/main/ts/api/process/docker-tool-runner.js +108 -0
  13. package/target/main/ts/api/process/failure.d.ts +1 -0
  14. package/target/main/ts/api/process/failure.js +12 -0
  15. package/target/main/ts/api/process/plugin.d.ts +10 -0
  16. package/target/main/ts/api/process/plugin.js +96 -0
  17. package/target/main/ts/compose/analyze-snapshot.d.ts +3 -2
  18. package/target/main/ts/compose/analyze-snapshot.js +82 -29
  19. package/target/main/ts/compose/inspect.d.ts +5 -0
  20. package/target/main/ts/compose/inspect.js +10 -6
  21. package/target/main/ts/core/engine/execute.d.ts +3 -1
  22. package/target/main/ts/core/engine/execute.js +14 -2
  23. package/target/main/ts/core/engine/operation-cache.d.ts +14 -0
  24. package/target/main/ts/core/engine/operation-cache.js +66 -0
  25. package/target/main/ts/core/engine/plan.d.ts +1 -0
  26. package/target/main/ts/core/engine/plan.js +22 -3
  27. package/target/main/ts/core/engine/plugin.d.ts +8 -1
  28. package/target/main/ts/core/engine/plugin.js +1 -3
  29. package/target/main/ts/core/engine/report-products.js +2 -13
  30. package/target/main/ts/core/model/clone-source.js +1 -1
  31. package/target/main/ts/core/model/code-structure.d.ts +3 -0
  32. package/target/main/ts/core/model/code-structure.js +4 -1
  33. package/target/main/ts/core/model/finding-ignore.js +1 -1
  34. package/target/main/ts/core/model/finding.js +1 -1
  35. package/target/main/ts/core/model/line-coverage.d.ts +5 -1
  36. package/target/main/ts/core/model/line-coverage.js +14 -11
  37. package/target/main/ts/core/model/measurement.js +1 -1
  38. package/target/main/ts/core/model/plugin-data.d.ts +2 -0
  39. package/target/main/ts/core/model/plugin-data.js +15 -1
  40. package/target/main/ts/core/model/quality-summary.js +1 -1
  41. package/target/main/ts/core/model/scanner-import.js +1 -1
  42. package/target/main/ts/core/model/snapshot.d.ts +1 -0
  43. package/target/main/ts/core/model/snapshot.js +5 -1
  44. package/target/main/ts/core/model/source.d.ts +3 -0
  45. package/target/main/ts/core/model/source.js +15 -0
  46. package/target/main/ts/core/ports/tool-runner.d.ts +18 -0
  47. package/target/main/ts/core/ports/tool-runner.js +2 -0
  48. package/target/main/ts/plugin.d.ts +7 -1
  49. package/target/main/ts/plugin.js +3 -1
  50. package/target/main/ts/plugins/coverage/coverage.d.ts +5 -2
  51. package/target/main/ts/plugins/coverage/coverage.js +35 -10
  52. package/target/main/ts/plugins/language-js/function-facts.d.ts +1 -0
  53. package/target/main/ts/plugins/language-js/function-facts.js +30 -4
  54. package/target/main/ts/report/html/app/viewer-chart-bars.d.ts +11 -0
  55. package/target/main/ts/report/html/app/viewer-chart-bars.js +54 -0
  56. package/target/main/ts/report/html/app/viewer-chart-label.d.ts +15 -0
  57. package/target/main/ts/report/html/app/viewer-chart-label.js +43 -0
  58. package/target/main/ts/report/html/app/viewer-chart-line.d.ts +24 -0
  59. package/target/main/ts/report/html/app/viewer-chart-line.js +89 -0
  60. package/target/main/ts/report/html/app/viewer-chart-points.d.ts +49 -0
  61. package/target/main/ts/report/html/app/viewer-chart-points.js +74 -0
  62. package/target/main/ts/report/html/app/viewer-chart-scale.d.ts +21 -0
  63. package/target/main/ts/report/html/app/viewer-chart-scale.js +93 -0
  64. package/target/main/ts/report/html/app/viewer-chart-svg.d.ts +28 -0
  65. package/target/main/ts/report/html/app/viewer-chart-svg.js +41 -0
  66. package/target/main/ts/report/html/app/viewer-chart-time.d.ts +26 -0
  67. package/target/main/ts/report/html/app/viewer-chart-time.js +150 -0
  68. package/target/main/ts/report/html/app/viewer-chart-tip.d.ts +4 -0
  69. package/target/main/ts/report/html/app/viewer-chart-tip.js +210 -0
  70. package/target/main/ts/report/html/app/viewer-chart-x.d.ts +12 -0
  71. package/target/main/ts/report/html/app/viewer-chart-x.js +50 -0
  72. package/target/main/ts/report/html/app/viewer-chart.d.ts +4 -98
  73. package/target/main/ts/report/html/app/viewer-chart.js +16 -677
  74. package/target/main/ts/report/html/app/viewer-code-map.d.ts +27 -0
  75. package/target/main/ts/report/html/app/viewer-code-map.js +175 -0
  76. package/target/main/ts/report/html/app/viewer-columns.d.ts +38 -0
  77. package/target/main/ts/report/html/app/viewer-columns.js +92 -0
  78. package/target/main/ts/report/html/app/viewer-commit-picker.d.ts +12 -0
  79. package/target/main/ts/report/html/app/viewer-commit-picker.js +229 -0
  80. package/target/main/ts/report/html/app/viewer-commits.d.ts +5 -9
  81. package/target/main/ts/report/html/app/viewer-commits.js +17 -216
  82. package/target/main/ts/report/html/app/viewer-controls.d.ts +43 -0
  83. package/target/main/ts/report/html/app/viewer-controls.js +141 -0
  84. package/target/main/ts/report/html/app/viewer-copy.d.ts +17 -0
  85. package/target/main/ts/report/html/app/viewer-copy.js +64 -0
  86. package/target/main/ts/report/html/app/viewer-diagnostics.d.ts +4 -0
  87. package/target/main/ts/report/html/app/viewer-diagnostics.js +60 -0
  88. package/target/main/ts/report/html/app/viewer-dom.d.ts +27 -0
  89. package/target/main/ts/report/html/app/viewer-dom.js +99 -0
  90. package/target/main/ts/report/html/app/viewer-file-aside.d.ts +19 -0
  91. package/target/main/ts/report/html/app/viewer-file-aside.js +124 -0
  92. package/target/main/ts/report/html/app/viewer-file-figures.d.ts +15 -0
  93. package/target/main/ts/report/html/app/viewer-file-figures.js +60 -0
  94. package/target/main/ts/report/html/app/viewer-file-source.d.ts +7 -0
  95. package/target/main/ts/report/html/app/viewer-file-source.js +119 -0
  96. package/target/main/ts/report/html/app/viewer-files.d.ts +2 -118
  97. package/target/main/ts/report/html/app/viewer-files.js +24 -2184
  98. package/target/main/ts/report/html/app/viewer-filter.d.ts +3 -51
  99. package/target/main/ts/report/html/app/viewer-filter.js +111 -450
  100. package/target/main/ts/report/html/app/viewer-hotspots.d.ts +4 -0
  101. package/target/main/ts/report/html/app/viewer-hotspots.js +131 -0
  102. package/target/main/ts/report/html/app/viewer-inspection.d.ts +69 -0
  103. package/target/main/ts/report/html/app/viewer-inspection.js +36 -0
  104. package/target/main/ts/report/html/app/viewer-issue-group.d.ts +27 -0
  105. package/target/main/ts/report/html/app/viewer-issue-group.js +174 -0
  106. package/target/main/ts/report/html/app/viewer-issues.d.ts +4 -0
  107. package/target/main/ts/report/html/app/viewer-issues.js +173 -0
  108. package/target/main/ts/report/html/app/viewer-language-bar.d.ts +9 -0
  109. package/target/main/ts/report/html/app/viewer-language-bar.js +72 -0
  110. package/target/main/ts/report/html/app/viewer-languages.d.ts +27 -0
  111. package/target/main/ts/report/html/app/viewer-languages.js +93 -0
  112. package/target/main/ts/report/html/app/viewer-layout.d.ts +14 -0
  113. package/target/main/ts/report/html/app/viewer-layout.js +134 -0
  114. package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +47 -0
  115. package/target/main/ts/report/html/app/viewer-line-coverage.js +121 -0
  116. package/target/main/ts/report/html/app/viewer-locations.d.ts +16 -0
  117. package/target/main/ts/report/html/app/viewer-locations.js +31 -0
  118. package/target/main/ts/report/html/app/viewer-map-scale.d.ts +26 -0
  119. package/target/main/ts/report/html/app/viewer-map-scale.js +147 -0
  120. package/target/main/ts/report/html/app/viewer-map-shape.d.ts +42 -0
  121. package/target/main/ts/report/html/app/viewer-map-shape.js +102 -0
  122. package/target/main/ts/report/html/app/viewer-metric-format.d.ts +23 -0
  123. package/target/main/ts/report/html/app/viewer-metric-format.js +93 -0
  124. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -20
  125. package/target/main/ts/report/html/app/viewer-metric-registry.js +0 -77
  126. package/target/main/ts/report/html/app/viewer-metrics-view.d.ts +4 -0
  127. package/target/main/ts/report/html/app/viewer-metrics-view.js +162 -0
  128. package/target/main/ts/report/html/app/viewer-metrics.d.ts +6 -1
  129. package/target/main/ts/report/html/app/viewer-metrics.js +53 -35
  130. package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +12 -0
  131. package/target/main/ts/report/html/app/viewer-overview-cards.js +112 -0
  132. package/target/main/ts/report/html/app/viewer-overview-hotspots.d.ts +9 -0
  133. package/target/main/ts/report/html/app/viewer-overview-hotspots.js +173 -0
  134. package/target/main/ts/report/html/app/viewer-overview-lead.d.ts +12 -0
  135. package/target/main/ts/report/html/app/viewer-overview-lead.js +116 -0
  136. package/target/main/ts/report/html/app/viewer-profile-badges.d.ts +11 -0
  137. package/target/main/ts/report/html/app/viewer-profile-badges.js +119 -0
  138. package/target/main/ts/report/html/app/viewer-profile-table.d.ts +29 -0
  139. package/target/main/ts/report/html/app/viewer-profile-table.js +124 -0
  140. package/target/main/ts/report/html/app/viewer-profile.d.ts +2 -6
  141. package/target/main/ts/report/html/app/viewer-profile.js +6 -248
  142. package/target/main/ts/report/html/app/viewer-pull-sections.d.ts +4 -0
  143. package/target/main/ts/report/html/app/viewer-pull-sections.js +118 -0
  144. package/target/main/ts/report/html/app/viewer-pull-trend.d.ts +5 -0
  145. package/target/main/ts/report/html/app/viewer-pull-trend.js +63 -0
  146. package/target/main/ts/report/html/app/viewer-pulls.d.ts +0 -1
  147. package/target/main/ts/report/html/app/viewer-pulls.js +28 -178
  148. package/target/main/ts/report/html/app/viewer-query-field.d.ts +19 -0
  149. package/target/main/ts/report/html/app/viewer-query-field.js +203 -0
  150. package/target/main/ts/report/html/app/viewer-route.d.ts +34 -0
  151. package/target/main/ts/report/html/app/viewer-route.js +55 -0
  152. package/target/main/ts/report/html/app/viewer-shell.d.ts +20 -0
  153. package/target/main/ts/report/html/app/viewer-shell.js +116 -0
  154. package/target/main/ts/report/html/app/viewer-source-view.d.ts +49 -0
  155. package/target/main/ts/report/html/app/viewer-source-view.js +150 -0
  156. package/target/main/ts/report/html/app/viewer-source.d.ts +0 -84
  157. package/target/main/ts/report/html/app/viewer-source.js +7 -363
  158. package/target/main/ts/report/html/app/viewer-suggest.d.ts +13 -0
  159. package/target/main/ts/report/html/app/viewer-suggest.js +91 -0
  160. package/target/main/ts/report/html/app/viewer-sunburst.d.ts +5 -0
  161. package/target/main/ts/report/html/app/viewer-sunburst.js +40 -0
  162. package/target/main/ts/report/html/app/viewer-table-cells.d.ts +25 -0
  163. package/target/main/ts/report/html/app/viewer-table-cells.js +129 -0
  164. package/target/main/ts/report/html/app/viewer-table-rows.d.ts +54 -0
  165. package/target/main/ts/report/html/app/viewer-table-rows.js +95 -0
  166. package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +16 -0
  167. package/target/main/ts/report/html/app/viewer-tokenizer.js +192 -0
  168. package/target/main/ts/report/html/app/viewer-totals.d.ts +14 -0
  169. package/target/main/ts/report/html/app/viewer-totals.js +89 -0
  170. package/target/main/ts/report/html/app/viewer-treemap.d.ts +24 -0
  171. package/target/main/ts/report/html/app/viewer-treemap.js +112 -0
  172. package/target/main/ts/report/html/app/viewer-trend-data.d.ts +49 -0
  173. package/target/main/ts/report/html/app/viewer-trend-data.js +105 -0
  174. package/target/main/ts/report/html/app/viewer-trend-nav.d.ts +5 -0
  175. package/target/main/ts/report/html/app/viewer-trend-nav.js +85 -0
  176. package/target/main/ts/report/html/app/viewer-trend-points.d.ts +30 -0
  177. package/target/main/ts/report/html/app/viewer-trend-points.js +128 -0
  178. package/target/main/ts/report/html/app/viewer-trend-series.d.ts +26 -0
  179. package/target/main/ts/report/html/app/viewer-trend-series.js +98 -0
  180. package/target/main/ts/report/html/app/viewer-trends.d.ts +2 -70
  181. package/target/main/ts/report/html/app/viewer-trends.js +41 -392
  182. package/target/main/ts/report/html/app/viewer.js +152 -663
  183. package/target/main/ts/report/html/site/badges.js +41 -18
  184. package/target/main/ts/report/json/store/local-store.js +2 -12
  185. package/target/main/ts/report/json/store/operation-cache.d.ts +8 -0
  186. package/target/main/ts/report/json/store/operation-cache.js +32 -0
  187. package/target/main/ts/report/json/store/replace-file.d.ts +1 -0
  188. package/target/main/ts/report/json/store/replace-file.js +14 -0
  189. package/target/main/ts/report.d.ts +1 -0
  190. package/target/main/ts/report.js +1 -0
@@ -0,0 +1,129 @@
1
+ import { basename, count, element, link, parentPath } from './viewer-dom.js';
2
+ import { duplicationContext } from './viewer-file-figures.js';
3
+ import { isLockfile, languageColor, languageOf } from './viewer-languages.js';
4
+ const icons = { file: 'fx-file-icon', folder: 'fx-folder-icon', component: 'fx-component-icon' };
5
+ /** In the flat list the folder is context and the file name is the subject; a long folder wraps after a slash. */
6
+ function flatLabel(path) {
7
+ const slash = path.lastIndexOf('/');
8
+ const label = element('span', 'fx-entry-label');
9
+ if (slash >= 0) {
10
+ const folder = element('span', 'fx-entry-folder');
11
+ for (const part of path.slice(0, slash + 1).split(/(?<=\/)/))
12
+ folder.append(part, element('wbr'));
13
+ label.append(folder);
14
+ }
15
+ label.append(element('span', 'fx-entry-name', path.slice(slash + 1)));
16
+ return label;
17
+ }
18
+ /** A component opens as a filter where it can; the files no component holds are only a label. */
19
+ function componentAnchor(path, open) {
20
+ if (!open)
21
+ return element('span', 'fx-entry fx-entry-muted', path);
22
+ return Object.assign(element('button', 'fx-entry fx-entry-button', path), { type: 'button', onclick: open });
23
+ }
24
+ function entryAnchor(row, context, flat, open) {
25
+ const { entry, kind } = row;
26
+ if (kind === 'component')
27
+ return componentAnchor(entry.path, open);
28
+ const target = kind === 'folder' ? { directory: entry.path } : { directory: parentPath(entry.path), file: entry.path };
29
+ const anchor = link(context.linkTo(target), flat ? '' : basename(entry.path), 'fx-entry');
30
+ if (flat)
31
+ anchor.append(flatLabel(entry.path));
32
+ return anchor;
33
+ }
34
+ function entryIcon(row) {
35
+ const icon = element('span', icons[row.kind]);
36
+ icon.setAttribute('aria-hidden', 'true');
37
+ if (row.kind === 'file')
38
+ icon.style.color = isLockfile(row.entry.path) ? 'var(--lockfile)' : languageColor(languageOf(row.entry.path));
39
+ return icon;
40
+ }
41
+ function cell(entry, column) {
42
+ const result = element('td', 'numeric', column.display(entry));
43
+ if (column.value(entry) === 0)
44
+ result.classList.add('fx-zero');
45
+ if (column.label === 'Duplication')
46
+ result.title = duplicationContext(entry) ?? '';
47
+ return result;
48
+ }
49
+ /** One row of the Metrics table: its name, with what it is and how many files it holds, then its figures. */
50
+ export function metricsRow(row, context, open) {
51
+ const { entry, kind } = row;
52
+ const result = element('tr');
53
+ const name = element('th', 'fx-path-column');
54
+ name.scope = 'row';
55
+ const anchor = entryAnchor(row, context, kind === 'file' && context.group !== 'folders', open);
56
+ anchor.prepend(entryIcon(row));
57
+ if (kind !== 'component')
58
+ anchor.setAttribute('title', entry.path);
59
+ if (entry.path === context.selected) {
60
+ anchor.setAttribute('aria-current', 'true');
61
+ result.dataset.selected = '';
62
+ }
63
+ name.append(anchor);
64
+ if (kind === 'file' && isLockfile(entry.path))
65
+ name.append(element('span', 'fx-entry-tag', 'Lockfile'));
66
+ if (kind !== 'file' && 'files' in entry)
67
+ name.append(element('span', 'fx-entry-count', count(entry.files)));
68
+ result.append(name, ...context.columns.map(column => cell(entry, column)));
69
+ return result;
70
+ }
71
+ function counted(total, one, many) {
72
+ return total ? `${count(total)} ${total === 1 ? one : many}` : '';
73
+ }
74
+ /** Names a list as people say it: "a, b and c". */
75
+ export function spokenList(parts) {
76
+ return [parts.slice(0, -1).join(', '), parts.at(-1)].filter(Boolean).join(' and ');
77
+ }
78
+ /** The fold at the end of the list: how many entries no plugin read, opening and closing in place. */
79
+ export function unreadRow(entries, span, expanded, toggle) {
80
+ const lockfiles = entries.filter(row => row.kind === 'file' && isLockfile(row.entry.path)).length;
81
+ const files = entries.filter(row => row.kind === 'file').length - lockfiles;
82
+ const folders = entries.length - files - lockfiles;
83
+ const parts = [counted(lockfiles, 'lockfile', 'lockfiles'), counted(files, 'file', 'files'), counted(folders, 'folder', 'folders')]
84
+ .filter(Boolean);
85
+ const row = element('tr', 'fx-unread');
86
+ const holder = element('td');
87
+ holder.colSpan = span;
88
+ const button = element('button', 'fx-unread-toggle', `${spokenList(parts)} ignored`);
89
+ button.type = 'button';
90
+ button.setAttribute('aria-expanded', String(expanded));
91
+ button.addEventListener('click', toggle);
92
+ holder.append(button);
93
+ row.append(holder);
94
+ return row;
95
+ }
96
+ /** The table with a sort button per column; a click on the sorted column reverses it. */
97
+ export function sortableTable(columns, settings, sorted) {
98
+ const table = element('table', 'fx-table');
99
+ const header = element('tr');
100
+ const thead = element('thead');
101
+ const body = element('tbody');
102
+ const headers = columns.map(({ label }, index) => {
103
+ const th = element('th', index ? 'numeric' : '');
104
+ th.scope = 'col';
105
+ const sort = element('button', 'fx-sort', label);
106
+ sort.type = 'button';
107
+ sort.addEventListener('click', () => {
108
+ settings.ascending = settings.sort === index ? !settings.ascending : index === 0 || (columns[index].ascending ?? false);
109
+ settings.sort = index;
110
+ sorted();
111
+ });
112
+ th.append(sort);
113
+ header.append(th);
114
+ return th;
115
+ });
116
+ thead.append(header);
117
+ table.append(thead, body);
118
+ return { table, headers, body };
119
+ }
120
+ /** Shows the chosen columns' headers and marks the one the table is sorted by. */
121
+ export function markSort(headers, isVisible, settings) {
122
+ headers.forEach((th, index) => {
123
+ th.hidden = !isVisible(index);
124
+ if (index === settings.sort)
125
+ th.setAttribute('aria-sort', settings.ascending ? 'ascending' : 'descending');
126
+ else
127
+ th.removeAttribute('aria-sort');
128
+ });
129
+ }
@@ -0,0 +1,54 @@
1
+ import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
2
+ import type { Directory, Metrics } from './viewer-inspection.js';
3
+ export type Group = 'folders' | 'files' | 'components';
4
+ export type RowKind = 'folder' | 'file' | 'component';
5
+ export interface Row {
6
+ readonly entry: Metrics;
7
+ readonly kind: RowKind;
8
+ }
9
+ /** A row of the table, or the fold that stands for the ignored ones. */
10
+ export type DisplayRow = Row | {
11
+ readonly kind: 'unread';
12
+ };
13
+ /** The component row for the files no component claims: it cannot be opened as a filter. */
14
+ export declare const notInComponent = "Not in a component";
15
+ export declare function isGroup(value: string | undefined): value is Group;
16
+ /** Components, each totalled over the chosen files it holds, and a last row for the chosen files none holds. */
17
+ export declare function componentRows(components: NonNullable<InspectionDetails['components']>, files: readonly Metrics[], filtering: boolean): Row[];
18
+ /** A folder's own listing: the folders right under it with their recorded totals, then its files. */
19
+ export declare function folderRows(directories: readonly Directory[], files: readonly Metrics[], directory: string): Row[];
20
+ /** Filtered folders hold only what passes the query, and their totals count only that. */
21
+ export declare function filteredFolderRows(files: readonly Metrics[], directory: string): Row[];
22
+ /** Sorts in place by a column; sorted by path, folders come before files. */
23
+ export declare function sortRows(rows: Row[], byPath: boolean, value: (entry: Metrics) => string | number | null, ascending: boolean): Row[];
24
+ /**
25
+ * The code comes first, whatever the sort: files no plugin read, and folders holding only such files, fold into one
26
+ * row at the end, open or closed. A query that asks for them (`keep`), or a list of nothing else, shows them as they are.
27
+ */
28
+ export declare function foldUnread(rows: readonly Row[], unreadPaths: ReadonlySet<string>, keep: boolean, expanded: boolean): {
29
+ readonly display: readonly DisplayRow[];
30
+ readonly folded: readonly Row[];
31
+ };
32
+ /**
33
+ * The entries a page shows, 1-based, counting rows and not the fold of ignored files, which takes a place in the list
34
+ * but is no entry of its own. None where the page holds only the fold.
35
+ */
36
+ export declare function entryRange(display: readonly {
37
+ readonly kind: string;
38
+ }[], first: number, shown: number): [number, number] | null;
39
+ export interface ListCounts {
40
+ /** The rows of the list, without the fold. */
41
+ readonly rows: number;
42
+ /** Rows and the fold, as the pages hold them. */
43
+ readonly display: number;
44
+ /** The files the query selected, and the files of the folder it searched. */
45
+ readonly files: number;
46
+ readonly scope: number;
47
+ /** The first and last entry of the page, where the list has pages. */
48
+ readonly range: readonly [number, number] | null;
49
+ }
50
+ /**
51
+ * The line under the table. A filtered file list says how many of the folder's files it kept; other lists name the
52
+ * selection only once. An empty list that a hint explains says nothing more.
53
+ */
54
+ export declare function listSummary(group: Group, counts: ListCounts, filtering: boolean, hinted: boolean): string;
@@ -0,0 +1,95 @@
1
+ import { count, parentPath } from './viewer-dom.js';
2
+ import { compareEntries } from './viewer-file-figures.js';
3
+ import { pageSize } from './viewer-inspection.js';
4
+ import { aggregate } from './viewer-totals.js';
5
+ /** The component row for the files no component claims: it cannot be opened as a filter. */
6
+ export const notInComponent = 'Not in a component';
7
+ export function isGroup(value) {
8
+ return value === 'folders' || value === 'files' || value === 'components';
9
+ }
10
+ const folderRow = (entry) => ({ entry, kind: 'folder' });
11
+ const fileRow = (entry) => ({ entry, kind: 'file' });
12
+ /** Components, each totalled over the chosen files it holds, and a last row for the chosen files none holds. */
13
+ export function componentRows(components, files, filtering) {
14
+ const chosen = new Map(files.map(entry => [entry.path, entry]));
15
+ const rows = components.map(({ component, paths }) => ({
16
+ entry: aggregate(component.name, paths.flatMap(path => chosen.get(path) ?? [])), kind: 'component'
17
+ }))
18
+ .filter(row => !filtering || row.entry.files > 0);
19
+ const assigned = new Set(components.flatMap(({ paths }) => paths));
20
+ const rest = files.filter(entry => !assigned.has(entry.path));
21
+ if (rest.length)
22
+ rows.push({ entry: aggregate(notInComponent, rest), kind: 'component' });
23
+ return rows;
24
+ }
25
+ /** A folder's own listing: the folders right under it with their recorded totals, then its files. */
26
+ export function folderRows(directories, files, directory) {
27
+ return [...directories.filter(entry => entry.path && parentPath(entry.path) === directory).map(folderRow),
28
+ ...files.filter(entry => parentPath(entry.path) === directory).map(fileRow)];
29
+ }
30
+ /** Filtered folders hold only what passes the query, and their totals count only that. */
31
+ export function filteredFolderRows(files, directory) {
32
+ const below = new Map();
33
+ const here = [];
34
+ const prefix = directory ? `${directory}/` : '';
35
+ for (const entry of files) {
36
+ const rest = entry.path.slice(prefix.length);
37
+ const slash = rest.indexOf('/');
38
+ if (slash < 0)
39
+ here.push(entry);
40
+ else {
41
+ const folder = prefix + rest.slice(0, slash);
42
+ below.set(folder, [...below.get(folder) ?? [], entry]);
43
+ }
44
+ }
45
+ return [...[...below].map(([path, entries]) => folderRow(aggregate(path, entries))), ...here.map(fileRow)];
46
+ }
47
+ /** Sorts in place by a column; sorted by path, folders come before files. */
48
+ export function sortRows(rows, byPath, value, ascending) {
49
+ return rows.sort((a, b) => {
50
+ const files = Number(a.kind === 'file') - Number(b.kind === 'file');
51
+ return (byPath ? files : 0) || compareEntries(a.entry, b.entry, value, ascending);
52
+ });
53
+ }
54
+ /**
55
+ * The code comes first, whatever the sort: files no plugin read, and folders holding only such files, fold into one
56
+ * row at the end, open or closed. A query that asks for them (`keep`), or a list of nothing else, shows them as they are.
57
+ */
58
+ export function foldUnread(rows, unreadPaths, keep, expanded) {
59
+ const unread = (row) => row.kind === 'file' ? row.entry.analysed === false : row.kind === 'folder' && unreadPaths.has(row.entry.path);
60
+ const folded = keep ? [] : rows.filter(unread);
61
+ const read = rows.filter(row => !folded.includes(row));
62
+ if (!folded.length || !read.length)
63
+ return { display: rows, folded };
64
+ return { display: [...read, { kind: 'unread' }, ...expanded ? folded : []], folded };
65
+ }
66
+ /**
67
+ * The entries a page shows, 1-based, counting rows and not the fold of ignored files, which takes a place in the list
68
+ * but is no entry of its own. None where the page holds only the fold.
69
+ */
70
+ export function entryRange(display, first, shown) {
71
+ const entries = (from, to) => display.slice(from, to).filter(row => row.kind !== 'unread').length;
72
+ const before = entries(0, first);
73
+ const here = entries(first, first + shown);
74
+ return here ? [before + 1, before + here] : null;
75
+ }
76
+ const nouns = { components: ['component', 'components'], folders: ['entry', 'entries'],
77
+ files: ['file', 'files'] };
78
+ /**
79
+ * The line under the table. A filtered file list says how many of the folder's files it kept; other lists name the
80
+ * selection only once. An empty list that a hint explains says nothing more.
81
+ */
82
+ export function listSummary(group, counts, filtering, hinted) {
83
+ if (counts.rows === 0)
84
+ return hinted ? '' : 'No files match this selection.';
85
+ const [one, many] = nouns[group];
86
+ const paged = counts.display > pageSize;
87
+ const listsFiles = group === 'files' && counts.rows === counts.files;
88
+ const of = filtering && (paged || !listsFiles) ? ` · ${count(counts.files)} of ${count(counts.scope)} files selected` : '';
89
+ const total = `${count(counts.rows)} ${many}${of}`;
90
+ if (paged)
91
+ return counts.range ? `${count(counts.range[0])}–${count(counts.range[1])} of ${total}` : total;
92
+ if (filtering && listsFiles)
93
+ return `${count(counts.rows)} of ${count(counts.scope)} files`;
94
+ return `${count(counts.rows)} ${counts.rows === 1 ? one : many}${of}`;
95
+ }
@@ -0,0 +1,16 @@
1
+ export type TokenKind = '' | 'c' | 's' | 'n' | 'k';
2
+ export type Run = [TokenKind, string];
3
+ /**
4
+ * Splits lines of JavaScript or TypeScript into coloured runs: comments, strings, regular expressions, numbers and
5
+ * keywords. It honours escapes and character classes, and it tells a regular expression from a division by what comes
6
+ * before the slash. State carries across lines, so a block comment or a template literal stays coloured to its end.
7
+ * Other languages come back as plain text.
8
+ */
9
+ export declare function tokenizer(path: string): (line: string) => Run[];
10
+ /** A line with no code: blank, or nothing but comment. */
11
+ export declare function codeless(lineRuns: readonly (readonly [TokenKind, string])[]): boolean;
12
+ /** A line's runs as nodes: coloured spans and plain text. */
13
+ export declare function runNodes(lineRuns: readonly Run[]): Node[];
14
+ export declare function highlighter(path: string): (line: string) => Node[];
15
+ /** A single line of code, coloured as the source view colours it; for a snippet that stands on its own. */
16
+ export declare function highlightCode(path: string, line: string): Node[];
@@ -0,0 +1,192 @@
1
+ // Light highlighting for JavaScript and TypeScript: a scanner, not a parser, that colours comments, strings, regular
2
+ // expressions, numbers and keywords. Other languages come back as plain text.
3
+ import { element } from './viewer-dom.js';
4
+ const keywords = new Set(('abstract as async await break case catch class const continue debugger declare default delete do else enum export '
5
+ + 'extends false finally for from function get if implements import in instanceof interface let new null of package private protected '
6
+ + 'public readonly return satisfies set static super switch this throw true try type typeof undefined var void while with yield').split(' '));
7
+ /** Words after which a slash opens a regular expression rather than divides. */
8
+ const beforeRegex = new Set('return typeof instanceof in of new delete void throw case do else yield await'.split(' '));
9
+ /** Past an escape: the index after the closing quote, or the line's end when it stays open. */
10
+ function closeQuote(line, from, quote) {
11
+ let at = from;
12
+ while (at < line.length && line[at] !== quote)
13
+ at += line[at] === '\\' ? 2 : 1;
14
+ return at < line.length ? [at + 1, true] : [line.length, false];
15
+ }
16
+ /** Takes the run up to `stop` as one token. */
17
+ function take(cursor, kind, stop) {
18
+ cursor.push(kind, cursor.line.slice(cursor.at, stop));
19
+ cursor.at = stop;
20
+ }
21
+ function insideComment(cursor) {
22
+ const end = cursor.line.indexOf('*/', cursor.at);
23
+ take(cursor, 'c', end < 0 ? cursor.line.length : end + 2);
24
+ if (end >= 0)
25
+ cursor.state.open = '';
26
+ }
27
+ function insideTemplate(cursor) {
28
+ const [stop, closed] = closeQuote(cursor.line, cursor.at, '`');
29
+ take(cursor, 's', stop);
30
+ if (!closed)
31
+ return;
32
+ cursor.state.open = '';
33
+ cursor.state.regexAllowed = false;
34
+ }
35
+ /**
36
+ * The end of a regular expression literal that starts at `at`, its flags included, honouring escapes and character
37
+ * classes; -1 where the line has no closing slash, so the slash divides after all.
38
+ */
39
+ function regexEnd(line, at) {
40
+ let end = at + 1;
41
+ let inClass = false;
42
+ while (end < line.length) {
43
+ const current = line[end];
44
+ if (current === '\\') {
45
+ end += 2;
46
+ continue;
47
+ }
48
+ if (current === '/' && !inClass)
49
+ break;
50
+ if (current === '[')
51
+ inClass = true;
52
+ else if (current === ']')
53
+ inClass = false;
54
+ end += 1;
55
+ }
56
+ if (end >= line.length)
57
+ return -1;
58
+ end += 1;
59
+ while (end < line.length && /[a-z]/i.test(line[end]))
60
+ end += 1;
61
+ return end;
62
+ }
63
+ const char = (cursor, offset = 0) => cursor.line[cursor.at + offset];
64
+ /** Where a token can start, tried in order; each takes what it recognises and says whether it did. */
65
+ const starts = [
66
+ function lineComment(cursor) {
67
+ if (char(cursor) !== '/' || char(cursor, 1) !== '/')
68
+ return false;
69
+ take(cursor, 'c', cursor.line.length);
70
+ return true;
71
+ },
72
+ function blockComment(cursor) {
73
+ if (char(cursor) !== '/' || char(cursor, 1) !== '*')
74
+ return false;
75
+ take(cursor, 'c', cursor.at + 2);
76
+ cursor.state.open = 'comment';
77
+ return true;
78
+ },
79
+ function template(cursor) {
80
+ if (char(cursor) !== '`')
81
+ return false;
82
+ take(cursor, 's', cursor.at + 1);
83
+ cursor.state.open = 'template';
84
+ return true;
85
+ },
86
+ function quoted(cursor) {
87
+ const quote = char(cursor);
88
+ if (quote !== '"' && quote !== "'")
89
+ return false;
90
+ take(cursor, 's', closeQuote(cursor.line, cursor.at + 1, quote)[0]);
91
+ cursor.state.regexAllowed = false;
92
+ return true;
93
+ },
94
+ function regex(cursor) {
95
+ if (char(cursor) !== '/' || !cursor.state.regexAllowed)
96
+ return false;
97
+ const end = regexEnd(cursor.line, cursor.at);
98
+ if (end < 0)
99
+ return false;
100
+ take(cursor, 's', end);
101
+ cursor.state.regexAllowed = false;
102
+ return true;
103
+ },
104
+ function word(cursor) {
105
+ const found = /^[A-Za-z_$][\w$]*/.exec(cursor.line.slice(cursor.at))?.[0];
106
+ if (!found)
107
+ return false;
108
+ take(cursor, keywords.has(found) ? 'k' : '', cursor.at + found.length);
109
+ cursor.state.regexAllowed = beforeRegex.has(found);
110
+ return true;
111
+ },
112
+ function number(cursor) {
113
+ const found = /^(?:0x[\da-f_]+n?|\d[\d_]*(?:\.\d[\d_]*)?(?:e[+-]?\d+)?n?)/i.exec(cursor.line.slice(cursor.at))?.[0];
114
+ if (!found)
115
+ return false;
116
+ take(cursor, 'n', cursor.at + found.length);
117
+ cursor.state.regexAllowed = false;
118
+ return true;
119
+ },
120
+ function punctuation(cursor) {
121
+ const found = char(cursor);
122
+ take(cursor, '', cursor.at + 1);
123
+ // After a closing bracket a slash divides; after any other punctuation it opens a regular expression.
124
+ if (!/\s/.test(found))
125
+ cursor.state.regexAllowed = found !== ')' && found !== ']';
126
+ return true;
127
+ },
128
+ ];
129
+ /** Collects a line's runs, joining plain text into one run between coloured ones. */
130
+ function runs() {
131
+ const result = [];
132
+ let plain = '';
133
+ return {
134
+ push(kind, value) {
135
+ if (!value)
136
+ return;
137
+ if (!kind) {
138
+ plain += value;
139
+ return;
140
+ }
141
+ if (plain)
142
+ result.push(['', plain]);
143
+ plain = '';
144
+ result.push([kind, value]);
145
+ },
146
+ done() {
147
+ if (plain)
148
+ result.push(['', plain]);
149
+ return result;
150
+ },
151
+ };
152
+ }
153
+ /**
154
+ * Splits lines of JavaScript or TypeScript into coloured runs: comments, strings, regular expressions, numbers and
155
+ * keywords. It honours escapes and character classes, and it tells a regular expression from a division by what comes
156
+ * before the slash. State carries across lines, so a block comment or a template literal stays coloured to its end.
157
+ * Other languages come back as plain text.
158
+ */
159
+ export function tokenizer(path) {
160
+ if (!/\.(m|c)?[jt]sx?$/.test(path))
161
+ return line => [['', line]];
162
+ const state = { open: '', regexAllowed: true };
163
+ return line => {
164
+ const collected = runs();
165
+ const cursor = { line, at: 0, state, push: collected.push };
166
+ while (cursor.at < line.length) {
167
+ if (state.open === 'comment')
168
+ insideComment(cursor);
169
+ else if (state.open === 'template')
170
+ insideTemplate(cursor);
171
+ else
172
+ starts.find(start => start(cursor));
173
+ }
174
+ return collected.done();
175
+ };
176
+ }
177
+ /** A line with no code: blank, or nothing but comment. */
178
+ export function codeless(lineRuns) {
179
+ return lineRuns.every(([kind, value]) => kind === 'c' || !value.trim());
180
+ }
181
+ /** A line's runs as nodes: coloured spans and plain text. */
182
+ export function runNodes(lineRuns) {
183
+ return lineRuns.map(([kind, value]) => kind ? element('span', `tok-${kind}`, value) : document.createTextNode(value));
184
+ }
185
+ export function highlighter(path) {
186
+ const tokenize = tokenizer(path);
187
+ return line => runNodes(tokenize(line));
188
+ }
189
+ /** A single line of code, coloured as the source view colours it; for a snippet that stands on its own. */
190
+ export function highlightCode(path, line) {
191
+ return highlighter(path)(line);
192
+ }
@@ -0,0 +1,14 @@
1
+ import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
2
+ import type { Directory, Metrics } from './viewer-inspection.js';
3
+ type Read = (entry: Metrics) => number | null | undefined;
4
+ /** The sum of what the files measured; null where none of them did. */
5
+ export declare function sum(files: readonly Metrics[], read: Read): number | null;
6
+ /** Totals for any set of files, measured the way folder totals are: sums, the peak, and ratios of sums. */
7
+ export declare function aggregate(path: string, files: readonly Metrics[]): Directory;
8
+ /** The folders all of whose files are only counted, found in one pass over the files. */
9
+ export declare function unreadFolders(files: readonly Pick<Metrics, 'path' | 'analysed'>[]): Set<string>;
10
+ /** The folders above a path, nearest first. */
11
+ export declare function ancestors(path: string): string[];
12
+ /** Each path's components, by name. */
13
+ export declare function componentIndex(components: NonNullable<InspectionDetails['components']>): Map<string, string[]>;
14
+ export {};
@@ -0,0 +1,89 @@
1
+ import { sized } from './viewer-languages.js';
2
+ import { localCatalog } from './viewer-inspection.js';
3
+ import { rollUp } from './viewer-metric-registry.js';
4
+ /** The sum of what the files measured; null where none of them did. */
5
+ export function sum(files, read) {
6
+ let total = null;
7
+ for (const entry of files) {
8
+ const value = read(entry);
9
+ if (value != null)
10
+ total = (total ?? 0) + value;
11
+ }
12
+ return total;
13
+ }
14
+ function zeroSum(files, read) {
15
+ return sum(files, read) ?? 0;
16
+ }
17
+ /** The quality counts that add up, in the order a folder's totals list them. */
18
+ const qualitySums = [
19
+ ['codeLines', entry => entry.quality?.codeLines],
20
+ ['commentLines', entry => entry.quality?.commentLines],
21
+ ['classes', entry => entry.quality?.classes],
22
+ ['cognitiveComplexity', entry => entry.quality?.cognitiveComplexity],
23
+ ['churn', entry => entry.quality?.churn],
24
+ ];
25
+ function qualityTotals(files) {
26
+ const quality = {};
27
+ for (const [key, read] of qualitySums) {
28
+ const value = sum(files, read);
29
+ if (value !== null)
30
+ quality[key] = value;
31
+ }
32
+ if (files.some(entry => entry.quality?.duplication)) {
33
+ quality.duplication = { duplicatedLines: zeroSum(files, entry => entry.quality?.duplication?.duplicatedLines),
34
+ codeLines: zeroSum(files, entry => entry.quality?.duplication?.codeLines) };
35
+ }
36
+ if (files.some(entry => entry.quality?.maintainability)) {
37
+ quality.maintainability = { smells: zeroSum(files, entry => entry.quality?.maintainability?.smells),
38
+ effortMinutes: sum(files, entry => entry.quality?.maintainability?.effortMinutes) };
39
+ }
40
+ return quality;
41
+ }
42
+ function peakComplexity(files) {
43
+ const peaks = files.flatMap(entry => entry.complexity?.maximum == null ? [] : [entry.complexity.maximum]);
44
+ return peaks.length ? peaks.reduce((max, value) => Math.max(max, value), 0) : null;
45
+ }
46
+ /** Totals for any set of files, measured the way folder totals are: sums, the peak, and ratios of sums. */
47
+ export function aggregate(path, files) {
48
+ const covered = files.filter(entry => entry.lineCoverage);
49
+ const values = rollUp(localCatalog(), files);
50
+ const quality = qualityTotals(files);
51
+ return {
52
+ path, files: files.length, lines: sum(files, entry => entry.lines), functions: sum(files, entry => entry.functions),
53
+ complexity: files.some(entry => entry.complexity) ? { sum: zeroSum(files, entry => entry.complexity?.sum), maximum: peakComplexity(files),
54
+ measuredFunctions: zeroSum(files, entry => entry.complexity?.measuredFunctions) } : null,
55
+ lineCoverage: covered.length ? { covered: zeroSum(files, entry => entry.lineCoverage?.covered),
56
+ total: zeroSum(files, entry => entry.lineCoverage?.total) } : null,
57
+ diagnosticCount: zeroSum(files, entry => entry.diagnosticCount),
58
+ sizeMeasuredFiles: files.filter(entry => entry.lines !== null).length, coverageMeasuredFiles: covered.length,
59
+ ...(Object.keys(quality).length ? { quality } : {}),
60
+ ...(values ? { values } : {}),
61
+ // A partial sum would understate the size: only a scope where every file has one gets a total.
62
+ ...(sized(files) ? { bytes: zeroSum(files, entry => entry.bytes) } : {}),
63
+ };
64
+ }
65
+ /** The folders all of whose files are only counted, found in one pass over the files. */
66
+ export function unreadFolders(files) {
67
+ const read = new Map();
68
+ for (const file of files) {
69
+ const analysed = file.analysed !== false;
70
+ for (const folder of ancestors(file.path))
71
+ read.set(folder, read.get(folder) === true || analysed);
72
+ }
73
+ return new Set([...read].filter(([, analysed]) => !analysed).map(([folder]) => folder));
74
+ }
75
+ /** The folders above a path, nearest first. */
76
+ export function ancestors(path) {
77
+ const folders = [];
78
+ for (let slash = path.lastIndexOf('/'); slash > 0; slash = path.lastIndexOf('/', slash - 1))
79
+ folders.push(path.slice(0, slash));
80
+ return folders;
81
+ }
82
+ /** Each path's components, by name. */
83
+ export function componentIndex(components) {
84
+ const index = new Map();
85
+ for (const { component, paths } of components)
86
+ for (const path of paths)
87
+ index.set(path, [...index.get(path) ?? [], component.name]);
88
+ return index;
89
+ }
@@ -0,0 +1,24 @@
1
+ import type { Branch, MapDraw } from './viewer-map-shape.js';
2
+ export interface Box {
3
+ readonly x: number;
4
+ readonly y: number;
5
+ readonly w: number;
6
+ readonly h: number;
7
+ }
8
+ /**
9
+ * Squarified treemap layout: rows of tiles kept as close to square as the areas allow, largest first, so sizes stay
10
+ * comparable at a glance.
11
+ */
12
+ export declare function squarify(children: readonly Branch[], room: Box): {
13
+ branch: Branch;
14
+ box: Box;
15
+ }[];
16
+ /** A label cut to the room it has, at about six pixels a character. */
17
+ export declare function fit(text: string, room: number): string;
18
+ /** A chain of folders that each hold one folder is one frame: src/main/ts/ rather than three nested ones. */
19
+ export declare function collapseChain(byParent: ReadonlyMap<string, readonly Branch[]>, branch: Branch): {
20
+ name: string;
21
+ inner: readonly Branch[];
22
+ };
23
+ /** The tree as tiles: folders frame their contents under a name strip, files fill the space by size. */
24
+ export declare function drawTiles(map: MapDraw, children: readonly Branch[], room: Box, level: number): void;