@repometry/cli 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +10 -5
  2. package/package.json +3 -3
  3. package/target/main/resources/licenses/spdx.json +746 -0
  4. package/target/main/resources/report/json/config-v2.schema.json +2 -1
  5. package/target/main/resources/report/json/file-metrics-v1.schema.json +2 -0
  6. package/target/main/resources/report/json/report-v2.schema.json +6 -3
  7. package/target/main/resources/report/json/repository-summary-v1.schema.json +14 -0
  8. package/target/main/resources/viewer/index.html +5 -1
  9. package/target/main/resources/viewer/styles.css +7 -3
  10. package/target/main/ts/api/git/git.d.ts +2 -1
  11. package/target/main/ts/api/git/git.js +4 -4
  12. package/target/main/ts/api/git/inspection-source.js +2 -2
  13. package/target/main/ts/api/git/local.d.ts +1 -1
  14. package/target/main/ts/api/git/local.js +5 -4
  15. package/target/main/ts/api/import/finding-import.js +2 -9
  16. package/target/main/ts/api/import/license-import.d.ts +2 -0
  17. package/target/main/ts/api/import/license-import.js +36 -0
  18. package/target/main/ts/api/import/repository-path.d.ts +1 -0
  19. package/target/main/ts/api/import/repository-path.js +10 -0
  20. package/target/main/ts/cli/distribution.d.ts +8 -0
  21. package/target/main/ts/cli/distribution.js +23 -0
  22. package/target/main/ts/cli/imports.d.ts +2 -0
  23. package/target/main/ts/cli/imports.js +6 -2
  24. package/target/main/ts/cli/run.d.ts +2 -2
  25. package/target/main/ts/cli/run.js +17 -8
  26. package/target/main/ts/compose/analysis-report.js +5 -2
  27. package/target/main/ts/compose/analysis-results.d.ts +3 -2
  28. package/target/main/ts/compose/analysis-results.js +15 -6
  29. package/target/main/ts/compose/analysis-steps.js +3 -0
  30. package/target/main/ts/compose/analyze-snapshot.d.ts +1 -1
  31. package/target/main/ts/compose/analyze-snapshot.js +7 -4
  32. package/target/main/ts/compose/built-ins.d.ts +2 -2
  33. package/target/main/ts/compose/built-ins.js +2 -2
  34. package/target/main/ts/compose/inspect.d.ts +2 -0
  35. package/target/main/ts/compose/inspect.js +7 -4
  36. package/target/main/ts/compose/load-plugins.js +4 -2
  37. package/target/main/ts/compose/phases.d.ts +7 -3
  38. package/target/main/ts/compose/phases.js +26 -10
  39. package/target/main/ts/plugins/built-in.d.ts +2 -0
  40. package/target/main/ts/plugins/built-in.js +4 -1
  41. package/target/main/ts/plugins/json-spans.d.ts +11 -0
  42. package/target/main/ts/plugins/json-spans.js +86 -0
  43. package/target/main/ts/plugins/legal/composer-lock.d.ts +2 -0
  44. package/target/main/ts/plugins/legal/composer-lock.js +24 -0
  45. package/target/main/ts/plugins/legal/dependencies.d.ts +73 -0
  46. package/target/main/ts/plugins/legal/dependencies.js +27 -0
  47. package/target/main/ts/plugins/legal/licenses.d.ts +19 -0
  48. package/target/main/ts/plugins/legal/licenses.js +112 -0
  49. package/target/main/ts/plugins/legal/npm-lock.d.ts +3 -0
  50. package/target/main/ts/plugins/legal/npm-lock.js +30 -0
  51. package/target/main/ts/plugins/legal/policy.d.ts +72 -0
  52. package/target/main/ts/plugins/legal/policy.js +149 -0
  53. package/target/main/ts/plugins/legal/sbom.d.ts +3 -0
  54. package/target/main/ts/plugins/legal/sbom.js +131 -0
  55. package/target/main/ts/plugins/legal/unverified-lock.d.ts +1 -0
  56. package/target/main/ts/plugins/legal/unverified-lock.js +21 -0
  57. package/target/main/ts/plugins/security/npm-supply-chain.js +2 -86
  58. package/target/main/ts/report/html/app/viewer-issue-group.js +1 -1
  59. package/target/main/ts/report/html/app/viewer-metric-registry.js +1 -1
  60. package/target/main/ts/report/html/app/viewer-metrics.d.ts +2 -1
  61. package/target/main/ts/report/html/app/viewer-metrics.js +7 -2
  62. package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +1 -0
  63. package/target/main/ts/report/html/app/viewer-overview-cards.js +20 -19
  64. package/target/main/ts/report/html/app/viewer-overview-lead.js +4 -1
  65. package/target/main/ts/report/html/app/viewer-shell.js +3 -1
  66. package/target/main/ts/report/html/app/viewer-tokenizer.js +35 -8
  67. package/target/main/ts/report/html/app/viewer-trend-data.js +1 -0
  68. package/target/main/ts/report/html/app/viewer.js +5 -2
  69. package/target/main/ts/report/json/validation/report.js +2 -2
@@ -1,9 +1,7 @@
1
1
  import { byId, count, percent, quantity } from './viewer-dom.js';
2
2
  import { codeSmellCategories, securityCategories } from './viewer-files.js';
3
- import { coverageGrade, formatMetric, gradeScope, metricValue, pluginSpec, securityGrades, securityRisks } from './viewer-metrics.js';
3
+ import { coverageGrade, gradeScope, legalFindings, securityGrades, securityRisks } from './viewer-metrics.js';
4
4
  import { href } from './viewer-route.js';
5
- /** Coverage kinds beyond lines, by their registry keys, in the words the Overview card uses for them. */
6
- const coverageKinds = [['branch-coverage', 'Branches'], ['function-coverage', 'Functions']];
7
5
  /** A detail that counts something leads to exactly what it counts, where the report has a page for it. */
8
6
  export function detailText(id, text, link) {
9
7
  if (link === undefined) {
@@ -22,6 +20,9 @@ export function smellsLink(sha) {
22
20
  export function securityLink(sha, level) {
23
21
  return href({ page: 'issues', sha, category: securityCategories.join(','), ...level ? { level } : {} });
24
22
  }
23
+ export function legalLink(sha) {
24
+ return href({ page: 'issues', sha, category: 'legal' });
25
+ }
25
26
  export function uncoveredLink(sha) {
26
27
  return href({ page: 'hotspots', sha, rank: 'missedLines' });
27
28
  }
@@ -46,21 +47,6 @@ function ring(ratio) {
46
47
  svg.append(...(ratio !== null && ratio > 0 ? [track, arc] : [track]));
47
48
  return svg;
48
49
  }
49
- /** Line coverage leads; the other kinds the coverage report carries follow on a quieter line. */
50
- function renderCoverageKinds(report) {
51
- const kinds = coverageKinds.flatMap(([key, name]) => {
52
- const metric = key;
53
- const value = pluginSpec(metric) ? metricValue(report, metric, undefined) : null;
54
- if (value === null)
55
- return [];
56
- // Each kind keeps its number; a narrow card wraps between kinds, never inside one.
57
- const kind = document.createElement('span');
58
- kind.textContent = `${name} ${formatMetric(value, metric)}`;
59
- return [kind];
60
- });
61
- byId('coverage-kinds').replaceChildren(...kinds.flatMap((kind, index) => index ? [' · ', kind] : [kind]));
62
- byId('coverage-kinds').hidden = kinds.length === 0;
63
- }
64
50
  export function renderInspection(report) {
65
51
  const lines = report.lineCoverage;
66
52
  const coverage = lines && lines.total > 0 ? lines.covered / lines.total : null;
@@ -75,7 +61,6 @@ export function renderInspection(report) {
75
61
  delete mark.dataset.grade;
76
62
  else
77
63
  mark.dataset.grade = coverageGrade(coverage);
78
- renderCoverageKinds(report);
79
64
  }
80
65
  export function renderQuality(report, quality) {
81
66
  const maintainability = quality?.maintainability ?? null;
@@ -89,6 +74,22 @@ export function renderQuality(report, quality) {
89
74
  const scope = byId('maintainability-scope');
90
75
  scope.textContent = gradeScope(quality) ?? '';
91
76
  scope.hidden = !scope.textContent;
77
+ renderLegal(report.sha, quality?.legal);
78
+ }
79
+ function renderLegal(sha, legal) {
80
+ const mark = byId('legal-mark');
81
+ mark.textContent = legal?.grade ?? '–';
82
+ mark.dataset.grade = legal?.grade ?? 'none';
83
+ const scope = byId('legal-scope');
84
+ if (legal === undefined) {
85
+ scope.textContent = 'Add a lockfile with license data or import an SBOM.';
86
+ detailText('legal-detail', 'No license data');
87
+ return;
88
+ }
89
+ const { checked } = legal;
90
+ scope.textContent = count(checked) + (checked === 1 ? ' dependency checked' : ' dependencies checked');
91
+ const findings = legalFindings(legal);
92
+ detailText('legal-detail', findings ? quantity(findings, 'finding') : 'No findings', findings ? legalLink(sha) : undefined);
92
93
  }
93
94
  /** The words of the five steps, as every grade has them: clear A, low B, medium C, high D, critical F. */
94
95
  const severities = ['clear', 'low', 'medium', 'high', 'critical'];
@@ -1,6 +1,6 @@
1
1
  import { byId, parentPath } from './viewer-dom.js';
2
2
  import { difference, formatMetric, labelOf, metricValue } from './viewer-metrics.js';
3
- import { securityLink, smellsLink, uncoveredLink } from './viewer-overview-cards.js';
3
+ import { legalLink, securityLink, smellsLink, uncoveredLink } from './viewer-overview-cards.js';
4
4
  import { href } from './viewer-route.js';
5
5
  import { commitTime } from './viewer-trend-data.js';
6
6
  const dateTime = new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' });
@@ -11,12 +11,14 @@ const dateTime = new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeS
11
11
  const areas = {
12
12
  debt: ['debt', 'effort', 'duplication', 'complexity'],
13
13
  coverage: ['coverage', 'coverable-lines', 'covered-lines', 'uncovered-lines'],
14
+ legal: ['legal'],
14
15
  security: ['security', 'security-high', 'security-medium', 'security-low'],
15
16
  complexity: ['complexity', 'functions', 'cognitive', 'code-lines'],
16
17
  };
17
18
  const emptyAreas = {
18
19
  coverage: 'No coverage report for this commit.',
19
20
  security: 'No security scanner report for this commit.',
21
+ legal: 'No license data for this commit.',
20
22
  };
21
23
  /** The figures that count findings lead to them; uncovered lines lead to the files that hold them. */
22
24
  const findingLinks = {
@@ -24,6 +26,7 @@ const findingLinks = {
24
26
  duplication: sha => href({ page: 'issues', sha, category: 'duplication' }),
25
27
  'uncovered-lines': uncoveredLink,
26
28
  security: sha => securityLink(sha),
29
+ legal: legalLink,
27
30
  'security-high': sha => securityLink(sha, 'high'),
28
31
  'security-medium': sha => securityLink(sha, 'medium'),
29
32
  'security-low': sha => securityLink(sha, 'low'),
@@ -7,7 +7,9 @@ import { renderSeries } from './viewer-trend-series.js';
7
7
  export function firstArea({ reports, quality }) {
8
8
  if (reports.some(report => quality[report.sha]?.maintainability?.debtRatio != null))
9
9
  return 'debt';
10
- return reports.some(report => report.lineCoverage !== null) ? 'coverage' : 'complexity';
10
+ if (reports.some(report => report.lineCoverage !== null))
11
+ return 'coverage';
12
+ return reports.some(report => quality[report.sha]?.legal !== undefined) ? 'legal' : 'complexity';
11
13
  }
12
14
  /** The Overview's quality tabs: one selected and focusable, the arrows moving between the visible ones. */
13
15
  export function verdictTabs(select) {
@@ -2,11 +2,11 @@ import { element } from './viewer-dom.js';
2
2
  import { languageIdOf, syntaxOf } from './viewer-languages.js';
3
3
  const form = (kind, start, end, multiline = false, raw = false) => ({ kind, start, end, multiline, raw });
4
4
  /** The syntax data in the shape the scanner reads: forms longest marker first, words as sets. */
5
- function grammarOf({ lineComments = [], blockComments = [], strings = [], stringPrefixes = [], keywords, regexAfter }) {
5
+ function grammarOf({ lineComments = [], blockComments = [], strings = [], stringPrefixes = [], keywords, regexAfter, nestedBlockComments }) {
6
6
  const forms = [
7
7
  ...lineComments.map(start => form('c', start, '', false, true)),
8
- ...blockComments.map(([start, end]) => form('c', start, end, true, true)),
9
- ...strings.map(({ quote, multiline, raw }) => form('s', quote, quote, multiline, raw)),
8
+ ...blockComments.map(([start, end]) => ({ ...form('c', start, end, true, true), nested: nestedBlockComments })),
9
+ ...strings.map(({ quote, end = quote, multiline, raw, doubleEnd }) => ({ ...form('s', quote, end, multiline, raw), doubleEnd })),
10
10
  ];
11
11
  return {
12
12
  // Longest marker first; the sort is stable, so on equal length a comment, listed first, wins.
@@ -21,9 +21,17 @@ function closeAt(line, from, open) {
21
21
  if (!open.end)
22
22
  return [line.length, true];
23
23
  let at = from;
24
- while (at < line.length && !line.startsWith(open.end, at))
25
- at += !open.raw && line[at] === '\\' ? 2 : 1;
26
- return at < line.length ? [at + open.end.length, true] : [line.length, false];
24
+ while (at < line.length) {
25
+ if (line.startsWith(open.end, at)) {
26
+ const next = at + open.end.length;
27
+ if (!open.doubleEnd || !line.startsWith(open.end, next))
28
+ return [next, true];
29
+ at = next + open.end.length;
30
+ }
31
+ else
32
+ at += !open.raw && line[at] === '\\' ? 2 : 1;
33
+ }
34
+ return [line.length, false];
27
35
  }
28
36
  /** Takes the run up to `stop` as one token. */
29
37
  function take(cursor, kind, stop) {
@@ -37,15 +45,34 @@ function close(state, closed) {
37
45
  }
38
46
  /** Inside a form that an earlier line or run left open: up to its end, or the whole line. */
39
47
  function inside(cursor, open) {
40
- const [stop, closed] = closeAt(cursor.line, cursor.at, open);
48
+ const [stop, closed] = open.nested ? closeNested(cursor, open) : closeAt(cursor.line, cursor.at, open);
41
49
  take(cursor, open.kind, stop);
42
50
  if (closed)
43
51
  close(cursor.state, open);
44
52
  }
53
+ /** Scans an active block-comment pair until its last outstanding opener closes. */
54
+ function closeNested({ line, at, state }, open) {
55
+ while (at < line.length) {
56
+ if (line.startsWith(open.end, at)) {
57
+ at += open.end.length;
58
+ if (--state.commentDepth === 0)
59
+ return [at, true];
60
+ }
61
+ else if (line.startsWith(open.start, at)) {
62
+ state.commentDepth++;
63
+ at += open.start.length;
64
+ }
65
+ else
66
+ at++;
67
+ }
68
+ return [line.length, false];
69
+ }
45
70
  /** Opens a form after `prefix` characters: a multi-line one as its start marker, left open; another to its end. */
46
71
  function begin(cursor, opened, prefix) {
47
72
  const body = cursor.at + prefix + opened.start.length;
48
73
  take(cursor, opened.kind, opened.multiline ? body : closeAt(cursor.line, body, opened)[0]);
74
+ if (opened.nested)
75
+ cursor.state.commentDepth = 1;
49
76
  if (opened.multiline)
50
77
  cursor.state.open = opened;
51
78
  else
@@ -177,7 +204,7 @@ function scanLine(cursor) {
177
204
  }
178
205
  }
179
206
  function scanLines(grammar, scan) {
180
- const state = { open: undefined, regexAllowed: true };
207
+ const state = { open: undefined, commentDepth: 0, regexAllowed: true };
181
208
  return line => {
182
209
  const collected = runs();
183
210
  scan({ line, grammar, at: 0, state, push: collected.push });
@@ -16,6 +16,7 @@ const builtinGroups = [
16
16
  // Branch and function coverage come from the registry, where the coverage report has them.
17
17
  ['Coverage', ['coverage', 'branch-coverage', 'function-coverage', 'diff-coverage']],
18
18
  ['Security', ['security']],
19
+ ['Legal', ['legal']],
19
20
  ['Size', ['code-lines', 'files', 'functions', 'classes', 'comments']],
20
21
  ];
21
22
  /** A view the registry names, not one the viewer draws by hand. */
@@ -73,11 +73,12 @@ function start(data) {
73
73
  }, branch);
74
74
  const markVerdict = verdictTabs(metric => {
75
75
  chartMetric = metric;
76
+ byId('overview-hotspots').hidden = chartMetric === 'legal';
76
77
  const { sha } = route();
77
78
  renderTrend(trendData(), bySha.get(sha), chartMetric, compact.matches);
78
79
  renderLead(reports, bySha.get(sha), history, chartMetric, cached.get(sha));
79
80
  const details = cached.get(sha);
80
- if (details)
81
+ if (details && chartMetric !== 'legal')
81
82
  renderOverviewHotspots(details, sha, chartMetric, context[sha]?.security !== undefined);
82
83
  });
83
84
  markVerdict(chartMetric);
@@ -169,7 +170,8 @@ function start(data) {
169
170
  }
170
171
  // The details name the most complex function, so its figure can now lead to its line.
171
172
  renderLead(reports, report, history, chartMetric, details);
172
- renderOverviewHotspots(details, report.sha, chartMetric, context[report.sha]?.security !== undefined);
173
+ if (chartMetric !== 'legal')
174
+ renderOverviewHotspots(details, report.sha, chartMetric, context[report.sha]?.security !== undefined);
173
175
  };
174
176
  const existing = cached.get(report.sha);
175
177
  if (existing) {
@@ -199,6 +201,7 @@ function start(data) {
199
201
  showPage(current);
200
202
  renderInspection(report);
201
203
  renderQuality(report, quality[report.sha]);
204
+ byId('overview-hotspots').hidden = chartMetric === 'legal';
202
205
  if (page === 'overview')
203
206
  renderLead(reports, report, history, chartMetric, cached.get(report.sha));
204
207
  renderScannerContext(context?.[current.sha], report.sha);
@@ -59,8 +59,8 @@ export function readReport(value) {
59
59
  if (value.findings?.some(finding => !isFinding(finding)))
60
60
  throw new Error('Invalid report: inconsistent finding location');
61
61
  const ignore = value.appliedConfig.findingIgnore;
62
- if (value.ignoredFindings?.some(({ finding, matchedRule }) => !isFinding(finding)
63
- || !Array.isArray(ignore) || matchedRule >= ignore.length))
62
+ if (value.ignoredFindings?.some(({ finding, matchedRule, reason }) => !isFinding(finding)
63
+ || (matchedRule === undefined ? !reason?.trim() : !Array.isArray(ignore) || matchedRule >= ignore.length)))
64
64
  throw new Error('Invalid report: inconsistent ignored finding');
65
65
  for (const item of value.measurements) {
66
66
  if (!Object.hasOwn(value.definitions, item.definition))