repometry 0.2.1 → 0.3.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/package.json +1 -1
- package/target/main/resources/report/json/report-v2.schema.json +42 -6
- package/target/main/resources/report/json/viewer-details-v1.schema.json +3 -0
- package/target/main/resources/viewer/files.css +19 -0
- package/target/main/resources/viewer/styles.css +2 -0
- package/target/main/ts/compose/analyze-snapshot.js +5 -3
- package/target/main/ts/core/model/line-coverage.d.ts +9 -0
- package/target/main/ts/core/model/line-coverage.js +21 -0
- package/target/main/ts/plugins/coverage/coverage.d.ts +2 -0
- package/target/main/ts/plugins/coverage/coverage.js +43 -7
- package/target/main/ts/report/html/app/viewer-files.d.ts +3 -0
- package/target/main/ts/report/html/app/viewer-files.js +53 -7
- package/target/main/ts/report/html/app/viewer-source.d.ts +18 -0
- package/target/main/ts/report/html/app/viewer-source.js +39 -0
- package/target/main/ts/report/html/app/viewer.js +5 -1
- package/target/main/ts/report/json/projections/inspection-details.js +3 -0
- package/target/main/ts/report/json/validation/report.js +4 -0
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +2 -0
package/package.json
CHANGED
|
@@ -104,14 +104,21 @@
|
|
|
104
104
|
},
|
|
105
105
|
"products": {
|
|
106
106
|
"type": "object",
|
|
107
|
+
"properties": {
|
|
108
|
+
"repometry.lcov-lines/v1": {
|
|
109
|
+
"type": "array",
|
|
110
|
+
"minItems": 1,
|
|
111
|
+
"maxItems": 1,
|
|
112
|
+
"items": {
|
|
113
|
+
"$ref": "#/$defs/reportProduct",
|
|
114
|
+
"type": "object",
|
|
115
|
+
"properties": { "value": { "$ref": "#/$defs/lcovLines" } }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
107
119
|
"additionalProperties": {
|
|
108
120
|
"type": "array",
|
|
109
|
-
"items": {
|
|
110
|
-
"type": "object",
|
|
111
|
-
"required": ["operation", "value"],
|
|
112
|
-
"properties": { "operation": { "type": "string" }, "path": { "type": "string" }, "value": true },
|
|
113
|
-
"additionalProperties": false
|
|
114
|
-
}
|
|
121
|
+
"items": { "$ref": "#/$defs/reportProduct" }
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
124
|
},
|
|
@@ -132,6 +139,35 @@
|
|
|
132
139
|
},
|
|
133
140
|
"additionalProperties": false,
|
|
134
141
|
"$defs": {
|
|
142
|
+
"reportProduct": {
|
|
143
|
+
"type": "object",
|
|
144
|
+
"required": ["operation", "value"],
|
|
145
|
+
"properties": { "operation": { "type": "string" }, "path": { "type": "string" }, "value": true },
|
|
146
|
+
"additionalProperties": false
|
|
147
|
+
},
|
|
148
|
+
"lcovLines": {
|
|
149
|
+
"type": "object",
|
|
150
|
+
"additionalProperties": {
|
|
151
|
+
"type": "object",
|
|
152
|
+
"required": ["covered", "uncovered"],
|
|
153
|
+
"additionalProperties": false,
|
|
154
|
+
"properties": {
|
|
155
|
+
"covered": { "$ref": "#/$defs/lcovLineRanges" },
|
|
156
|
+
"uncovered": { "$ref": "#/$defs/lcovLineRanges" },
|
|
157
|
+
"partial": { "$ref": "#/$defs/lcovLineRanges" }
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
"lcovLineRanges": {
|
|
162
|
+
"type": "array",
|
|
163
|
+
"description": "Sorted, merged 1-based inclusive line ranges.",
|
|
164
|
+
"items": {
|
|
165
|
+
"type": "array",
|
|
166
|
+
"minItems": 2,
|
|
167
|
+
"prefixItems": [{ "type": "integer", "minimum": 1 }, { "type": "integer", "minimum": 1 }],
|
|
168
|
+
"items": false
|
|
169
|
+
}
|
|
170
|
+
},
|
|
135
171
|
"pluginRule": {
|
|
136
172
|
"type": "object",
|
|
137
173
|
"required": ["id", "category"],
|
|
@@ -429,6 +429,13 @@
|
|
|
429
429
|
.fx-source-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .25rem 1rem; padding: .625rem 1rem; background: var(--band); border-bottom: 1px solid var(--rule); }
|
|
430
430
|
.fx-source-path { min-width: 0; font-size: .8125rem; color: var(--ink); overflow-wrap: anywhere; }
|
|
431
431
|
.fx-source-meta { display: inline-flex; align-items: center; gap: .375rem; font-size: .75rem; color: var(--secondary); }
|
|
432
|
+
/* The switch between findings and coverage leads the head's right side; a narrow head wraps it under the name whole. */
|
|
433
|
+
.fx-source-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .375rem .875rem; min-width: 0; }
|
|
434
|
+
.fx-source-head:has(.fx-source-layer) { padding-block: .375rem; }
|
|
435
|
+
.fx-source-layer { height: 1.75rem; }
|
|
436
|
+
.fx-source-layer button { padding: 0 .625rem; font-size: .75rem; }
|
|
437
|
+
/* Under the file name, on a phone, the switch and the meta line up on the left, as the name does. */
|
|
438
|
+
@media (max-width: 42rem) { .fx-source-tools { justify-content: flex-start; } }
|
|
432
439
|
.fx-source-wait, .fx-source-missing { margin: 0; padding: 1.25rem 1rem; }
|
|
433
440
|
.fx-source-missing { color: var(--secondary); font-size: .875rem; }
|
|
434
441
|
.src { overflow-x: auto; padding: .375rem 0 .75rem; font-family: var(--mono); font-size: .8125rem; line-height: 1.6; tab-size: 2; }
|
|
@@ -439,6 +446,18 @@
|
|
|
439
446
|
.src-number:hover { color: var(--ink); }
|
|
440
447
|
.src-code { padding-right: 1.5rem; font: inherit; white-space: pre; color: var(--ink); }
|
|
441
448
|
.src-flagged { background: var(--warn-bg); }
|
|
449
|
+
/* Coverage replaces the findings on the lines: covered green, partly covered amber, missed red, unmeasured plain. The
|
|
450
|
+
gutter says the same by shape, a full, half or empty dot, for readers who do not tell the tints apart. */
|
|
451
|
+
.src-cov { display: none; }
|
|
452
|
+
.src[data-layer="coverage"] .src-complexity, .src[data-layer="coverage"] .src-note { display: none; }
|
|
453
|
+
.src[data-layer="coverage"] .src-flagged { background: none; }
|
|
454
|
+
.src[data-layer="coverage"] .src-cov-covered { background: var(--good-bg); }
|
|
455
|
+
.src[data-layer="coverage"] .src-cov-partial { background: var(--warn-bg); }
|
|
456
|
+
.src[data-layer="coverage"] .src-cov-uncovered { background: var(--bad-bg); }
|
|
457
|
+
.src[data-layer="coverage"] .src-cov { display: block; width: .5rem; height: .5rem; border: 1.5px solid currentColor; border-radius: 50%; }
|
|
458
|
+
.src-cov-mark-covered { color: var(--good); background: currentColor; }
|
|
459
|
+
.src-cov-mark-partial { color: var(--grade-c); background: linear-gradient(90deg, currentColor 50%, transparent 50%); }
|
|
460
|
+
.src-cov-mark-uncovered { color: var(--bad); }
|
|
442
461
|
.src-target, .src-target:hover { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
|
|
443
462
|
.src-complexity { min-width: 1.375rem; padding: 0 .25rem; font-family: var(--sans); font-size: .6875rem; font-weight: 650; line-height: 1.125rem; text-align: center; border-radius: 4px; color: var(--secondary); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--rule); }
|
|
444
463
|
.src-band-1 { color: var(--heat-ink); background: var(--heat-1); box-shadow: none; }
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
--flag-good: #2f9445;
|
|
23
23
|
--flag-bad: #c63d36;
|
|
24
24
|
--bad-bg: #fdecea;
|
|
25
|
+
--good-bg: #eff8f2;
|
|
25
26
|
--bad-ink: #9f2a21;
|
|
26
27
|
--warn-bg: #fdf3dc;
|
|
27
28
|
--warn-ink: #81580a;
|
|
@@ -86,6 +87,7 @@
|
|
|
86
87
|
--flag-good: #5fd06a;
|
|
87
88
|
--flag-bad: #f0736b;
|
|
88
89
|
--bad-bg: #3a1c1a;
|
|
90
|
+
--good-bg: #11231a;
|
|
89
91
|
--bad-ink: #ffb1a8;
|
|
90
92
|
--warn-bg: #352812;
|
|
91
93
|
--warn-ink: #f2cd7f;
|
|
@@ -18,7 +18,7 @@ const selected = ['structure/size', 'structure/complexity', 'maintainability/fil
|
|
|
18
18
|
const bindings = new Map(selected.map(operation => [operation, { syntax: { operation: 'babel-syntax/parse' } }]));
|
|
19
19
|
const sourcePlan = plan({ plugins: sourcePlugins, select: selected, inputs: new Map([['file', sourceFile.id]]), bindings });
|
|
20
20
|
const duplicationPlan = plan({ plugins: [duplication], select: ['duplication/detect'], inputs: new Map([['sources', duplicationInput.id]]) });
|
|
21
|
-
const coveragePlan = plan({ plugins: [coverage], select: ['lcov/import'], inputs: new Map([['lcov', lcovInput.id]]) });
|
|
21
|
+
const coveragePlan = plan({ plugins: [coverage], select: ['lcov/import', 'lcov/lines'], inputs: new Map([['lcov', lcovInput.id]]) });
|
|
22
22
|
const measurementDefinitions = {
|
|
23
23
|
[definitions.lines]: 'Physical lines including blank lines and comments. A final line terminator does not add a line.',
|
|
24
24
|
[definitions.functions]: 'Babel function nodes with bodies, including nested functions and methods.',
|
|
@@ -75,8 +75,10 @@ export async function analyzeSnapshot({ snapshot, excludedOutput, excludedPaths
|
|
|
75
75
|
if (inputCoverage !== undefined) {
|
|
76
76
|
const value = { text: inputCoverage.text, root: inputCoverage.sourceRoot, sourceLines: sourceLineCounts(snapshot.files),
|
|
77
77
|
excludes: sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded) };
|
|
78
|
-
const
|
|
79
|
-
|
|
78
|
+
const outcomes = await execute(coveragePlan, new Map([['lcov', { contract: lcovInput.id, value }]]));
|
|
79
|
+
for (const task of coveragePlan)
|
|
80
|
+
record(task, outcomes.get(task.key));
|
|
81
|
+
const result = outcomes.get('lcov/import');
|
|
80
82
|
if (result.state === 'completed' && coverageResult.accepts(result.product.value)) {
|
|
81
83
|
for (const { path, reason } of result.product.value.gaps) {
|
|
82
84
|
diagnostics.push({ operation: 'lcov/import', state: 'partial', path, message: reason });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DataContract } from '../engine/plugin.js';
|
|
2
|
+
export type CoveredLineRange = readonly [first: number, last: number];
|
|
3
|
+
export interface FileLineCoverage {
|
|
4
|
+
readonly covered: readonly CoveredLineRange[];
|
|
5
|
+
readonly uncovered: readonly CoveredLineRange[];
|
|
6
|
+
readonly partial?: readonly CoveredLineRange[];
|
|
7
|
+
}
|
|
8
|
+
export type LineCoverage = Readonly<Record<string, FileLineCoverage>>;
|
|
9
|
+
export declare const lcovLines: DataContract<LineCoverage>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isRecord } from '../engine/plugin.js';
|
|
2
|
+
export const lcovLines = {
|
|
3
|
+
id: 'repometry.lcov-lines/v1',
|
|
4
|
+
accepts: (value) => isRecord(value) && Object.values(value).every(file => isRecord(file) && isMerged(file.covered) && isMerged(file.uncovered) &&
|
|
5
|
+
(file.partial === undefined || isMerged(file.partial))),
|
|
6
|
+
};
|
|
7
|
+
function isMerged(value) {
|
|
8
|
+
if (!Array.isArray(value))
|
|
9
|
+
return false;
|
|
10
|
+
let previous = -1;
|
|
11
|
+
for (const range of value) {
|
|
12
|
+
if (!Array.isArray(range) || range.length !== 2)
|
|
13
|
+
return false;
|
|
14
|
+
const [first, last] = range;
|
|
15
|
+
if (typeof first !== 'number' || typeof last !== 'number' || !Number.isSafeInteger(first)
|
|
16
|
+
|| !Number.isSafeInteger(last) || first <= previous + 1 || last < first)
|
|
17
|
+
return false;
|
|
18
|
+
previous = last;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DataContract, Plugin } from '../../core/engine/plugin.js';
|
|
2
2
|
import type { Measurement } from '../../core/model/measurement.js';
|
|
3
|
+
import type { LineCoverage } from '../../core/model/line-coverage.js';
|
|
3
4
|
export interface CoverageInput {
|
|
4
5
|
readonly text: string;
|
|
5
6
|
readonly root: string;
|
|
@@ -12,6 +13,7 @@ interface CoverageResult {
|
|
|
12
13
|
readonly path: string;
|
|
13
14
|
readonly reason: string;
|
|
14
15
|
}[];
|
|
16
|
+
readonly lineCoverage: LineCoverage;
|
|
15
17
|
}
|
|
16
18
|
export declare const lcovInput: DataContract<CoverageInput>;
|
|
17
19
|
export declare const coverageResult: DataContract<CoverageResult>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { posix, win32 } from 'node:path';
|
|
2
|
+
import reportSchema from '../../../resources/report/json/report-v2.schema.json' with { type: 'json' };
|
|
2
3
|
import { isRecord, pluginApi } from '../../core/engine/plugin.js';
|
|
3
4
|
import { comparePaths } from '../../core/model/snapshot.js';
|
|
4
5
|
import { definitions, measurements } from '../../core/model/measurement.js';
|
|
6
|
+
import { lcovLines } from '../../core/model/line-coverage.js';
|
|
5
7
|
export const lcovInput = {
|
|
6
8
|
id: 'repometry.lcov-input/v1',
|
|
7
9
|
accepts: (value) => isRecord(value) && typeof value.text === 'string'
|
|
@@ -11,7 +13,8 @@ export const lcovInput = {
|
|
|
11
13
|
export const coverageResult = {
|
|
12
14
|
id: 'repometry.coverage-result/v1',
|
|
13
15
|
accepts: (value) => isRecord(value) && measurements.accepts(value.measurements)
|
|
14
|
-
&& Array.isArray(value.gaps) && value.gaps.every(gap => isRecord(gap) && typeof gap.path === 'string' && typeof gap.reason === 'string')
|
|
16
|
+
&& Array.isArray(value.gaps) && value.gaps.every(gap => isRecord(gap) && typeof gap.path === 'string' && typeof gap.reason === 'string')
|
|
17
|
+
&& lcovLines.accepts(value.lineCoverage),
|
|
15
18
|
};
|
|
16
19
|
export const coverage = {
|
|
17
20
|
id: 'lcov',
|
|
@@ -31,13 +34,20 @@ export const coverage = {
|
|
|
31
34
|
ratio: { of: definitions.coveredFunctions, over: definitions.coverableFunctions }, bands: [0.6, 0.7, 0.8, 0.9], group: 'Coverage' },
|
|
32
35
|
{ id: definitions.coveredFunctions, label: 'Covered functions', unit: 'count', scope: 'file', aggregate: 'sum', better: 'higher', group: 'Coverage' },
|
|
33
36
|
{ id: definitions.coverableFunctions, label: 'Measured functions', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Coverage' },
|
|
34
|
-
] }
|
|
37
|
+
] }, { contract: lcovLines.id, persistence: 'report',
|
|
38
|
+
schema: { ...reportSchema.$defs.lcovLines, $defs: { lcovLineRanges: reportSchema.$defs.lcovLineRanges } } }],
|
|
35
39
|
operations: [{
|
|
36
40
|
id: 'import',
|
|
37
41
|
role: 'inspection',
|
|
38
42
|
inputs: { report: lcovInput },
|
|
39
43
|
output: coverageResult,
|
|
40
44
|
execute: inputs => importCoverage(inputs.read('report', lcovInput)),
|
|
45
|
+
}, {
|
|
46
|
+
id: 'lines',
|
|
47
|
+
role: 'inspection',
|
|
48
|
+
inputs: { coverage: coverageResult },
|
|
49
|
+
output: lcovLines,
|
|
50
|
+
execute: inputs => inputs.read('coverage', coverageResult).lineCoverage,
|
|
41
51
|
}],
|
|
42
52
|
};
|
|
43
53
|
export function mapCoverage({ text, root, sourceLines, excludes }) {
|
|
@@ -135,15 +145,21 @@ export function mapCoverage({ text, root, sourceLines, excludes }) {
|
|
|
135
145
|
function importCoverage(input) {
|
|
136
146
|
const { files, branches, functions, gaps } = mapCoverage(input);
|
|
137
147
|
const rows = [];
|
|
148
|
+
const lineCoverage = [];
|
|
138
149
|
let totalCovered = 0;
|
|
139
150
|
let totalLines = 0;
|
|
140
151
|
for (const [path, hits] of [...files].sort(([left], [right]) => comparePaths(left, right))) {
|
|
141
152
|
if (gaps.has(path))
|
|
142
153
|
continue;
|
|
143
|
-
|
|
144
|
-
for (const hit of hits
|
|
145
|
-
|
|
146
|
-
|
|
154
|
+
const hitLines = [], missedLines = [];
|
|
155
|
+
for (const [line, hit] of hits)
|
|
156
|
+
(hit ? hitLines : missedLines).push(line);
|
|
157
|
+
const partial = mergedRanges(partiallyCoveredLines(branches.get(path), input.sourceLines.get(path)));
|
|
158
|
+
if (hits.size || partial.length)
|
|
159
|
+
lineCoverage.push([path, {
|
|
160
|
+
covered: mergedRanges(hitLines), uncovered: mergedRanges(missedLines), ...(partial.length ? { partial } : {}),
|
|
161
|
+
}]);
|
|
162
|
+
const covered = hitLines.length;
|
|
147
163
|
totalCovered += covered;
|
|
148
164
|
totalLines += hits.size;
|
|
149
165
|
rows.push({ definition: definitions.coverage, target: 'file', path, covered, total: hits.size, value: ratio(covered, hits.size) });
|
|
@@ -157,9 +173,29 @@ function importCoverage(input) {
|
|
|
157
173
|
...hitRows(branches, gaps, definitions.branchCoverage, definitions.coveredBranches, definitions.coverableBranches),
|
|
158
174
|
...hitRows(functions, gaps, definitions.functionCoverage, definitions.coveredFunctions, definitions.coverableFunctions),
|
|
159
175
|
];
|
|
160
|
-
return { measurements: [...rows, ...counts, ...extra],
|
|
176
|
+
return { measurements: [...rows, ...counts, ...extra], lineCoverage: Object.fromEntries(lineCoverage),
|
|
161
177
|
gaps: [...gaps].sort(([left], [right]) => comparePaths(left, right)).map(([path, reason]) => ({ path, reason })) };
|
|
162
178
|
}
|
|
179
|
+
function partiallyCoveredLines(branches, lastLine) {
|
|
180
|
+
const taken = new Set(), missed = new Set();
|
|
181
|
+
for (const [branch, hit] of branches ?? []) {
|
|
182
|
+
const line = Number(branch.slice(0, branch.indexOf(',')));
|
|
183
|
+
if (line <= lastLine)
|
|
184
|
+
(hit ? taken : missed).add(line);
|
|
185
|
+
}
|
|
186
|
+
return [...taken].filter(line => missed.has(line));
|
|
187
|
+
}
|
|
188
|
+
function mergedRanges(lines) {
|
|
189
|
+
const ranges = [];
|
|
190
|
+
for (const line of lines.sort((left, right) => left - right)) {
|
|
191
|
+
const previous = ranges.at(-1);
|
|
192
|
+
if (previous && previous[1] + 1 === line)
|
|
193
|
+
previous[1] = line;
|
|
194
|
+
else
|
|
195
|
+
ranges.push([line, line]);
|
|
196
|
+
}
|
|
197
|
+
return ranges;
|
|
198
|
+
}
|
|
163
199
|
/** Per-file and repository ratios with their counts, for a kind the LCOV reports; nothing when it reports none. */
|
|
164
200
|
function hitRows(files, gaps, ratioId, coveredId, totalId) {
|
|
165
201
|
const rows = [];
|
|
@@ -19,6 +19,8 @@ interface Navigation {
|
|
|
19
19
|
readonly level?: string | undefined;
|
|
20
20
|
/** What Hotspots ranks by. */
|
|
21
21
|
readonly rank?: string | undefined;
|
|
22
|
+
/** What an open file's lines show: its findings (the default) or its coverage. */
|
|
23
|
+
readonly layer?: string | undefined;
|
|
22
24
|
/** Source text of a file at this commit; absent where the view cannot load source. */
|
|
23
25
|
readonly source?: ((path: string) => Promise<string | null>) | undefined;
|
|
24
26
|
/** The file's page on its forge, when the export names one. */
|
|
@@ -37,6 +39,7 @@ export interface LinkOptions {
|
|
|
37
39
|
readonly category?: string;
|
|
38
40
|
readonly level?: string;
|
|
39
41
|
readonly rank?: string;
|
|
42
|
+
readonly layer?: string;
|
|
40
43
|
}
|
|
41
44
|
/**
|
|
42
45
|
* The finding categories Repometry counts as code smells, mirroring core's quality summary (structure and
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { formatQuery, ignoredLabel, isLockfile, languageColor, languageOf, languageShares, lockfilesLabel, matches, parseQuery, queryField, sameClause, sized, suggest, usePluginMeasures } from './viewer-filter.js';
|
|
2
2
|
import { bandLabels as pluginBandLabels, bandOf, bandScale, catalogIndex, compareValues, entryValue, firstSortAscending, format, rollUp } from './viewer-metric-registry.js';
|
|
3
3
|
import { extendCatalog, labelOf, pluginMetrics, pluginSpec, securityRisks, size } from './viewer-metrics.js';
|
|
4
|
-
import { highlightCode, lineSnippet, renderExcerpt, renderSource } from './viewer-source.js';
|
|
4
|
+
import { highlightCode, isSourceLayer, lineSnippet, lineStates, renderExcerpt, renderSource, setSourceLayer } from './viewer-source.js';
|
|
5
5
|
/**
|
|
6
6
|
* The finding categories Repometry counts as code smells, mirroring core's quality summary (structure and
|
|
7
7
|
* duplication), so the Overview's smell count links to exactly the findings it counts.
|
|
@@ -683,15 +683,31 @@ function fileView(details, navigation, file, load) {
|
|
|
683
683
|
// The folder is in the breadcrumbs right above; the head names the file alone, with its full path on hover.
|
|
684
684
|
const name = element('code', 'fx-source-path', basename(file.path));
|
|
685
685
|
name.title = file.path;
|
|
686
|
-
|
|
687
|
-
|
|
686
|
+
const meta = element('span', 'fx-source-meta');
|
|
687
|
+
meta.append(dot, `${language} · ${count(file.lines)} lines`);
|
|
688
|
+
// Lines show the findings, or the tests' coverage where the file has it; without coverage the head stays as it was.
|
|
689
|
+
const coverage = fileCoverage(details, file.path);
|
|
690
|
+
let layer = coverage ? sourceLayer(navigation.layer) : 'issues';
|
|
691
|
+
let line = navigation.line;
|
|
692
|
+
const place = () => nav.href('metrics', { directory: parentPath(file.path), file: file.path, ...line ? { line } : {},
|
|
693
|
+
...layer === 'coverage' ? { layer } : {} });
|
|
694
|
+
const toggle = coverage ? segmented('Lines show', [['issues', 'Issues'], ['coverage', 'Coverage']], layer, value => {
|
|
695
|
+
layer = value;
|
|
696
|
+
rememberLayer(layer);
|
|
697
|
+
setSourceLayer(body, layer);
|
|
698
|
+
history.replaceState(history.state, '', place());
|
|
699
|
+
}) : null;
|
|
700
|
+
toggle?.classList.add('fx-source-layer');
|
|
701
|
+
const tools = element('div', 'fx-source-tools');
|
|
702
|
+
tools.append(...toggle ? [toggle] : [], meta);
|
|
703
|
+
head.append(name, tools);
|
|
688
704
|
// The forge's page for the file, at the chosen line, whether or not the text opens here.
|
|
689
705
|
const page = navigation.sourcePage?.(file.path, navigation.line);
|
|
690
706
|
const forge = page ? link(page.href, `View on ${page.provider}`, 'fx-source-forge') : null;
|
|
691
707
|
if (forge) {
|
|
692
708
|
forge.target = '_blank';
|
|
693
709
|
forge.rel = 'noopener noreferrer';
|
|
694
|
-
|
|
710
|
+
meta.append(' · ', forge);
|
|
695
711
|
}
|
|
696
712
|
const body = element('div', 'fx-source-body');
|
|
697
713
|
body.append(element('p', 'fx-note fx-source-wait', 'Loading source…'));
|
|
@@ -708,11 +724,14 @@ function fileView(details, navigation, file, load) {
|
|
|
708
724
|
if (text === null) {
|
|
709
725
|
// No locator, a private repository, a commit never pushed: one quiet state, and the forge's page when there is one.
|
|
710
726
|
body.replaceChildren(element('p', 'fx-source-missing', 'Source not available'));
|
|
727
|
+
// Nothing to shade: the head is the one a file without coverage has.
|
|
728
|
+
toggle?.remove();
|
|
711
729
|
return;
|
|
712
730
|
}
|
|
713
|
-
const choose = (
|
|
714
|
-
|
|
715
|
-
|
|
731
|
+
const choose = (chosen) => {
|
|
732
|
+
line = chosen;
|
|
733
|
+
history.replaceState(history.state, '', place());
|
|
734
|
+
const moved = navigation.sourcePage?.(file.path, chosen);
|
|
716
735
|
if (forge && moved)
|
|
717
736
|
forge.href = moved.href;
|
|
718
737
|
};
|
|
@@ -720,6 +739,7 @@ function fileView(details, navigation, file, load) {
|
|
|
720
739
|
path: file.path,
|
|
721
740
|
functions: functions.flatMap(record => record.line === null ? [] : [{ line: record.line, complexity: record.complexity, name: record.name }]),
|
|
722
741
|
notes, line: navigation.line, choose,
|
|
742
|
+
coverage: coverage ? lineStates(coverage) : undefined, layer,
|
|
723
743
|
});
|
|
724
744
|
const next = fileDetails(details, file, nav, { text, reveal: line => { reveal(line); choose(line); } });
|
|
725
745
|
aside.replaceWith(next);
|
|
@@ -727,6 +747,32 @@ function fileView(details, navigation, file, load) {
|
|
|
727
747
|
});
|
|
728
748
|
return view;
|
|
729
749
|
}
|
|
750
|
+
/** A file's line coverage, where the inspection's coverage report names the file. */
|
|
751
|
+
function fileCoverage(details, path) {
|
|
752
|
+
const coverage = details.lineCoverage;
|
|
753
|
+
return coverage && Object.hasOwn(coverage, path) ? coverage[path] : undefined;
|
|
754
|
+
}
|
|
755
|
+
const layerKey = 'repometry.source-layer';
|
|
756
|
+
/** The URL's choice of what lines show, else the one made earlier in this session, else the findings. */
|
|
757
|
+
function sourceLayer(requested) {
|
|
758
|
+
if (isSourceLayer(requested))
|
|
759
|
+
return requested;
|
|
760
|
+
try {
|
|
761
|
+
const stored = sessionStorage.getItem(layerKey);
|
|
762
|
+
return isSourceLayer(stored) ? stored : 'issues';
|
|
763
|
+
}
|
|
764
|
+
catch {
|
|
765
|
+
return 'issues';
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
function rememberLayer(layer) {
|
|
769
|
+
try {
|
|
770
|
+
sessionStorage.setItem(layerKey, layer);
|
|
771
|
+
}
|
|
772
|
+
catch {
|
|
773
|
+
// Blocked storage only forgets the choice; the URL still carries it.
|
|
774
|
+
}
|
|
775
|
+
}
|
|
730
776
|
/**
|
|
731
777
|
* The top of a relative colour scale, per level: files against files, folders against the folders at their depth. One
|
|
732
778
|
* scale for both would let a folder's sum outshine every file in it, and the map would read hot folders over pale files.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SourceLocator } from '../../json/wire/summary-model.js';
|
|
2
|
+
import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
|
|
2
3
|
/** Where the viewer fetches a file's text, as the export names it: a URL template and the page a person would open. */
|
|
3
4
|
export type { SourceLocator } from '../../json/wire/summary-model.js';
|
|
4
5
|
export interface SourcePlace {
|
|
@@ -36,15 +37,32 @@ export interface SourceNote {
|
|
|
36
37
|
readonly title: string;
|
|
37
38
|
readonly message: string;
|
|
38
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>;
|
|
39
51
|
export interface SourceOptions {
|
|
40
52
|
readonly path: string;
|
|
41
53
|
readonly functions: readonly SourceFunction[];
|
|
42
54
|
readonly notes: readonly SourceNote[];
|
|
55
|
+
/** Each line's coverage, where the file has a coverage report. */
|
|
56
|
+
readonly coverage?: ReadonlyMap<number, LineState> | undefined;
|
|
57
|
+
/** What the lines show first; the view switches it with setSourceLayer. */
|
|
58
|
+
readonly layer?: SourceLayer | undefined;
|
|
43
59
|
/** The line to bring into view and mark, from the URL. */
|
|
44
60
|
readonly line?: number | undefined;
|
|
45
61
|
/** Called when a line number is chosen, so the page can put it in the URL. */
|
|
46
62
|
readonly choose: (line: number) => void;
|
|
47
63
|
}
|
|
64
|
+
/** Switches a rendered source between its findings and its coverage, without drawing it again. */
|
|
65
|
+
export declare function setSourceLayer(container: HTMLElement, layer: SourceLayer): void;
|
|
48
66
|
/** The source as numbered lines; returns a function that brings a line into view and marks it. */
|
|
49
67
|
export declare function renderSource(container: HTMLElement, text: string, options: SourceOptions): (line: number) => void;
|
|
50
68
|
export interface ExcerptOptions {
|
|
@@ -56,6 +56,34 @@ export function sourcePage(sha, path, line) {
|
|
|
56
56
|
const name = providerNames[locator.provider.toLowerCase()] ?? locator.provider.charAt(0).toUpperCase() + locator.provider.slice(1);
|
|
57
57
|
return { href: expandLocator(locator.web, { revision: sha, path, line }), provider: name };
|
|
58
58
|
}
|
|
59
|
+
export function isSourceLayer(value) {
|
|
60
|
+
return value === 'issues' || value === 'coverage';
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Each line's coverage, by line number; a line no range names was not measured. Where ranges overlap, the worse
|
|
64
|
+
* state wins: a line a test missed is never shown as covered.
|
|
65
|
+
*/
|
|
66
|
+
export function lineStates(coverage) {
|
|
67
|
+
const states = new Map();
|
|
68
|
+
const lay = (ranges, state) => {
|
|
69
|
+
for (const [from, to] of ranges ?? [])
|
|
70
|
+
for (let line = Math.max(1, from); line <= to; line++)
|
|
71
|
+
states.set(line, state);
|
|
72
|
+
};
|
|
73
|
+
lay(coverage.covered, 'covered');
|
|
74
|
+
lay(coverage.partial, 'partial');
|
|
75
|
+
lay(coverage.uncovered, 'uncovered');
|
|
76
|
+
return states;
|
|
77
|
+
}
|
|
78
|
+
const lineStateNames = {
|
|
79
|
+
covered: 'Covered', partial: 'Partly covered: some branches missed', uncovered: 'Not covered',
|
|
80
|
+
};
|
|
81
|
+
/** Switches a rendered source between its findings and its coverage, without drawing it again. */
|
|
82
|
+
export function setSourceLayer(container, layer) {
|
|
83
|
+
const code = container.querySelector(':scope > .src');
|
|
84
|
+
if (code)
|
|
85
|
+
code.dataset.layer = layer;
|
|
86
|
+
}
|
|
59
87
|
/** The source as numbered lines; returns a function that brings a line into view and marks it. */
|
|
60
88
|
export function renderSource(container, text, options) {
|
|
61
89
|
const lines = text.replace(/\r\n?/g, '\n').replace(/\n$/, '').split('\n');
|
|
@@ -65,6 +93,7 @@ export function renderSource(container, text, options) {
|
|
|
65
93
|
for (const note of options.notes)
|
|
66
94
|
notes.set(note.line, [...notes.get(note.line) ?? [], note]);
|
|
67
95
|
const code = element('div', 'src');
|
|
96
|
+
code.dataset.layer = options.layer ?? 'issues';
|
|
68
97
|
code.setAttribute('role', 'region');
|
|
69
98
|
code.setAttribute('aria-label', `Source of ${options.path}`);
|
|
70
99
|
const rows = [];
|
|
@@ -80,6 +109,16 @@ export function renderSource(container, text, options) {
|
|
|
80
109
|
badge.title = `Cyclomatic complexity ${start.complexity}`;
|
|
81
110
|
mark.append(badge);
|
|
82
111
|
}
|
|
112
|
+
// The coverage layer marks each measured line in the gutter by shape, full, half or empty, as well as by its tint.
|
|
113
|
+
const state = options.coverage?.get(number);
|
|
114
|
+
if (state) {
|
|
115
|
+
row.classList.add(`src-cov-${state}`);
|
|
116
|
+
const glyph = element('span', `src-cov src-cov-mark-${state}`);
|
|
117
|
+
glyph.setAttribute('role', 'img');
|
|
118
|
+
glyph.setAttribute('aria-label', lineStateNames[state]);
|
|
119
|
+
glyph.title = lineStateNames[state];
|
|
120
|
+
mark.append(glyph);
|
|
121
|
+
}
|
|
83
122
|
const anchor = element('a', 'src-number', String(number));
|
|
84
123
|
anchor.href = `#L${number}`;
|
|
85
124
|
anchor.addEventListener('click', event => {
|
|
@@ -135,6 +135,7 @@ function start({ reports, quality, context, counts, pullReviewCount, branch, met
|
|
|
135
135
|
category: params.get('category') ?? undefined,
|
|
136
136
|
level: params.get('level') ?? undefined,
|
|
137
137
|
rank: params.get('rank') ?? undefined,
|
|
138
|
+
layer: params.get('layer') ?? undefined,
|
|
138
139
|
};
|
|
139
140
|
}
|
|
140
141
|
function loadPulls() {
|
|
@@ -261,6 +262,7 @@ function start({ reports, quality, context, counts, pullReviewCount, branch, met
|
|
|
261
262
|
category: current.category,
|
|
262
263
|
level: current.level,
|
|
263
264
|
rank: current.rank,
|
|
265
|
+
layer: current.layer,
|
|
264
266
|
source: path => loadSource(report.sha, path),
|
|
265
267
|
sourcePage: (path, line) => sourcePage(report.sha, path, line),
|
|
266
268
|
href: (destination, options) => href({ page: destination, sha: report.sha, ...options }),
|
|
@@ -310,7 +312,7 @@ function start({ reports, quality, context, counts, pullReviewCount, branch, met
|
|
|
310
312
|
message.hidden = true;
|
|
311
313
|
render();
|
|
312
314
|
}
|
|
313
|
-
function href({ page, sha, directory, file, view, period, query, group, line, category, level, rank }) {
|
|
315
|
+
function href({ page, sha, directory, file, view, period, query, group, line, category, level, rank, layer }) {
|
|
314
316
|
const params = new URLSearchParams({ sha });
|
|
315
317
|
if (directory)
|
|
316
318
|
params.set('dir', directory);
|
|
@@ -332,6 +334,8 @@ function href({ page, sha, directory, file, view, period, query, group, line, ca
|
|
|
332
334
|
params.set('level', level);
|
|
333
335
|
if (rank)
|
|
334
336
|
params.set('rank', rank);
|
|
337
|
+
if (layer)
|
|
338
|
+
params.set('layer', layer);
|
|
335
339
|
// Category lists read as written: category=structure,duplication.
|
|
336
340
|
return `#${page}?${params.toString().replaceAll('%2C', ',')}`;
|
|
337
341
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { definitions } from '../../../core/model/measurement.js';
|
|
2
|
+
import { lcovLines } from '../../../core/model/line-coverage.js';
|
|
2
3
|
import { comparePaths } from '../../../core/model/snapshot.js';
|
|
3
4
|
import { fileMetrics } from './file-metrics.js';
|
|
4
5
|
import { inspectionHistory } from './inspection-context.js';
|
|
@@ -9,6 +10,7 @@ export function inspectionAsset(report, components, context = inspectionHistory(
|
|
|
9
10
|
}
|
|
10
11
|
export function inspectionDetails(report, components = []) {
|
|
11
12
|
const metrics = fileMetrics(report);
|
|
13
|
+
const lineCoverage = report.pluginData?.products[lcovLines.id]?.[0]?.value;
|
|
12
14
|
const profile = profileSettings(report.appliedConfig);
|
|
13
15
|
const ruleCatalog = report.pluginData?.rules.flatMap(({ plugin, rules }) => rules.map(rule => ({
|
|
14
16
|
source: plugin, kind: 'check', rule: rule.id, category: rule.category,
|
|
@@ -18,6 +20,7 @@ export function inspectionDetails(report, components = []) {
|
|
|
18
20
|
})));
|
|
19
21
|
return { metrics, functions: complexFunctions(report), diagnostics: report.diagnostics, findings: report.findings,
|
|
20
22
|
components: components.length ? componentFiles(components, metrics) : undefined,
|
|
23
|
+
...(lcovLines.accepts(lineCoverage) ? { lineCoverage } : {}),
|
|
21
24
|
...(profile ? { profile: { ...profile, ...(ruleCatalog?.length ? { ruleCatalog } : {}) } } : {}) };
|
|
22
25
|
}
|
|
23
26
|
/** The applied configuration, field by field; whatever is missing or malformed is left out rather than guessed. */
|
|
@@ -5,6 +5,7 @@ import schemaV2 from '../../../../resources/report/json/report-v2.schema.json' w
|
|
|
5
5
|
import { isRecord } from '../../../core/engine/plugin.js';
|
|
6
6
|
import { isMetricDescriptor } from '../../../core/engine/manifest.js';
|
|
7
7
|
import { isFinding } from '../../../core/model/finding.js';
|
|
8
|
+
import { lcovLines } from '../../../core/model/line-coverage.js';
|
|
8
9
|
import { digest } from '../../../core/model/snapshot.js';
|
|
9
10
|
import { compactJsonSchema, unpackJson } from '../wire/compact-json.js';
|
|
10
11
|
import { legacyReportSchema, reportSchema } from '../../../core/model/report.js';
|
|
@@ -42,6 +43,9 @@ export function readReport(value) {
|
|
|
42
43
|
if (ids.size !== metrics.length || !metrics.every(isMetricDescriptor)
|
|
43
44
|
|| [...measured, ...privateMetrics ?? []].some(id => !ids.has(id)))
|
|
44
45
|
throw new Error('Invalid report: inconsistent metric catalog');
|
|
46
|
+
const lines = value.pluginData.products[lcovLines.id];
|
|
47
|
+
if (lines && !lcovLines.accepts(lines[0]?.value))
|
|
48
|
+
throw new Error('Invalid report: LCOV line ranges must be sorted and merged');
|
|
45
49
|
}
|
|
46
50
|
if (value.scope.parsed > value.scope.files)
|
|
47
51
|
throw new Error('Invalid report: parsed count exceeds source count');
|
|
@@ -3,12 +3,14 @@ import type { FileMetricsReport } from './file-metrics-model.js';
|
|
|
3
3
|
import type { InspectionContext } from './inspection-context-model.js';
|
|
4
4
|
import type { ComplexFunction } from './public-history-model.js';
|
|
5
5
|
import type { ComponentMetrics } from './component-model.js';
|
|
6
|
+
import type { LineCoverage } from '../../../core/model/line-coverage.js';
|
|
6
7
|
export interface InspectionDetails {
|
|
7
8
|
readonly metrics: FileMetricsReport;
|
|
8
9
|
readonly functions: readonly ComplexFunction[];
|
|
9
10
|
readonly diagnostics: Report['diagnostics'];
|
|
10
11
|
readonly findings?: Report['findings'];
|
|
11
12
|
readonly components?: readonly ComponentMetrics[];
|
|
13
|
+
readonly lineCoverage?: LineCoverage;
|
|
12
14
|
/**
|
|
13
15
|
* The colour band limits the profile sets for the metrics with a meaningful scale: four ascending upper bounds
|
|
14
16
|
* (three for duplication, whose first band is zero). Absent, the viewer uses its defaults.
|