repometry 0.4.2 → 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.
- package/README.md +4 -0
- package/package.json +1 -1
- package/target/main/resources/report/json/report-v2.schema.json +13 -1
- package/target/main/resources/viewer/styles.css +2 -2
- package/target/main/ts/api/git/git.d.ts +1 -0
- package/target/main/ts/api/git/git.js +12 -0
- package/target/main/ts/api/git/inspection-source.js +2 -8
- package/target/main/ts/api/git/local.d.ts +1 -1
- package/target/main/ts/api/git/local.js +39 -5
- package/target/main/ts/api/process/docker-tool-runner.d.ts +13 -0
- package/target/main/ts/api/process/docker-tool-runner.js +108 -0
- package/target/main/ts/api/process/failure.d.ts +1 -0
- package/target/main/ts/api/process/failure.js +12 -0
- package/target/main/ts/api/process/plugin.d.ts +10 -0
- package/target/main/ts/api/process/plugin.js +96 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +3 -2
- package/target/main/ts/compose/analyze-snapshot.js +82 -29
- package/target/main/ts/compose/inspect.d.ts +5 -0
- package/target/main/ts/compose/inspect.js +10 -6
- package/target/main/ts/core/engine/execute.d.ts +3 -1
- package/target/main/ts/core/engine/execute.js +14 -2
- package/target/main/ts/core/engine/operation-cache.d.ts +14 -0
- package/target/main/ts/core/engine/operation-cache.js +66 -0
- package/target/main/ts/core/engine/plan.d.ts +1 -0
- package/target/main/ts/core/engine/plan.js +22 -3
- package/target/main/ts/core/engine/plugin.d.ts +8 -1
- package/target/main/ts/core/engine/plugin.js +1 -3
- package/target/main/ts/core/engine/report-products.js +2 -13
- package/target/main/ts/core/model/clone-source.js +1 -1
- package/target/main/ts/core/model/code-structure.d.ts +3 -0
- package/target/main/ts/core/model/code-structure.js +4 -1
- package/target/main/ts/core/model/finding-ignore.js +1 -1
- package/target/main/ts/core/model/finding.js +1 -1
- package/target/main/ts/core/model/line-coverage.d.ts +5 -1
- package/target/main/ts/core/model/line-coverage.js +14 -11
- package/target/main/ts/core/model/measurement.js +1 -1
- package/target/main/ts/core/model/plugin-data.d.ts +2 -0
- package/target/main/ts/core/model/plugin-data.js +15 -1
- package/target/main/ts/core/model/quality-summary.js +1 -1
- package/target/main/ts/core/model/scanner-import.js +1 -1
- package/target/main/ts/core/model/snapshot.d.ts +1 -0
- package/target/main/ts/core/model/snapshot.js +5 -1
- package/target/main/ts/core/model/source.d.ts +3 -0
- package/target/main/ts/core/model/source.js +15 -0
- package/target/main/ts/core/ports/tool-runner.d.ts +18 -0
- package/target/main/ts/core/ports/tool-runner.js +2 -0
- package/target/main/ts/plugin.d.ts +7 -1
- package/target/main/ts/plugin.js +3 -1
- package/target/main/ts/plugins/coverage/coverage.d.ts +5 -2
- package/target/main/ts/plugins/coverage/coverage.js +35 -10
- package/target/main/ts/plugins/language-js/function-facts.d.ts +1 -0
- package/target/main/ts/plugins/language-js/function-facts.js +30 -4
- package/target/main/ts/report/html/app/viewer-chart-bars.d.ts +11 -0
- package/target/main/ts/report/html/app/viewer-chart-bars.js +54 -0
- package/target/main/ts/report/html/app/viewer-chart-label.d.ts +15 -0
- package/target/main/ts/report/html/app/viewer-chart-label.js +43 -0
- package/target/main/ts/report/html/app/viewer-chart-line.d.ts +24 -0
- package/target/main/ts/report/html/app/viewer-chart-line.js +89 -0
- package/target/main/ts/report/html/app/viewer-chart-points.d.ts +49 -0
- package/target/main/ts/report/html/app/viewer-chart-points.js +74 -0
- package/target/main/ts/report/html/app/viewer-chart-scale.d.ts +21 -0
- package/target/main/ts/report/html/app/viewer-chart-scale.js +93 -0
- package/target/main/ts/report/html/app/viewer-chart-svg.d.ts +28 -0
- package/target/main/ts/report/html/app/viewer-chart-svg.js +41 -0
- package/target/main/ts/report/html/app/viewer-chart-time.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-chart-time.js +150 -0
- package/target/main/ts/report/html/app/viewer-chart-tip.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-chart-tip.js +210 -0
- package/target/main/ts/report/html/app/viewer-chart-x.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-chart-x.js +50 -0
- package/target/main/ts/report/html/app/viewer-chart.d.ts +4 -98
- package/target/main/ts/report/html/app/viewer-chart.js +16 -677
- package/target/main/ts/report/html/app/viewer-code-map.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-code-map.js +175 -0
- package/target/main/ts/report/html/app/viewer-columns.d.ts +38 -0
- package/target/main/ts/report/html/app/viewer-columns.js +92 -0
- package/target/main/ts/report/html/app/viewer-commit-picker.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-commit-picker.js +229 -0
- package/target/main/ts/report/html/app/viewer-commits.d.ts +5 -9
- package/target/main/ts/report/html/app/viewer-commits.js +17 -216
- package/target/main/ts/report/html/app/viewer-controls.d.ts +43 -0
- package/target/main/ts/report/html/app/viewer-controls.js +141 -0
- package/target/main/ts/report/html/app/viewer-copy.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-copy.js +64 -0
- package/target/main/ts/report/html/app/viewer-diagnostics.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-diagnostics.js +60 -0
- package/target/main/ts/report/html/app/viewer-dom.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-dom.js +99 -0
- package/target/main/ts/report/html/app/viewer-file-aside.d.ts +19 -0
- package/target/main/ts/report/html/app/viewer-file-aside.js +124 -0
- package/target/main/ts/report/html/app/viewer-file-figures.d.ts +15 -0
- package/target/main/ts/report/html/app/viewer-file-figures.js +60 -0
- package/target/main/ts/report/html/app/viewer-file-source.d.ts +7 -0
- package/target/main/ts/report/html/app/viewer-file-source.js +119 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +2 -118
- package/target/main/ts/report/html/app/viewer-files.js +24 -2184
- package/target/main/ts/report/html/app/viewer-filter.d.ts +3 -51
- package/target/main/ts/report/html/app/viewer-filter.js +111 -450
- package/target/main/ts/report/html/app/viewer-hotspots.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-hotspots.js +131 -0
- package/target/main/ts/report/html/app/viewer-inspection.d.ts +69 -0
- package/target/main/ts/report/html/app/viewer-inspection.js +36 -0
- package/target/main/ts/report/html/app/viewer-issue-group.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-issue-group.js +174 -0
- package/target/main/ts/report/html/app/viewer-issues.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-issues.js +173 -0
- package/target/main/ts/report/html/app/viewer-language-bar.d.ts +9 -0
- package/target/main/ts/report/html/app/viewer-language-bar.js +72 -0
- package/target/main/ts/report/html/app/viewer-languages.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-languages.js +93 -0
- package/target/main/ts/report/html/app/viewer-layout.d.ts +14 -0
- package/target/main/ts/report/html/app/viewer-layout.js +134 -0
- package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +47 -0
- package/target/main/ts/report/html/app/viewer-line-coverage.js +121 -0
- package/target/main/ts/report/html/app/viewer-locations.d.ts +16 -0
- package/target/main/ts/report/html/app/viewer-locations.js +31 -0
- package/target/main/ts/report/html/app/viewer-map-scale.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-map-scale.js +147 -0
- package/target/main/ts/report/html/app/viewer-map-shape.d.ts +42 -0
- package/target/main/ts/report/html/app/viewer-map-shape.js +102 -0
- package/target/main/ts/report/html/app/viewer-metric-format.d.ts +23 -0
- package/target/main/ts/report/html/app/viewer-metric-format.js +93 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -20
- package/target/main/ts/report/html/app/viewer-metric-registry.js +0 -77
- package/target/main/ts/report/html/app/viewer-metrics-view.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-metrics-view.js +162 -0
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +6 -1
- package/target/main/ts/report/html/app/viewer-metrics.js +53 -35
- package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-overview-cards.js +112 -0
- package/target/main/ts/report/html/app/viewer-overview-hotspots.d.ts +9 -0
- package/target/main/ts/report/html/app/viewer-overview-hotspots.js +173 -0
- package/target/main/ts/report/html/app/viewer-overview-lead.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-overview-lead.js +116 -0
- package/target/main/ts/report/html/app/viewer-profile-badges.d.ts +11 -0
- package/target/main/ts/report/html/app/viewer-profile-badges.js +119 -0
- package/target/main/ts/report/html/app/viewer-profile-table.d.ts +29 -0
- package/target/main/ts/report/html/app/viewer-profile-table.js +124 -0
- package/target/main/ts/report/html/app/viewer-profile.d.ts +2 -6
- package/target/main/ts/report/html/app/viewer-profile.js +6 -248
- package/target/main/ts/report/html/app/viewer-pull-sections.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-pull-sections.js +118 -0
- package/target/main/ts/report/html/app/viewer-pull-trend.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-pull-trend.js +63 -0
- package/target/main/ts/report/html/app/viewer-pulls.d.ts +0 -1
- package/target/main/ts/report/html/app/viewer-pulls.js +28 -178
- package/target/main/ts/report/html/app/viewer-query-field.d.ts +19 -0
- package/target/main/ts/report/html/app/viewer-query-field.js +203 -0
- package/target/main/ts/report/html/app/viewer-route.d.ts +34 -0
- package/target/main/ts/report/html/app/viewer-route.js +55 -0
- package/target/main/ts/report/html/app/viewer-shell.d.ts +20 -0
- package/target/main/ts/report/html/app/viewer-shell.js +116 -0
- package/target/main/ts/report/html/app/viewer-source-view.d.ts +49 -0
- package/target/main/ts/report/html/app/viewer-source-view.js +150 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +0 -84
- package/target/main/ts/report/html/app/viewer-source.js +7 -365
- package/target/main/ts/report/html/app/viewer-suggest.d.ts +13 -0
- package/target/main/ts/report/html/app/viewer-suggest.js +91 -0
- package/target/main/ts/report/html/app/viewer-sunburst.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-sunburst.js +40 -0
- package/target/main/ts/report/html/app/viewer-table-cells.d.ts +25 -0
- package/target/main/ts/report/html/app/viewer-table-cells.js +129 -0
- package/target/main/ts/report/html/app/viewer-table-rows.d.ts +54 -0
- package/target/main/ts/report/html/app/viewer-table-rows.js +95 -0
- package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +16 -0
- package/target/main/ts/report/html/app/viewer-tokenizer.js +192 -0
- package/target/main/ts/report/html/app/viewer-totals.d.ts +14 -0
- package/target/main/ts/report/html/app/viewer-totals.js +89 -0
- package/target/main/ts/report/html/app/viewer-treemap.d.ts +24 -0
- package/target/main/ts/report/html/app/viewer-treemap.js +112 -0
- package/target/main/ts/report/html/app/viewer-trend-data.d.ts +49 -0
- package/target/main/ts/report/html/app/viewer-trend-data.js +105 -0
- package/target/main/ts/report/html/app/viewer-trend-nav.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-trend-nav.js +85 -0
- package/target/main/ts/report/html/app/viewer-trend-points.d.ts +30 -0
- package/target/main/ts/report/html/app/viewer-trend-points.js +128 -0
- package/target/main/ts/report/html/app/viewer-trend-series.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-trend-series.js +98 -0
- package/target/main/ts/report/html/app/viewer-trends.d.ts +2 -70
- package/target/main/ts/report/html/app/viewer-trends.js +41 -392
- package/target/main/ts/report/html/app/viewer.js +152 -663
- package/target/main/ts/report/json/store/local-store.js +2 -12
- package/target/main/ts/report/json/store/operation-cache.d.ts +8 -0
- package/target/main/ts/report/json/store/operation-cache.js +32 -0
- package/target/main/ts/report/json/store/replace-file.d.ts +1 -0
- package/target/main/ts/report/json/store/replace-file.js +14 -0
- package/target/main/ts/report.d.ts +1 -0
- package/target/main/ts/report.js +1 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { byId, count } from './viewer-dom.js';
|
|
2
|
+
import { labelOf } from './viewer-metrics.js';
|
|
3
|
+
import { href, pages } from './viewer-route.js';
|
|
4
|
+
import { charted, stableWindow } from './viewer-trend-data.js';
|
|
5
|
+
import { seriesPoints, trendLegend } from './viewer-trend-points.js';
|
|
6
|
+
import { renderSeries } from './viewer-trend-series.js';
|
|
7
|
+
/** The area the Overview opens on: maintainability where it was measured, else coverage, else complexity. */
|
|
8
|
+
export function firstArea({ reports, quality }) {
|
|
9
|
+
if (reports.some(report => quality[report.sha]?.maintainability?.debtRatio != null))
|
|
10
|
+
return 'debt';
|
|
11
|
+
return reports.some(report => report.lineCoverage !== null) ? 'coverage' : 'complexity';
|
|
12
|
+
}
|
|
13
|
+
/** The Overview's quality tabs: one selected and focusable, the arrows moving between the visible ones. */
|
|
14
|
+
export function verdictTabs(select) {
|
|
15
|
+
const verdicts = document.querySelectorAll('.verdict-tab');
|
|
16
|
+
const mark = (chosen) => {
|
|
17
|
+
for (const verdict of verdicts) {
|
|
18
|
+
const selected = verdict.dataset.metric === chosen;
|
|
19
|
+
verdict.setAttribute('aria-selected', String(selected));
|
|
20
|
+
verdict.tabIndex = selected ? 0 : -1;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
for (const verdict of verdicts) {
|
|
24
|
+
verdict.addEventListener('click', () => {
|
|
25
|
+
const metric = verdict.dataset.metric;
|
|
26
|
+
mark(metric);
|
|
27
|
+
select(metric);
|
|
28
|
+
});
|
|
29
|
+
verdict.addEventListener('keydown', event => {
|
|
30
|
+
if (event.key !== 'ArrowRight' && event.key !== 'ArrowLeft')
|
|
31
|
+
return;
|
|
32
|
+
const visible = [...verdicts].filter(item => !item.closest('.verdict').hidden);
|
|
33
|
+
const next = visible[(visible.indexOf(verdict) + (event.key === 'ArrowRight' ? 1 : -1) + visible.length) % visible.length];
|
|
34
|
+
next.focus();
|
|
35
|
+
next.click();
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return mark;
|
|
39
|
+
}
|
|
40
|
+
export function showTab(page, visible) {
|
|
41
|
+
const tab = document.querySelector(`#navigation a[data-page="${page}"]`);
|
|
42
|
+
if (tab)
|
|
43
|
+
tab.hidden = !visible;
|
|
44
|
+
}
|
|
45
|
+
/** Tabs follow the code: pages with nothing to show leave the bar, and issues and diagnostics carry their count. */
|
|
46
|
+
export function updateTabs(page, findings, diagnostics) {
|
|
47
|
+
byId('issues-count').textContent = count(findings);
|
|
48
|
+
byId('diagnostics-count').textContent = count(diagnostics);
|
|
49
|
+
showTab('diagnostics', diagnostics > 0 || page === 'diagnostics');
|
|
50
|
+
}
|
|
51
|
+
export function updateDetailsTabs(page, details) {
|
|
52
|
+
updateTabs(page, details.findings?.length ?? 0, details.diagnostics.length);
|
|
53
|
+
}
|
|
54
|
+
/** Shows the route's page and points the navigation at its commit; focus follows a page change made from the page. */
|
|
55
|
+
export function showPage(current) {
|
|
56
|
+
const previousPage = pages.find(page => !byId(page).hidden);
|
|
57
|
+
const focusWasInPage = previousPage !== undefined && byId(previousPage).contains(document.activeElement);
|
|
58
|
+
byId('inspection-meta').hidden = current.page === 'pulls';
|
|
59
|
+
for (const page of pages)
|
|
60
|
+
byId(page).hidden = page !== current.page;
|
|
61
|
+
if (previousPage && previousPage !== current.page) {
|
|
62
|
+
window.scrollTo({ top: 0 });
|
|
63
|
+
if (focusWasInPage) {
|
|
64
|
+
const section = byId(current.page);
|
|
65
|
+
section.tabIndex = -1;
|
|
66
|
+
section.focus({ preventScroll: true });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const link of document.querySelectorAll('#navigation a')) {
|
|
70
|
+
const page = link.dataset.page;
|
|
71
|
+
link.href = href({ page, sha: current.sha });
|
|
72
|
+
if (page === current.page)
|
|
73
|
+
link.setAttribute('aria-current', 'page');
|
|
74
|
+
else
|
|
75
|
+
link.removeAttribute('aria-current');
|
|
76
|
+
}
|
|
77
|
+
document.querySelector('.brand').href = href({ page: 'overview', sha: current.sha });
|
|
78
|
+
}
|
|
79
|
+
export function renderTrend(data, selected, metric, compact) {
|
|
80
|
+
// Enough inspections to show a curve, not a pair of dots; the Trends page holds the whole history.
|
|
81
|
+
const size = compact ? 24 : 60;
|
|
82
|
+
const { start, end } = stableWindow(data.reports, data.reports.indexOf(selected), size, 'overview');
|
|
83
|
+
const shown = charted(data.reports.slice(start, end).reverse());
|
|
84
|
+
const link = (sha) => href({ page: 'overview', sha });
|
|
85
|
+
const chart = byId('chart');
|
|
86
|
+
const hasData = renderSeries({ chart, key: byId('trend-key'), data, shown, metric, selected: selected.sha, link }, { compact, height: compact ? undefined : 296, labelCurrent: false });
|
|
87
|
+
chart.hidden = !hasData;
|
|
88
|
+
byId('trend-empty').hidden = hasData;
|
|
89
|
+
// With no chart, its empty line is the panel's one statement: no key, no reading notes, no second "not measured".
|
|
90
|
+
byId('trend').dataset.empty = String(!hasData);
|
|
91
|
+
const points = seriesPoints(data, shown, metric, selected.sha, link);
|
|
92
|
+
// The figures under the chart state the value and its change, so the chart is named for screen readers only.
|
|
93
|
+
byId('trend-title').textContent = `${labelOf(metric)} by commit`;
|
|
94
|
+
const legend = trendLegend(points);
|
|
95
|
+
byId('trend-detail').textContent = legend;
|
|
96
|
+
byId('trend-detail').hidden = legend === '' || !hasData;
|
|
97
|
+
}
|
|
98
|
+
export async function readOptional(path) {
|
|
99
|
+
try {
|
|
100
|
+
const response = await fetch(path);
|
|
101
|
+
if (!response.ok)
|
|
102
|
+
throw new Error(`Could not read ${path}`);
|
|
103
|
+
return await response.json();
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** The project's name, where the export gives one, in the tab and the header. */
|
|
110
|
+
export function showTitle() {
|
|
111
|
+
const title = document.querySelector('meta[name="repometry-project"]')?.content.trim();
|
|
112
|
+
if (!title)
|
|
113
|
+
return;
|
|
114
|
+
document.title = `${title} · Repometry`;
|
|
115
|
+
byId('project-name').textContent = title;
|
|
116
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { LineReading, SourceLayer } from './viewer-line-coverage.js';
|
|
2
|
+
export interface SourceFunction {
|
|
3
|
+
readonly line: number;
|
|
4
|
+
readonly complexity: number;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SourceNote {
|
|
8
|
+
readonly line: number;
|
|
9
|
+
readonly level: string;
|
|
10
|
+
readonly title: string;
|
|
11
|
+
readonly message: string;
|
|
12
|
+
}
|
|
13
|
+
export interface SourceOptions {
|
|
14
|
+
readonly path: string;
|
|
15
|
+
readonly functions: readonly SourceFunction[];
|
|
16
|
+
readonly notes: readonly SourceNote[];
|
|
17
|
+
/** What each measured line's gutter shows, where the file has a coverage report. */
|
|
18
|
+
readonly coverage?: ReadonlyMap<number, LineReading> | undefined;
|
|
19
|
+
/** What the lines show first; the view switches it with setSourceLayer. */
|
|
20
|
+
readonly layer?: SourceLayer | undefined;
|
|
21
|
+
/** The line to bring into view and mark, from the URL. */
|
|
22
|
+
readonly line?: number | undefined;
|
|
23
|
+
/** Called when a line number is chosen, so the page can put it in the URL. */
|
|
24
|
+
readonly choose: (line: number) => void;
|
|
25
|
+
}
|
|
26
|
+
/** The source as numbered lines; returns a function that brings a line into view and marks it. */
|
|
27
|
+
export declare function renderSource(container: HTMLElement, text: string, options: SourceOptions): (line: number) => void;
|
|
28
|
+
export interface ExcerptOptions {
|
|
29
|
+
readonly path: string;
|
|
30
|
+
/** The flagged range; the excerpt shows its head with a line of context before it. */
|
|
31
|
+
readonly line: number;
|
|
32
|
+
readonly endLine?: number | undefined;
|
|
33
|
+
/** Where the rest of a long range opens in full. */
|
|
34
|
+
readonly more?: ((line: number) => string) | undefined;
|
|
35
|
+
readonly size?: number;
|
|
36
|
+
}
|
|
37
|
+
/** The lines an excerpt shows, `from` to `to`, and the last line of the flagged range, which may lie past them. */
|
|
38
|
+
export declare function excerptRange(lineCount: number, options: Pick<ExcerptOptions, 'line' | 'endLine' | 'size'>): {
|
|
39
|
+
from: number;
|
|
40
|
+
to: number;
|
|
41
|
+
end: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A few lines of source around a finding, bounded so a 160-line function stays a card: one line of context,
|
|
45
|
+
* the head of the flagged range marked, then a link to the rest.
|
|
46
|
+
*/
|
|
47
|
+
export declare function renderExcerpt(text: string, options: ExcerptOptions): HTMLElement;
|
|
48
|
+
/** The first code on a line, trimmed: a name for an anonymous function that says which one it is. */
|
|
49
|
+
export declare function lineSnippet(text: string, line: number, limit?: number): string | null;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// A file's source as numbered lines, lightly highlighted, with the inspection's findings and function complexity laid
|
|
2
|
+
// on the lines they describe, or the tests' coverage in the gutter; and the short excerpt a finding shows.
|
|
3
|
+
import { element } from './viewer-dom.js';
|
|
4
|
+
import { bridgeStates, hitLabel } from './viewer-line-coverage.js';
|
|
5
|
+
import { codeless, highlighter, runNodes, tokenizer } from './viewer-tokenizer.js';
|
|
6
|
+
function sourceLines(text) {
|
|
7
|
+
return text.replace(/\r\n?/g, '\n').replace(/\n$/, '').split('\n');
|
|
8
|
+
}
|
|
9
|
+
/** A function's complexity at its first line, in one of four bands: from 5, 10 and 20 up. */
|
|
10
|
+
function complexityBadge(start) {
|
|
11
|
+
const band = [5, 10, 20].filter(limit => start.complexity >= limit).length;
|
|
12
|
+
const badge = element('span', `src-complexity src-band-${band}`, String(start.complexity));
|
|
13
|
+
badge.title = `Cyclomatic complexity ${start.complexity}`;
|
|
14
|
+
return badge;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The coverage layer tints each measured line's gutter cell and writes in it how often the line ran, or a function was
|
|
18
|
+
* called; a miss's red says it. Nothing runs on a blank or comment line: where a tool counts one anyway, or it sits
|
|
19
|
+
* inside a run of one state, it keeps the strip's tint and says nothing.
|
|
20
|
+
*/
|
|
21
|
+
function coverageCell(own, bridged, runs) {
|
|
22
|
+
const state = own?.state ?? bridged;
|
|
23
|
+
if (!state)
|
|
24
|
+
return [];
|
|
25
|
+
if (!own || codeless(runs)) {
|
|
26
|
+
const silent = element('span', `src-cov src-cov-mark-${state}`);
|
|
27
|
+
silent.setAttribute('aria-hidden', 'true');
|
|
28
|
+
return [silent];
|
|
29
|
+
}
|
|
30
|
+
const cell = element('span', `src-cov src-cov-mark-${state}`, own.count === undefined || state === 'uncovered' ? '' : hitLabel(own.count));
|
|
31
|
+
cell.setAttribute('role', 'img');
|
|
32
|
+
cell.setAttribute('aria-label', own.text);
|
|
33
|
+
cell.title = own.text;
|
|
34
|
+
return [cell];
|
|
35
|
+
}
|
|
36
|
+
function noteBox(note) {
|
|
37
|
+
const box = element('div', `src-note src-note-${note.level}`);
|
|
38
|
+
box.append(element('strong', '', note.title), element('span', '', note.message));
|
|
39
|
+
return box;
|
|
40
|
+
}
|
|
41
|
+
/** The source as numbered lines; returns a function that brings a line into view and marks it. */
|
|
42
|
+
export function renderSource(container, text, options) {
|
|
43
|
+
const lines = sourceLines(text);
|
|
44
|
+
// Tokenized up front, in order, since a comment's state carries from line to line.
|
|
45
|
+
const tokenize = tokenizer(options.path);
|
|
46
|
+
const tokens = lines.map(line => tokenize(line));
|
|
47
|
+
const states = new Map([...options.coverage ?? []].map(([line, reading]) => [line, reading.state]));
|
|
48
|
+
const bridged = options.coverage ? bridgeStates(states, tokens.map(codeless)) : new Map();
|
|
49
|
+
const starts = new Map(options.functions.map(entry => [entry.line, entry]));
|
|
50
|
+
const notes = new Map();
|
|
51
|
+
for (const note of options.notes)
|
|
52
|
+
notes.set(note.line, [...notes.get(note.line) ?? [], note]);
|
|
53
|
+
const code = element('div', 'src');
|
|
54
|
+
code.dataset.layer = options.layer ?? 'issues';
|
|
55
|
+
code.setAttribute('role', 'region');
|
|
56
|
+
code.setAttribute('aria-label', `Source of ${options.path}`);
|
|
57
|
+
const rows = [];
|
|
58
|
+
const fragment = document.createDocumentFragment();
|
|
59
|
+
function reveal(line, scroll = true) {
|
|
60
|
+
for (const row of code.querySelectorAll('.src-target'))
|
|
61
|
+
row.classList.remove('src-target');
|
|
62
|
+
const row = rows[line - 1];
|
|
63
|
+
if (!row)
|
|
64
|
+
return;
|
|
65
|
+
row.classList.add('src-target');
|
|
66
|
+
if (scroll)
|
|
67
|
+
row.scrollIntoView({ block: 'center' });
|
|
68
|
+
}
|
|
69
|
+
function lineRow(number, runs) {
|
|
70
|
+
const row = element('div', 'src-line');
|
|
71
|
+
row.id = `L${number}`;
|
|
72
|
+
const mark = element('span', 'src-mark');
|
|
73
|
+
const start = starts.get(number);
|
|
74
|
+
if (start)
|
|
75
|
+
mark.append(complexityBadge(start));
|
|
76
|
+
mark.append(...coverageCell(options.coverage?.get(number), bridged.get(number), runs));
|
|
77
|
+
const anchor = element('a', 'src-number', String(number));
|
|
78
|
+
anchor.href = `#L${number}`;
|
|
79
|
+
anchor.addEventListener('click', event => {
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
reveal(number, false);
|
|
82
|
+
options.choose(number);
|
|
83
|
+
});
|
|
84
|
+
const content = element('code', 'src-code');
|
|
85
|
+
content.append(...runNodes(runs));
|
|
86
|
+
if (notes.has(number))
|
|
87
|
+
row.classList.add('src-flagged');
|
|
88
|
+
row.append(mark, anchor, content);
|
|
89
|
+
return row;
|
|
90
|
+
}
|
|
91
|
+
for (const [index, runs] of tokens.entries()) {
|
|
92
|
+
const row = lineRow(index + 1, runs);
|
|
93
|
+
rows.push(row);
|
|
94
|
+
fragment.append(row, ...(notes.get(index + 1) ?? []).map(noteBox));
|
|
95
|
+
}
|
|
96
|
+
rows[0]?.classList.add('src-first');
|
|
97
|
+
rows.at(-1)?.classList.add('src-last');
|
|
98
|
+
code.append(fragment);
|
|
99
|
+
container.replaceChildren(code);
|
|
100
|
+
if (options.line)
|
|
101
|
+
requestAnimationFrame(() => reveal(options.line));
|
|
102
|
+
return reveal;
|
|
103
|
+
}
|
|
104
|
+
/** The lines an excerpt shows, `from` to `to`, and the last line of the flagged range, which may lie past them. */
|
|
105
|
+
export function excerptRange(lineCount, options) {
|
|
106
|
+
const end = Math.min(lineCount, Math.max(options.line, options.endLine ?? options.line));
|
|
107
|
+
const from = Math.max(1, options.line - 1);
|
|
108
|
+
const to = Math.min(end, from + (options.size ?? 6) - 1, lineCount);
|
|
109
|
+
return { from, to, end };
|
|
110
|
+
}
|
|
111
|
+
/** The rest of a long range, as a link where the page can open it. */
|
|
112
|
+
function moreLines(end, to, more) {
|
|
113
|
+
const hidden = end - to;
|
|
114
|
+
const rest = element(more ? 'a' : 'span', 'src-more', `⋯ ${hidden} more ${hidden === 1 ? 'line' : 'lines'}, to line ${end}`);
|
|
115
|
+
if (more && rest instanceof HTMLAnchorElement)
|
|
116
|
+
rest.href = more(to + 1);
|
|
117
|
+
return rest;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* A few lines of source around a finding, bounded so a 160-line function stays a card: one line of context,
|
|
121
|
+
* the head of the flagged range marked, then a link to the rest.
|
|
122
|
+
*/
|
|
123
|
+
export function renderExcerpt(text, options) {
|
|
124
|
+
const lines = sourceLines(text);
|
|
125
|
+
const { from, to, end } = excerptRange(lines.length, options);
|
|
126
|
+
const highlight = highlighter(options.path);
|
|
127
|
+
const box = element('div', 'src src-excerpt');
|
|
128
|
+
// Highlighting runs from the top so a comment or template opened above the excerpt keeps its colour.
|
|
129
|
+
for (const [index, line] of lines.slice(0, to).entries()) {
|
|
130
|
+
const nodes = highlight(line);
|
|
131
|
+
const number = index + 1;
|
|
132
|
+
if (number < from)
|
|
133
|
+
continue;
|
|
134
|
+
const row = element('div', number >= options.line && number <= end ? 'src-line src-range' : 'src-line');
|
|
135
|
+
const code = element('code', 'src-code');
|
|
136
|
+
code.append(...nodes);
|
|
137
|
+
row.append(element('span', 'src-mark'), element('span', 'src-number', String(number)), code);
|
|
138
|
+
box.append(row);
|
|
139
|
+
}
|
|
140
|
+
if (end > to)
|
|
141
|
+
box.append(moreLines(end, to, options.more));
|
|
142
|
+
return box;
|
|
143
|
+
}
|
|
144
|
+
/** The first code on a line, trimmed: a name for an anonymous function that says which one it is. */
|
|
145
|
+
export function lineSnippet(text, line, limit = 60) {
|
|
146
|
+
const found = text.split('\n')[line - 1]?.trim();
|
|
147
|
+
if (!found)
|
|
148
|
+
return null;
|
|
149
|
+
return found.length > limit ? `${found.slice(0, limit - 1)}…` : found;
|
|
150
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { SourceLocator } from '../../json/wire/summary-model.js';
|
|
2
|
-
import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
|
|
3
2
|
/** Where the viewer fetches a file's text, as the export names it: a URL template and the page a person would open. */
|
|
4
3
|
export type { SourceLocator } from '../../json/wire/summary-model.js';
|
|
5
4
|
export interface SourcePlace {
|
|
@@ -26,86 +25,3 @@ export declare function sourcePage(sha: string, path: string, line?: number): {
|
|
|
26
25
|
readonly href: string;
|
|
27
26
|
readonly provider: string;
|
|
28
27
|
} | null;
|
|
29
|
-
export interface SourceFunction {
|
|
30
|
-
readonly line: number;
|
|
31
|
-
readonly complexity: number;
|
|
32
|
-
readonly name: string;
|
|
33
|
-
}
|
|
34
|
-
export interface SourceNote {
|
|
35
|
-
readonly line: number;
|
|
36
|
-
readonly level: string;
|
|
37
|
-
readonly title: string;
|
|
38
|
-
readonly message: string;
|
|
39
|
-
}
|
|
40
|
-
/** Line ranges of one file's coverage: 1-based, inclusive and merged. Partial lines ran with some branches missed. */
|
|
41
|
-
export type FileLineCoverage = NonNullable<InspectionDetails['lineCoverage']>[string];
|
|
42
|
-
export type LineState = 'covered' | 'partial' | 'uncovered';
|
|
43
|
-
/** What the source view's lines show: the inspection's findings and complexity, or the tests' coverage. */
|
|
44
|
-
export type SourceLayer = 'issues' | 'coverage';
|
|
45
|
-
export declare function isSourceLayer(value: string | null | undefined): value is SourceLayer;
|
|
46
|
-
/**
|
|
47
|
-
* Each line's coverage, by line number; a line no range names was not measured. Where ranges overlap, the worse
|
|
48
|
-
* state wins: a line a test missed is never shown as covered.
|
|
49
|
-
*/
|
|
50
|
-
export declare function lineStates(coverage: FileLineCoverage): Map<number, LineState>;
|
|
51
|
-
/** Runs of equal hit counts: first and last line, 1-based and inclusive, and how often tests ran them; 0 is a miss. */
|
|
52
|
-
export type HitRun = readonly [first: number, last: number, count: number];
|
|
53
|
-
/** How often tests ran each line, where the report carries the counts; an older report has none. */
|
|
54
|
-
export declare function lineHits(coverage: FileLineCoverage): Map<number, number>;
|
|
55
|
-
/** A count short enough for the gutter: 3×, 980×, 1.2K×, 45K×, 270K×, 3.4M×. */
|
|
56
|
-
export declare function hitLabel(count: number): string;
|
|
57
|
-
/** What a measured line says to a pointer and a screen reader: its state, and how often it ran where that is known. */
|
|
58
|
-
export declare function lineCoverageText(state: LineState, count?: number): string;
|
|
59
|
-
export interface SourceOptions {
|
|
60
|
-
readonly path: string;
|
|
61
|
-
readonly functions: readonly SourceFunction[];
|
|
62
|
-
readonly notes: readonly SourceNote[];
|
|
63
|
-
/** Each line's coverage, where the file has a coverage report. */
|
|
64
|
-
readonly coverage?: ReadonlyMap<number, LineState> | undefined;
|
|
65
|
-
/** How often tests ran each line, where the report counts it. */
|
|
66
|
-
readonly hits?: ReadonlyMap<number, number> | undefined;
|
|
67
|
-
/** What the lines show first; the view switches it with setSourceLayer. */
|
|
68
|
-
readonly layer?: SourceLayer | undefined;
|
|
69
|
-
/** The line to bring into view and mark, from the URL. */
|
|
70
|
-
readonly line?: number | undefined;
|
|
71
|
-
/** Called when a line number is chosen, so the page can put it in the URL. */
|
|
72
|
-
readonly choose: (line: number) => void;
|
|
73
|
-
}
|
|
74
|
-
/** Switches a rendered source between its findings and its coverage, without drawing it again. */
|
|
75
|
-
export declare function setSourceLayer(container: HTMLElement, layer: SourceLayer): void;
|
|
76
|
-
/** The source as numbered lines; returns a function that brings a line into view and marks it. */
|
|
77
|
-
export declare function renderSource(container: HTMLElement, text: string, options: SourceOptions): (line: number) => void;
|
|
78
|
-
export interface ExcerptOptions {
|
|
79
|
-
readonly path: string;
|
|
80
|
-
/** The flagged range; the excerpt shows its head with a line of context before it. */
|
|
81
|
-
readonly line: number;
|
|
82
|
-
readonly endLine?: number | undefined;
|
|
83
|
-
/** Where the rest of a long range opens in full. */
|
|
84
|
-
readonly more?: ((line: number) => string) | undefined;
|
|
85
|
-
readonly size?: number;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* A few lines of source around a finding, bounded so a 160-line function stays a card: one line of context,
|
|
89
|
-
* the head of the flagged range marked, then a link to the rest.
|
|
90
|
-
*/
|
|
91
|
-
export declare function renderExcerpt(text: string, options: ExcerptOptions): HTMLElement;
|
|
92
|
-
/** The first code on a line, trimmed: a name for an anonymous function that says which one it is. */
|
|
93
|
-
export declare function lineSnippet(text: string, line: number, limit?: number): string | null;
|
|
94
|
-
/** A single line of code, coloured as the source view colours it; for a snippet that stands on its own. */
|
|
95
|
-
export declare function highlightCode(path: string, line: string): Node[];
|
|
96
|
-
export type TokenKind = '' | 'c' | 's' | 'n' | 'k';
|
|
97
|
-
/**
|
|
98
|
-
* Splits lines of JavaScript or TypeScript into coloured runs: comments, strings, regular expressions, numbers and
|
|
99
|
-
* keywords. It is a scanner, not a parser, but it honours escapes and character classes, and it tells a regular
|
|
100
|
-
* expression from a division by what comes before the slash. State carries across lines, so a block comment or a
|
|
101
|
-
* template literal stays coloured to its end. Other languages come back as plain text.
|
|
102
|
-
*/
|
|
103
|
-
export declare function tokenizer(path: string): (line: string) => [TokenKind, string][];
|
|
104
|
-
/**
|
|
105
|
-
* The tint a gap of blank and comment lines takes so the strip has no breaks: the state of the measured line above it,
|
|
106
|
-
* 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
|
|
107
|
-
* takes its other neighbour, and one with no measured neighbour stays plain.
|
|
108
|
-
*/
|
|
109
|
-
export declare function bridgeStates(states: ReadonlyMap<number, LineState>, codeless: readonly boolean[]): Map<number, LineState>;
|
|
110
|
-
/** A line with no code: blank, or nothing but comment. */
|
|
111
|
-
export declare function codeless(runs: readonly (readonly [TokenKind, string])[]): boolean;
|