repometry 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/package.json +1 -1
  2. package/target/main/resources/report/json/report-v2.schema.json +12 -1
  3. package/target/main/resources/viewer/files.css +6 -2
  4. package/target/main/ts/api/git/git.d.ts +1 -1
  5. package/target/main/ts/api/git/git.js +21 -5
  6. package/target/main/ts/api/git/inspection-source.d.ts +1 -1
  7. package/target/main/ts/api/git/inspection-source.js +10 -4
  8. package/target/main/ts/api/git/local.d.ts +1 -1
  9. package/target/main/ts/api/git/local.js +29 -10
  10. package/target/main/ts/api/worker/worker-protocol.js +34 -9
  11. package/target/main/ts/compose/analyze-snapshot.d.ts +1 -0
  12. package/target/main/ts/compose/analyze-snapshot.js +50 -17
  13. package/target/main/ts/compose/inspect.js +2 -2
  14. package/target/main/ts/compose/plugin-list.js +2 -1
  15. package/target/main/ts/compose/security-plugins.d.ts +1 -0
  16. package/target/main/ts/compose/security-plugins.js +7 -0
  17. package/target/main/ts/core/engine/manifest.js +3 -2
  18. package/target/main/ts/core/engine/plugin.d.ts +2 -0
  19. package/target/main/ts/core/model/line-coverage.d.ts +2 -0
  20. package/target/main/ts/core/model/line-coverage.js +19 -1
  21. package/target/main/ts/core/model/source.d.ts +3 -0
  22. package/target/main/ts/core/model/source.js +4 -1
  23. package/target/main/ts/core/usecases/inspect.js +2 -2
  24. package/target/main/ts/plugins/coverage/coverage.d.ts +4 -3
  25. package/target/main/ts/plugins/coverage/coverage.js +46 -17
  26. package/target/main/ts/plugins/language-js/js-security.d.ts +4 -0
  27. package/target/main/ts/plugins/language-js/js-security.js +508 -0
  28. package/target/main/ts/plugins/security/actions-security.d.ts +2 -0
  29. package/target/main/ts/plugins/security/actions-security.js +581 -0
  30. package/target/main/ts/plugins/security/dockerfile.d.ts +2 -0
  31. package/target/main/ts/plugins/security/dockerfile.js +488 -0
  32. package/target/main/ts/plugins/security/npm-supply-chain.d.ts +4 -0
  33. package/target/main/ts/plugins/security/npm-supply-chain.js +368 -0
  34. package/target/main/ts/plugins/security/secrets.d.ts +12 -0
  35. package/target/main/ts/plugins/security/secrets.js +254 -0
  36. package/target/main/ts/report/html/app/viewer-files.d.ts +7 -0
  37. package/target/main/ts/report/html/app/viewer-files.js +17 -3
  38. package/target/main/ts/report/html/app/viewer-filter.js +8 -0
  39. package/target/main/ts/report/html/app/viewer-source.d.ts +6 -0
  40. package/target/main/ts/report/html/app/viewer-source.js +34 -7
  41. package/target/main/ts/report/html/site/badges.d.ts +1 -4
  42. package/target/main/ts/report/html/site/badges.js +28 -19
  43. package/target/main/ts/report/json/projections/commit-summary.js +2 -11
  44. package/target/main/ts/report/json/projections/inspection-context.js +6 -12
  45. package/target/main/ts/report/json/projections/security-summary.d.ts +11 -0
  46. package/target/main/ts/report/json/projections/security-summary.js +22 -0
@@ -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(first + 1)}–${count(first + visible.length)} of ${count(rows.length)} ${noun}${of}`
323
- : filtering && listsFiles ? `${count(rows.length)} of ${count(scopeFiles.length)} files`
324
- : `${count(rows.length)} ${rows.length === 1 ? noun.replace(/s$/, '').replace('entrie', 'entry') : noun}${of}`;
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;
@@ -777,6 +779,16 @@ function rememberLayer(layer) {
777
779
  // Blocked storage only forgets the choice; the URL still carries it.
778
780
  }
779
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
+ }
780
792
  /**
781
793
  * The top of a relative colour scale, per level: files against files, folders against the folders at their depth. One
782
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.
@@ -1673,6 +1685,8 @@ function issueGroup(group, navigation, files) {
1673
1685
  summary.append(identity, severity, element('span', 'fx-issue-count', group.some(finding => finding.effortMinutes !== undefined)
1674
1686
  ? `${quantity(group.length, 'occurrence')} · ${duration(effort)}` : quantity(group.length, 'occurrence')));
1675
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;
1676
1690
  // The occurrences, and the source they load, are built when the group is first opened: a page of closed groups
1677
1691
  // requests nothing.
1678
1692
  details.addEventListener('toggle', () => { if (details.open && !locations.childElementCount)
@@ -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');
@@ -101,5 +101,11 @@ export type TokenKind = '' | 'c' | 's' | 'n' | 'k';
101
101
  * template literal stays coloured to its end. Other languages come back as plain text.
102
102
  */
103
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>;
104
110
  /** A line with no code: blank, or nothing but comment. */
105
111
  export declare function codeless(runs: readonly (readonly [TokenKind, string])[]): boolean;
@@ -77,10 +77,8 @@ export function lineStates(coverage) {
77
77
  }
78
78
  /** How often tests ran each line, where the report carries the counts; an older report has none. */
79
79
  export function lineHits(coverage) {
80
- // The wire is getting `hits`; until it lands the field is read off the record as the agreed shape.
81
- const runs = coverage.hits;
82
80
  const hits = new Map();
83
- for (const [from, to, count] of runs ?? [])
81
+ for (const [from, to, count] of coverage.hits ?? [])
84
82
  for (let line = Math.max(1, from); line <= to; line++)
85
83
  hits.set(line, count);
86
84
  return hits;
@@ -110,7 +108,10 @@ export function setSourceLayer(container, layer) {
110
108
  /** The source as numbered lines; returns a function that brings a line into view and marks it. */
111
109
  export function renderSource(container, text, options) {
112
110
  const lines = text.replace(/\r\n?/g, '\n').replace(/\n$/, '').split('\n');
111
+ // Tokenized up front, in order, since a comment's state carries from line to line.
113
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();
114
115
  const starts = new Map(options.functions.map(entry => [entry.line, entry]));
115
116
  const notes = new Map();
116
117
  for (const note of options.notes)
@@ -133,10 +134,12 @@ export function renderSource(container, text, options) {
133
134
  mark.append(badge);
134
135
  }
135
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.
136
- // Some tools count blank and comment lines as run; nothing runs there, so they keep the strip's tint and say nothing.
137
- const runs = tokenize(line);
138
- const state = options.coverage?.get(number);
139
- if (state && codeless(runs)) {
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))) {
140
143
  const cell = element('span', `src-cov src-cov-mark-${state}`);
141
144
  cell.setAttribute('aria-hidden', 'true');
142
145
  mark.append(cell);
@@ -368,6 +371,30 @@ export function tokenizer(path) {
368
371
  return runs;
369
372
  };
370
373
  }
374
+ /**
375
+ * The tint a gap of blank and comment lines takes so the strip has no breaks: the state of the measured line above it,
376
+ * 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
377
+ * takes its other neighbour, and one with no measured neighbour stays plain.
378
+ */
379
+ export function bridgeStates(states, codeless) {
380
+ const bridged = new Map();
381
+ let line = 1;
382
+ while (line <= codeless.length) {
383
+ if (states.has(line) || !codeless[line - 1]) {
384
+ line += 1;
385
+ continue;
386
+ }
387
+ let end = line;
388
+ while (end < codeless.length && !states.has(end + 1) && codeless[end])
389
+ end += 1;
390
+ const state = states.get(line - 1) ?? states.get(end + 1);
391
+ if (state)
392
+ for (let at = line; at <= end; at++)
393
+ bridged.set(at, state);
394
+ line = end + 1;
395
+ }
396
+ return bridged;
397
+ }
371
398
  /** A line with no code: blank, or nothing but comment. */
372
399
  export function codeless(runs) {
373
400
  return runs.every(([kind, value]) => kind === 'c' || !value.trim());
@@ -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
- const label = '#0f1720';
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
- // A missing measurement is one mark, not a word.
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), 68)],
19
- ['maintainability.svg', badge('maintainability', grade ?? '—', grade, 112)],
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, 64));
17
+ files.set('security.svg', badge('security', grade, grade));
24
18
  }
25
19
  return files;
26
20
  }
27
- function badge(name, value, grade, labelWidth) {
21
+ function badge(name, value, grade) {
28
22
  const fill = grade ? colors[grade] : unavailable;
29
- const valueWidth = Math.max(30, value.length * 8 + 14);
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
- return Buffer.from(`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="26" viewBox="0 0 ${width} 26" role="img" aria-label="${name}: ${value}">
32
- <rect width="${width}" height="26" rx="5" fill="${fill}"/>
33
- <path d="M0 5a5 5 0 0 1 5-5h${labelWidth - 5}v26H5a5 5 0 0 1-5-5Z" fill="${label}"/>
34
- <g fill="#fff" font-family="system-ui,sans-serif" font-size="12" font-weight="600" text-anchor="middle">
35
- <text x="${labelWidth / 2}" y="17">${name}</text>
36
- <text x="${labelWidth + valueWidth / 2}" y="17">${value}</text>
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 { isSensitiveFinding } from '../../../core/model/finding.js';
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 tracksSecurity = findingImportMethods(report.appliedConfig.findingImports)
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
- if (!methods.length)
47
+ const sources = [...methods.flatMap(({ tools }) => tools), ...nativeScanners(report)];
48
+ if (!methods.length && !sources.length)
48
49
  return {};
49
- const scanners = [...new Map(methods.flatMap(({ tools }) => tools.map(tool => [JSON.stringify(tool), tool]))).values()];
50
- const security = methods.some(({ category }) => isSensitiveFinding(category))
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