repometry 0.3.0 → 0.4.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 +12 -1
- package/target/main/resources/viewer/files.css +16 -9
- package/target/main/resources/viewer/styles.css +13 -2
- package/target/main/ts/api/git/git.d.ts +1 -1
- package/target/main/ts/api/git/git.js +21 -5
- package/target/main/ts/api/git/inspection-source.d.ts +1 -1
- package/target/main/ts/api/git/inspection-source.js +10 -4
- package/target/main/ts/api/git/local.d.ts +1 -1
- package/target/main/ts/api/git/local.js +29 -10
- package/target/main/ts/api/worker/worker-protocol.js +34 -9
- package/target/main/ts/compose/analyze-snapshot.d.ts +1 -0
- package/target/main/ts/compose/analyze-snapshot.js +50 -17
- package/target/main/ts/compose/inspect.js +2 -2
- package/target/main/ts/compose/plugin-list.js +2 -1
- package/target/main/ts/compose/security-plugins.d.ts +1 -0
- package/target/main/ts/compose/security-plugins.js +7 -0
- package/target/main/ts/core/engine/manifest.js +3 -2
- package/target/main/ts/core/engine/plugin.d.ts +2 -0
- package/target/main/ts/core/model/line-coverage.d.ts +2 -0
- package/target/main/ts/core/model/line-coverage.js +19 -1
- package/target/main/ts/core/model/source.d.ts +3 -0
- package/target/main/ts/core/model/source.js +4 -1
- package/target/main/ts/core/usecases/inspect.js +2 -2
- package/target/main/ts/plugins/coverage/coverage.d.ts +4 -3
- package/target/main/ts/plugins/coverage/coverage.js +46 -17
- package/target/main/ts/plugins/language-js/js-security.d.ts +4 -0
- package/target/main/ts/plugins/language-js/js-security.js +508 -0
- package/target/main/ts/plugins/security/actions-security.d.ts +2 -0
- package/target/main/ts/plugins/security/actions-security.js +581 -0
- package/target/main/ts/plugins/security/dockerfile.d.ts +2 -0
- package/target/main/ts/plugins/security/dockerfile.js +488 -0
- package/target/main/ts/plugins/security/npm-supply-chain.d.ts +4 -0
- package/target/main/ts/plugins/security/npm-supply-chain.js +368 -0
- package/target/main/ts/plugins/security/secrets.d.ts +12 -0
- package/target/main/ts/plugins/security/secrets.js +254 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +7 -0
- package/target/main/ts/report/html/app/viewer-files.js +60 -10
- package/target/main/ts/report/html/app/viewer-filter.js +8 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-source.js +71 -11
- package/target/main/ts/report/html/site/badges.d.ts +1 -4
- package/target/main/ts/report/html/site/badges.js +28 -19
- package/target/main/ts/report/json/projections/commit-summary.js +2 -11
- package/target/main/ts/report/json/projections/inspection-context.js +6 -12
- package/target/main/ts/report/json/projections/security-summary.d.ts +11 -0
- package/target/main/ts/report/json/projections/security-summary.js +22 -0
|
@@ -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, isSourceLayer, lineSnippet, lineStates, renderExcerpt, renderSource, setSourceLayer } from './viewer-source.js';
|
|
4
|
+
import { highlightCode, isSourceLayer, lineHits, 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.
|
|
@@ -318,10 +318,12 @@ function metricsView(details, navigation, settings, directory, selectedFile) {
|
|
|
318
318
|
// A filtered file list says how many of the folder's files it kept; other lists name the selection only once.
|
|
319
319
|
const listsFiles = noun === 'files' && rows.length === files.length;
|
|
320
320
|
const of = filtering && !(listsFiles && display.length <= pageSize) ? ` · ${count(files.length)} of ${count(scopeFiles.length)} files selected` : '';
|
|
321
|
+
const range = entryRange(display, first, visible.length);
|
|
321
322
|
result.textContent = rows.length === 0 ? (hint.hidden ? 'No files match this selection.' : '')
|
|
322
|
-
: display.length > pageSize ? `${count(
|
|
323
|
-
:
|
|
324
|
-
: `${count(rows.length)} ${
|
|
323
|
+
: display.length > pageSize && range ? `${count(range[0])}–${count(range[1])} of ${count(rows.length)} ${noun}${of}`
|
|
324
|
+
: display.length > pageSize ? `${count(rows.length)} ${noun}${of}`
|
|
325
|
+
: filtering && listsFiles ? `${count(rows.length)} of ${count(scopeFiles.length)} files`
|
|
326
|
+
: `${count(rows.length)} ${rows.length === 1 ? noun.replace(/s$/, '').replace('entrie', 'entry') : noun}${of}`;
|
|
325
327
|
tableWrap.hidden = rows.length === 0;
|
|
326
328
|
pager.hidden = !result.textContent;
|
|
327
329
|
navigationState.section.hidden = display.length <= pageSize;
|
|
@@ -544,10 +546,9 @@ function directorySummary(entry, analysed, lockfiles, selection) {
|
|
|
544
546
|
panel.setAttribute('aria-label', selection ? 'Selection totals' : 'Folder totals');
|
|
545
547
|
const heading = element('div', 'fx-aside-heading');
|
|
546
548
|
heading.append(element('h2', '', selection ? 'Selection' : entry.path ? basename(entry.path) : 'All files'));
|
|
549
|
+
// The breadcrumbs above name the folder; only a selection needs its words here.
|
|
547
550
|
if (selection)
|
|
548
551
|
heading.append(element('p', 'fx-aside-path fx-aside-selection', selection));
|
|
549
|
-
else if (entry.path.includes('/'))
|
|
550
|
-
heading.append(element('p', 'fx-aside-path', parentPath(entry.path) + '/'));
|
|
551
552
|
const facts = element('dl', 'fx-kv');
|
|
552
553
|
// A measurement the inspection did not take leaves no row behind.
|
|
553
554
|
const quality = entry.quality;
|
|
@@ -578,13 +579,12 @@ function fileDetails(details, entry, navigation, hooks = {}) {
|
|
|
578
579
|
const panel = element('aside', 'fx-aside fx-file');
|
|
579
580
|
panel.setAttribute('aria-label', 'File details');
|
|
580
581
|
const heading = element('div', 'fx-aside-heading');
|
|
582
|
+
// The breadcrumbs above name the folder, so the title is the file alone.
|
|
581
583
|
const title = element('h2', '', basename(entry.path));
|
|
582
584
|
const close = link(navigation.href('metrics', { directory: parentPath(entry.path) }), '', 'fx-close');
|
|
583
585
|
close.setAttribute('aria-label', 'Close file details');
|
|
584
586
|
close.title = 'Close file details';
|
|
585
587
|
heading.append(title, close);
|
|
586
|
-
if (entry.path.includes('/'))
|
|
587
|
-
heading.append(element('p', 'fx-aside-path', parentPath(entry.path) + '/'));
|
|
588
588
|
const facts = element('dl', 'fx-kv');
|
|
589
589
|
const quality = entry.quality;
|
|
590
590
|
if (quality?.codeLines !== undefined)
|
|
@@ -683,6 +683,12 @@ 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
|
+
// The whole path from the repository root is a click away; a refused clipboard shows it in the name's place, selected.
|
|
687
|
+
const named = element('span', 'fx-source-name');
|
|
688
|
+
named.append(name, copyPathButton(file.path, () => {
|
|
689
|
+
name.textContent = file.path;
|
|
690
|
+
return name;
|
|
691
|
+
}));
|
|
686
692
|
const meta = element('span', 'fx-source-meta');
|
|
687
693
|
meta.append(dot, `${language} · ${count(file.lines)} lines`);
|
|
688
694
|
// Lines show the findings, or the tests' coverage where the file has it; without coverage the head stays as it was.
|
|
@@ -700,7 +706,7 @@ function fileView(details, navigation, file, load) {
|
|
|
700
706
|
toggle?.classList.add('fx-source-layer');
|
|
701
707
|
const tools = element('div', 'fx-source-tools');
|
|
702
708
|
tools.append(...toggle ? [toggle] : [], meta);
|
|
703
|
-
head.append(
|
|
709
|
+
head.append(named, tools);
|
|
704
710
|
// The forge's page for the file, at the chosen line, whether or not the text opens here.
|
|
705
711
|
const page = navigation.sourcePage?.(file.path, navigation.line);
|
|
706
712
|
const forge = page ? link(page.href, `View on ${page.provider}`, 'fx-source-forge') : null;
|
|
@@ -739,7 +745,7 @@ function fileView(details, navigation, file, load) {
|
|
|
739
745
|
path: file.path,
|
|
740
746
|
functions: functions.flatMap(record => record.line === null ? [] : [{ line: record.line, complexity: record.complexity, name: record.name }]),
|
|
741
747
|
notes, line: navigation.line, choose,
|
|
742
|
-
coverage: coverage ? lineStates(coverage) : undefined, layer,
|
|
748
|
+
coverage: coverage ? lineStates(coverage) : undefined, hits: coverage ? lineHits(coverage) : undefined, layer,
|
|
743
749
|
});
|
|
744
750
|
const next = fileDetails(details, file, nav, { text, reveal: line => { reveal(line); choose(line); } });
|
|
745
751
|
aside.replaceWith(next);
|
|
@@ -773,6 +779,16 @@ function rememberLayer(layer) {
|
|
|
773
779
|
// Blocked storage only forgets the choice; the URL still carries it.
|
|
774
780
|
}
|
|
775
781
|
}
|
|
782
|
+
/**
|
|
783
|
+
* The entries a page shows, 1-based, counting rows and not the fold of ignored files, which takes a place in the list
|
|
784
|
+
* but is no entry of its own. None where the page holds only the fold.
|
|
785
|
+
*/
|
|
786
|
+
export function entryRange(display, first, shown) {
|
|
787
|
+
const entries = (from, to) => display.slice(from, to).filter(row => row.kind !== 'unread').length;
|
|
788
|
+
const before = entries(0, first);
|
|
789
|
+
const here = entries(first, first + shown);
|
|
790
|
+
return here ? [before + 1, before + here] : null;
|
|
791
|
+
}
|
|
776
792
|
/**
|
|
777
793
|
* The top of a relative colour scale, per level: files against files, folders against the folders at their depth. One
|
|
778
794
|
* scale for both would let a folder's sum outshine every file in it, and the map would read hot folders over pale files.
|
|
@@ -1669,6 +1685,8 @@ function issueGroup(group, navigation, files) {
|
|
|
1669
1685
|
summary.append(identity, severity, element('span', 'fx-issue-count', group.some(finding => finding.effortMinutes !== undefined)
|
|
1670
1686
|
? `${quantity(group.length, 'occurrence')} · ${duration(effort)}` : quantity(group.length, 'occurrence')));
|
|
1671
1687
|
const locations = element('ul', 'fx-event-list fx-occurrences');
|
|
1688
|
+
// The excerpts mark their lines in the finding's own colour, as its severity badge does.
|
|
1689
|
+
locations.dataset.level = item.level;
|
|
1672
1690
|
// The occurrences, and the source they load, are built when the group is first opened: a page of closed groups
|
|
1673
1691
|
// requests nothing.
|
|
1674
1692
|
details.addEventListener('toggle', () => { if (details.open && !locations.childElementCount)
|
|
@@ -1793,6 +1811,38 @@ function ignoreSnippet(finding) {
|
|
|
1793
1811
|
details.append(title, hint, code, feedback);
|
|
1794
1812
|
return details;
|
|
1795
1813
|
}
|
|
1814
|
+
/**
|
|
1815
|
+
* Copies a file's path from the repository root. Where the browser refuses the clipboard, `show` puts the path on the
|
|
1816
|
+
* page and it is selected, for the reader's own copy shortcut.
|
|
1817
|
+
*/
|
|
1818
|
+
function copyPathButton(path, show) {
|
|
1819
|
+
const label = 'Copy path';
|
|
1820
|
+
const copy = element('button', 'fx-copy fx-copy-inline');
|
|
1821
|
+
copy.type = 'button';
|
|
1822
|
+
copy.title = `${label}: ${path}`;
|
|
1823
|
+
copy.setAttribute('aria-label', label);
|
|
1824
|
+
copy.append(copyIcon());
|
|
1825
|
+
const status = element('span', 'visually-hidden');
|
|
1826
|
+
status.setAttribute('role', 'status');
|
|
1827
|
+
copy.append(status);
|
|
1828
|
+
let reset;
|
|
1829
|
+
copy.addEventListener('click', async () => {
|
|
1830
|
+
clearTimeout(reset);
|
|
1831
|
+
try {
|
|
1832
|
+
if (!navigator.clipboard)
|
|
1833
|
+
throw new Error('Clipboard unavailable');
|
|
1834
|
+
await navigator.clipboard.writeText(path);
|
|
1835
|
+
copy.classList.add('fx-copied');
|
|
1836
|
+
status.textContent = 'Path copied';
|
|
1837
|
+
reset = setTimeout(() => { copy.classList.remove('fx-copied'); status.textContent = ''; }, 1500);
|
|
1838
|
+
}
|
|
1839
|
+
catch {
|
|
1840
|
+
window.getSelection()?.selectAllChildren(show());
|
|
1841
|
+
status.textContent = 'Path selected. Press your copy shortcut.';
|
|
1842
|
+
}
|
|
1843
|
+
});
|
|
1844
|
+
return copy;
|
|
1845
|
+
}
|
|
1796
1846
|
/** The common copy glyph, two offset sheets, with the check it turns into once copied. */
|
|
1797
1847
|
export function copyIcon() {
|
|
1798
1848
|
const svg = svgElement('svg');
|
|
@@ -90,16 +90,24 @@ const languages = {
|
|
|
90
90
|
py: 'Python', go: 'Go', rs: 'Rust', java: 'Java', kt: 'Kotlin', kts: 'Kotlin', rb: 'Ruby', php: 'PHP', cs: 'C#',
|
|
91
91
|
c: 'C', h: 'C', cc: 'C++', cpp: 'C++', cxx: 'C++', hpp: 'C++', hh: 'C++', swift: 'Swift', scala: 'Scala',
|
|
92
92
|
vue: 'Vue', svelte: 'Svelte', sh: 'Shell', bash: 'Shell', css: 'CSS', scss: 'SCSS', less: 'Less', html: 'HTML',
|
|
93
|
+
yaml: 'YAML', yml: 'YAML', json: 'JSON', dockerfile: 'Dockerfile',
|
|
93
94
|
};
|
|
95
|
+
/** Files a name alone types: Dockerfile and Containerfile, with or without a suffix such as Dockerfile.dev. */
|
|
96
|
+
const namedLanguages = [[/^(?:dockerfile|containerfile)(?:\..+)?$/i, 'Dockerfile']];
|
|
94
97
|
/** Language colours follow the conventions people already know from code hosts. */
|
|
95
98
|
const languageColors = {
|
|
96
99
|
TypeScript: '#3178c6', JavaScript: '#f1e05a', Python: '#3572a5', Go: '#00add8', Rust: '#dea584', Java: '#b07219',
|
|
97
100
|
Kotlin: '#a97bff', Ruby: '#701516', PHP: '#4f5d95', 'C#': '#178600', C: '#555555', 'C++': '#f34b7d', Swift: '#f05138',
|
|
98
101
|
Scala: '#c22d40', Vue: '#41b883', Svelte: '#ff3e00', Shell: '#89e051', CSS: '#663399', SCSS: '#c6538c', Less: '#1d365d',
|
|
99
102
|
HTML: '#e34c26',
|
|
103
|
+
// Configuration reads beside the code, so it takes quieter tones than the code hosts give it.
|
|
104
|
+
YAML: '#c47d84', JSON: '#9b86b5', Dockerfile: '#4f9a94',
|
|
100
105
|
};
|
|
101
106
|
export function languageOf(path) {
|
|
102
107
|
const name = path.slice(path.lastIndexOf('/') + 1);
|
|
108
|
+
const named = namedLanguages.find(([pattern]) => pattern.test(name));
|
|
109
|
+
if (named)
|
|
110
|
+
return named[1];
|
|
103
111
|
const dot = name.lastIndexOf('.');
|
|
104
112
|
const extension = dot > 0 ? name.slice(dot + 1).toLowerCase() : '';
|
|
105
113
|
return languages[extension] ?? (extension ? extension.toUpperCase() : 'Other');
|
|
@@ -48,12 +48,22 @@ export declare function isSourceLayer(value: string | null | undefined): value i
|
|
|
48
48
|
* state wins: a line a test missed is never shown as covered.
|
|
49
49
|
*/
|
|
50
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;
|
|
51
59
|
export interface SourceOptions {
|
|
52
60
|
readonly path: string;
|
|
53
61
|
readonly functions: readonly SourceFunction[];
|
|
54
62
|
readonly notes: readonly SourceNote[];
|
|
55
63
|
/** Each line's coverage, where the file has a coverage report. */
|
|
56
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;
|
|
57
67
|
/** What the lines show first; the view switches it with setSourceLayer. */
|
|
58
68
|
readonly layer?: SourceLayer | undefined;
|
|
59
69
|
/** The line to bring into view and mark, from the URL. */
|
|
@@ -91,3 +101,10 @@ export type TokenKind = '' | 'c' | 's' | 'n' | 'k';
|
|
|
91
101
|
* template literal stays coloured to its end. Other languages come back as plain text.
|
|
92
102
|
*/
|
|
93
103
|
export declare function tokenizer(path: string): (line: string) => [TokenKind, string][];
|
|
104
|
+
/**
|
|
105
|
+
* The tint a gap of blank and comment lines takes so a run of one state stays one strip: the state of the measured
|
|
106
|
+
* lines on both sides, where they agree. A gap between different states, or at the file's start or end, stays plain.
|
|
107
|
+
*/
|
|
108
|
+
export declare function bridgeStates(states: ReadonlyMap<number, LineState>, codeless: readonly boolean[]): Map<number, LineState>;
|
|
109
|
+
/** A line with no code: blank, or nothing but comment. */
|
|
110
|
+
export declare function codeless(runs: readonly (readonly [TokenKind, string])[]): boolean;
|
|
@@ -75,6 +75,27 @@ export function lineStates(coverage) {
|
|
|
75
75
|
lay(coverage.uncovered, 'uncovered');
|
|
76
76
|
return states;
|
|
77
77
|
}
|
|
78
|
+
/** How often tests ran each line, where the report carries the counts; an older report has none. */
|
|
79
|
+
export function lineHits(coverage) {
|
|
80
|
+
const hits = new Map();
|
|
81
|
+
for (const [from, to, count] of coverage.hits ?? [])
|
|
82
|
+
for (let line = Math.max(1, from); line <= to; line++)
|
|
83
|
+
hits.set(line, count);
|
|
84
|
+
return hits;
|
|
85
|
+
}
|
|
86
|
+
// Two figures are enough for a glance; the tooltip has the whole count.
|
|
87
|
+
const compactCount = new Intl.NumberFormat('en', { notation: 'compact', maximumSignificantDigits: 2 });
|
|
88
|
+
const fullCount = new Intl.NumberFormat();
|
|
89
|
+
/** A count short enough for the gutter: 3×, 980×, 1.2K×, 45K×, 270K×, 3.4M×. */
|
|
90
|
+
export function hitLabel(count) {
|
|
91
|
+
return `${count < 1000 ? count : compactCount.format(count)}×`;
|
|
92
|
+
}
|
|
93
|
+
/** What a measured line says to a pointer and a screen reader: its state, and how often it ran where that is known. */
|
|
94
|
+
export function lineCoverageText(state, count) {
|
|
95
|
+
if (count === undefined || state === 'uncovered')
|
|
96
|
+
return lineStateNames[state];
|
|
97
|
+
return `${lineStateNames[state]}. Ran ${fullCount.format(count)} ${count === 1 ? 'time' : 'times'}`;
|
|
98
|
+
}
|
|
78
99
|
const lineStateNames = {
|
|
79
100
|
covered: 'Covered', partial: 'Partly covered: some branches missed', uncovered: 'Not covered',
|
|
80
101
|
};
|
|
@@ -87,7 +108,10 @@ export function setSourceLayer(container, layer) {
|
|
|
87
108
|
/** The source as numbered lines; returns a function that brings a line into view and marks it. */
|
|
88
109
|
export function renderSource(container, text, options) {
|
|
89
110
|
const lines = text.replace(/\r\n?/g, '\n').replace(/\n$/, '').split('\n');
|
|
90
|
-
|
|
111
|
+
// Tokenized up front, in order, since a comment's state carries from line to line.
|
|
112
|
+
const tokenize = tokenizer(options.path);
|
|
113
|
+
const tokens = lines.map(line => tokenize(line));
|
|
114
|
+
const bridged = options.coverage ? bridgeStates(options.coverage, tokens.map(codeless)) : new Map();
|
|
91
115
|
const starts = new Map(options.functions.map(entry => [entry.line, entry]));
|
|
92
116
|
const notes = new Map();
|
|
93
117
|
for (const note of options.notes)
|
|
@@ -109,15 +133,24 @@ export function renderSource(container, text, options) {
|
|
|
109
133
|
badge.title = `Cyclomatic complexity ${start.complexity}`;
|
|
110
134
|
mark.append(badge);
|
|
111
135
|
}
|
|
112
|
-
// The coverage layer
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
136
|
+
// The coverage layer tints each measured line's gutter cell and writes in it how often the line ran; a miss's red says it.
|
|
137
|
+
// Nothing runs on a blank or comment line: where a tool counts one anyway, or it sits inside a run of one state, it
|
|
138
|
+
// keeps the strip's tint and says nothing.
|
|
139
|
+
const runs = tokens[index];
|
|
140
|
+
const own = options.coverage?.get(number);
|
|
141
|
+
const state = own ?? bridged.get(number);
|
|
142
|
+
if (state && (!own || codeless(runs))) {
|
|
143
|
+
const cell = element('span', `src-cov src-cov-mark-${state}`);
|
|
144
|
+
cell.setAttribute('aria-hidden', 'true');
|
|
145
|
+
mark.append(cell);
|
|
146
|
+
}
|
|
147
|
+
else if (state) {
|
|
148
|
+
const count = options.hits?.get(number);
|
|
149
|
+
const cell = element('span', `src-cov src-cov-mark-${state}`, count === undefined || state === 'uncovered' ? '' : hitLabel(count));
|
|
150
|
+
cell.setAttribute('role', 'img');
|
|
151
|
+
cell.setAttribute('aria-label', lineCoverageText(state, count));
|
|
152
|
+
cell.title = lineCoverageText(state, count);
|
|
153
|
+
mark.append(cell);
|
|
121
154
|
}
|
|
122
155
|
const anchor = element('a', 'src-number', String(number));
|
|
123
156
|
anchor.href = `#L${number}`;
|
|
@@ -127,7 +160,7 @@ export function renderSource(container, text, options) {
|
|
|
127
160
|
options.choose(number);
|
|
128
161
|
});
|
|
129
162
|
const content = element('code', 'src-code');
|
|
130
|
-
content.append(...
|
|
163
|
+
content.append(...runs.map(([kind, value]) => kind ? element('span', `tok-${kind}`, value) : document.createTextNode(value)));
|
|
131
164
|
if (notes.has(number))
|
|
132
165
|
row.classList.add('src-flagged');
|
|
133
166
|
row.append(mark, anchor, content);
|
|
@@ -338,6 +371,33 @@ export function tokenizer(path) {
|
|
|
338
371
|
return runs;
|
|
339
372
|
};
|
|
340
373
|
}
|
|
374
|
+
/**
|
|
375
|
+
* The tint a gap of blank and comment lines takes so a run of one state stays one strip: the state of the measured
|
|
376
|
+
* lines on both sides, where they agree. A gap between different states, or at the file's start or end, stays plain.
|
|
377
|
+
*/
|
|
378
|
+
export function bridgeStates(states, codeless) {
|
|
379
|
+
const bridged = new Map();
|
|
380
|
+
let line = 1;
|
|
381
|
+
while (line <= codeless.length) {
|
|
382
|
+
if (states.has(line) || !codeless[line - 1]) {
|
|
383
|
+
line += 1;
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
let end = line;
|
|
387
|
+
while (end < codeless.length && !states.has(end + 1) && codeless[end])
|
|
388
|
+
end += 1;
|
|
389
|
+
const before = states.get(line - 1);
|
|
390
|
+
if (before && before === states.get(end + 1))
|
|
391
|
+
for (let at = line; at <= end; at++)
|
|
392
|
+
bridged.set(at, before);
|
|
393
|
+
line = end + 1;
|
|
394
|
+
}
|
|
395
|
+
return bridged;
|
|
396
|
+
}
|
|
397
|
+
/** A line with no code: blank, or nothing but comment. */
|
|
398
|
+
export function codeless(runs) {
|
|
399
|
+
return runs.every(([kind, value]) => kind === 'c' || !value.trim());
|
|
400
|
+
}
|
|
341
401
|
function highlighter(path) {
|
|
342
402
|
const tokenize = tokenizer(path);
|
|
343
403
|
return line => tokenize(line).map(([kind, value]) => kind ? element('span', `tok-${kind}`, value) : document.createTextNode(value));
|
|
@@ -7,8 +7,5 @@ export interface SecurityCounts {
|
|
|
7
7
|
readonly low: number;
|
|
8
8
|
readonly unknown: number;
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
11
|
-
* The README badges. Security joins coverage and maintainability only where the export may carry scanner counts:
|
|
12
|
-
* the public export leaves them out, and so leaves the badge out.
|
|
13
|
-
*/
|
|
10
|
+
/** The README badges. Security is available when the inspection recorded scanner counts. */
|
|
14
11
|
export declare function badges(report: PublicHistoryEntry | undefined, quality: QualitySummary | undefined, security?: SecurityCounts): Map<string, Buffer>;
|
|
@@ -2,38 +2,47 @@ import { coverageGrade, securityGrade } from '../../../core/model/quality-summar
|
|
|
2
2
|
/** The report's own grade colours, so a badge in a README reads as the report does. */
|
|
3
3
|
const colors = { A: '#1f9d5a', B: '#74a83a', C: '#d9a400', D: '#ec8a2c', F: '#db4a3f' };
|
|
4
4
|
const unavailable = '#6b7684';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The README badges. Security joins coverage and maintainability only where the export may carry scanner counts:
|
|
8
|
-
* the public export leaves them out, and so leaves the badge out.
|
|
9
|
-
*/
|
|
5
|
+
/** The README badges. Security is available when the inspection recorded scanner counts. */
|
|
10
6
|
export function badges(report, quality, security) {
|
|
11
7
|
const lines = report?.lineCoverage;
|
|
12
8
|
const ratio = lines && lines.total > 0 ? lines.covered / lines.total : null;
|
|
13
9
|
const grade = quality?.maintainability?.grade ?? null;
|
|
14
|
-
|
|
15
|
-
const coverage = ratio === null ? '—'
|
|
16
|
-
: new Intl.NumberFormat('en', { style: 'percent', maximumFractionDigits: 1 }).format(ratio);
|
|
10
|
+
const coverage = lines && lines.total > 0 ? `${BigInt(lines.covered) * 100n / BigInt(lines.total)}%` : '—';
|
|
17
11
|
const files = new Map([
|
|
18
|
-
['coverage.svg', badge('coverage', coverage, ratio === null ? null : coverageGrade(ratio)
|
|
19
|
-
['maintainability.svg', badge('maintainability', grade ?? '—', grade
|
|
12
|
+
['coverage.svg', badge('coverage', coverage, ratio === null ? null : coverageGrade(ratio))],
|
|
13
|
+
['maintainability.svg', badge('maintainability', grade ?? '—', grade)],
|
|
20
14
|
]);
|
|
21
15
|
if (security) {
|
|
22
16
|
const grade = securityGrade(security);
|
|
23
|
-
files.set('security.svg', badge('security', grade, grade
|
|
17
|
+
files.set('security.svg', badge('security', grade, grade));
|
|
24
18
|
}
|
|
25
19
|
return files;
|
|
26
20
|
}
|
|
27
|
-
function badge(name, value, grade
|
|
21
|
+
function badge(name, value, grade) {
|
|
28
22
|
const fill = grade ? colors[grade] : unavailable;
|
|
29
|
-
const
|
|
23
|
+
const labelWidth = Math.max(11, name.length * 7) + 12;
|
|
24
|
+
const valueWidth = Math.max(11, value.length * 7) + 12;
|
|
30
25
|
const width = labelWidth + valueWidth;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
<
|
|
35
|
-
<
|
|
36
|
-
<
|
|
26
|
+
const labelCenter = labelWidth / 2;
|
|
27
|
+
const valueCenter = labelWidth + valueWidth / 2;
|
|
28
|
+
return Buffer.from(`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="20" viewBox="0 0 ${width} 20" role="img" aria-label="${name}: ${value}">
|
|
29
|
+
<defs>
|
|
30
|
+
<clipPath id="badge"><rect width="${width}" height="20" rx="3"/></clipPath>
|
|
31
|
+
<linearGradient id="shade" x2="0" y2="100%">
|
|
32
|
+
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
|
33
|
+
<stop offset="1" stop-color="#000" stop-opacity=".1"/>
|
|
34
|
+
</linearGradient>
|
|
35
|
+
</defs>
|
|
36
|
+
<g clip-path="url(#badge)">
|
|
37
|
+
<rect width="${labelWidth}" height="20" fill="#555"/>
|
|
38
|
+
<rect x="${labelWidth}" width="${valueWidth}" height="20" fill="${fill}"/>
|
|
39
|
+
<rect width="${width}" height="20" fill="url(#shade)"/>
|
|
40
|
+
</g>
|
|
41
|
+
<g aria-hidden="true" fill="#fff" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11" text-anchor="middle">
|
|
42
|
+
<text x="${labelCenter}" y="15" fill="#010101" fill-opacity=".3">${name}</text>
|
|
43
|
+
<text x="${valueCenter}" y="15" fill="#010101" fill-opacity=".3">${value}</text>
|
|
44
|
+
<text x="${labelCenter}" y="14">${name}</text>
|
|
45
|
+
<text x="${valueCenter}" y="14">${value}</text>
|
|
37
46
|
</g>
|
|
38
47
|
</svg>\n`);
|
|
39
48
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { isRecord } from '../../../core/engine/plugin.js';
|
|
2
2
|
import { definitions } from '../../../core/model/measurement.js';
|
|
3
3
|
import { qualitySummary } from '../../../core/model/quality-summary.js';
|
|
4
|
-
import {
|
|
5
|
-
import { findingImportMethods } from '../../../core/model/scanner-import.js';
|
|
4
|
+
import { securityCounts } from './security-summary.js';
|
|
6
5
|
import { compareHistoryEntries } from '../wire/public-history-model.js';
|
|
7
6
|
import { inspectionProfileDigest } from './inspection-context.js';
|
|
8
7
|
import { reportRevision } from '../validation/report.js';
|
|
@@ -12,15 +11,7 @@ export function commitSummary(report) {
|
|
|
12
11
|
const history = historyEntry(report);
|
|
13
12
|
const profileDigest = inspectionProfileDigest(report);
|
|
14
13
|
const metrics = metricProjection(report);
|
|
15
|
-
const
|
|
16
|
-
.some(({ category }) => isSensitiveFinding(category));
|
|
17
|
-
const security = tracksSecurity ? { low: 0, medium: 0, high: 0, unknown: 0 } : undefined;
|
|
18
|
-
if (security) {
|
|
19
|
-
for (const finding of report.findings ?? []) {
|
|
20
|
-
if (isSensitiveFinding(finding.category))
|
|
21
|
-
security[finding.level]++;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
14
|
+
const security = securityCounts(report);
|
|
24
15
|
return {
|
|
25
16
|
...history,
|
|
26
17
|
...(report.commit === undefined ? {} : { subject: report.commit.subject, author: report.commit.author }),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from 'node:util';
|
|
2
2
|
import { isRecord } from '../../../core/engine/plugin.js';
|
|
3
|
-
import { isSensitiveFinding } from '../../../core/model/finding.js';
|
|
4
3
|
import { findingImportMethods } from '../../../core/model/scanner-import.js';
|
|
4
|
+
import { nativeScanners, securityCounts } from './security-summary.js';
|
|
5
5
|
import { normalizeFindingIgnore } from '../../../core/model/finding-ignore.js';
|
|
6
6
|
import { comparePaths, digest } from '../../../core/model/snapshot.js';
|
|
7
7
|
export function inspectionProfileDigest(report) {
|
|
@@ -44,17 +44,11 @@ function ignoreContext(report) {
|
|
|
44
44
|
}
|
|
45
45
|
function scannerContext(report) {
|
|
46
46
|
const methods = findingImportMethods(report.appliedConfig.findingImports);
|
|
47
|
-
|
|
47
|
+
const sources = [...methods.flatMap(({ tools }) => tools), ...nativeScanners(report)];
|
|
48
|
+
if (!methods.length && !sources.length)
|
|
48
49
|
return {};
|
|
49
|
-
const scanners = [...new Map(
|
|
50
|
-
const security =
|
|
51
|
-
? { low: 0, medium: 0, high: 0, unknown: 0 } : undefined;
|
|
52
|
-
if (security) {
|
|
53
|
-
for (const finding of report.findings ?? []) {
|
|
54
|
-
if (isSensitiveFinding(finding.category))
|
|
55
|
-
security[finding.level]++;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
50
|
+
const scanners = [...new Map(sources.map(tool => [JSON.stringify(tool), tool])).values()];
|
|
51
|
+
const security = securityCounts(report);
|
|
58
52
|
return security ? { scanners, security } : { scanners };
|
|
59
53
|
}
|
|
60
54
|
function readProfile(config) {
|
|
@@ -73,7 +67,7 @@ function readProfile(config) {
|
|
|
73
67
|
const { inputDigest, inputDigests, pathBase, ...settings } = coverage;
|
|
74
68
|
coverage = settings;
|
|
75
69
|
}
|
|
76
|
-
const { churnWindow, ...settings } = config;
|
|
70
|
+
const { churnWindow, securityScanners, ...settings } = config;
|
|
77
71
|
// The policy is stable across commits; its matched paths describe this snapshot alone.
|
|
78
72
|
const { generatedExcluded, ...sourceSettings } = source;
|
|
79
73
|
return {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Report } from '../../../core/model/report.js';
|
|
2
|
+
export declare function nativeScanners(report: Report): readonly {
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
}[];
|
|
6
|
+
export declare function securityCounts(report: Report): {
|
|
7
|
+
low: number;
|
|
8
|
+
medium: number;
|
|
9
|
+
high: number;
|
|
10
|
+
unknown: number;
|
|
11
|
+
} | undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isRecord } from '../../../core/engine/plugin.js';
|
|
2
|
+
import { isSensitiveFinding } from '../../../core/model/finding.js';
|
|
3
|
+
import { findingImportMethods } from '../../../core/model/scanner-import.js';
|
|
4
|
+
export function nativeScanners(report) {
|
|
5
|
+
const scanners = report.appliedConfig.securityScanners;
|
|
6
|
+
if (!Array.isArray(scanners))
|
|
7
|
+
return [];
|
|
8
|
+
return scanners.flatMap((scanner) => isRecord(scanner) && typeof scanner.name === 'string' && typeof scanner.version === 'string'
|
|
9
|
+
? [{ name: scanner.name, version: scanner.version }] : []);
|
|
10
|
+
}
|
|
11
|
+
export function securityCounts(report) {
|
|
12
|
+
const imported = findingImportMethods(report.appliedConfig.findingImports).some(({ category }) => isSensitiveFinding(category));
|
|
13
|
+
if (!imported && !nativeScanners(report).length)
|
|
14
|
+
return undefined;
|
|
15
|
+
const counts = { low: 0, medium: 0, high: 0, unknown: 0 };
|
|
16
|
+
for (const finding of report.findings ?? []) {
|
|
17
|
+
if (isSensitiveFinding(finding.category))
|
|
18
|
+
counts[finding.level]++;
|
|
19
|
+
}
|
|
20
|
+
return counts;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=security-summary.js.map
|