@repometry/cli 0.2.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.
Files changed (88) hide show
  1. package/README.md +5 -2
  2. package/package.json +2 -2
  3. package/target/main/resources/language-catalog.json +54 -0
  4. package/target/main/resources/licenses/spdx.json +746 -0
  5. package/target/main/resources/report/json/config-v2.schema.json +2 -1
  6. package/target/main/resources/report/json/file-metrics-v1.schema.json +2 -0
  7. package/target/main/resources/report/json/report-v2.schema.json +6 -3
  8. package/target/main/resources/report/json/repository-summary-v1.schema.json +14 -0
  9. package/target/main/resources/viewer/index.html +4 -0
  10. package/target/main/resources/viewer/styles.css +7 -2
  11. package/target/main/ts/api/git/git.d.ts +2 -1
  12. package/target/main/ts/api/git/git.js +4 -4
  13. package/target/main/ts/api/git/inspection-source.js +2 -2
  14. package/target/main/ts/api/git/local.d.ts +1 -1
  15. package/target/main/ts/api/git/local.js +5 -4
  16. package/target/main/ts/api/import/finding-import.js +2 -9
  17. package/target/main/ts/api/import/license-import.d.ts +2 -0
  18. package/target/main/ts/api/import/license-import.js +36 -0
  19. package/target/main/ts/api/import/repository-path.d.ts +1 -0
  20. package/target/main/ts/api/import/repository-path.js +10 -0
  21. package/target/main/ts/cli/imports.d.ts +2 -0
  22. package/target/main/ts/cli/imports.js +6 -2
  23. package/target/main/ts/cli/run.js +10 -4
  24. package/target/main/ts/compose/analysis-report.js +5 -2
  25. package/target/main/ts/compose/analysis-results.d.ts +3 -2
  26. package/target/main/ts/compose/analysis-results.js +15 -6
  27. package/target/main/ts/compose/analysis-steps.js +3 -0
  28. package/target/main/ts/compose/analyze-snapshot.d.ts +1 -1
  29. package/target/main/ts/compose/analyze-snapshot.js +7 -4
  30. package/target/main/ts/compose/built-ins.d.ts +2 -2
  31. package/target/main/ts/compose/built-ins.js +2 -2
  32. package/target/main/ts/compose/inspect.d.ts +2 -0
  33. package/target/main/ts/compose/inspect.js +7 -4
  34. package/target/main/ts/compose/language-discovery.js +3 -1
  35. package/target/main/ts/compose/load-plugins.js +4 -2
  36. package/target/main/ts/compose/phases.d.ts +7 -3
  37. package/target/main/ts/compose/phases.js +26 -10
  38. package/target/main/ts/plugins/built-in.d.ts +2 -0
  39. package/target/main/ts/plugins/built-in.js +4 -1
  40. package/target/main/ts/plugins/duplication/duplication.d.ts +1 -2
  41. package/target/main/ts/plugins/duplication/duplication.js +18 -17
  42. package/target/main/ts/plugins/json-spans.d.ts +11 -0
  43. package/target/main/ts/plugins/json-spans.js +86 -0
  44. package/target/main/ts/plugins/language-js/babel-provider.d.ts +34 -2
  45. package/target/main/ts/plugins/language-js/babel-provider.js +39 -35
  46. package/target/main/ts/plugins/language-js/js-security.d.ts +17 -2
  47. package/target/main/ts/plugins/language-js/js-security.js +24 -23
  48. package/target/main/ts/plugins/language-js/structural-observations.d.ts +2 -1
  49. package/target/main/ts/plugins/language-js/structural-observations.js +2 -2
  50. package/target/main/ts/plugins/legal/composer-lock.d.ts +2 -0
  51. package/target/main/ts/plugins/legal/composer-lock.js +24 -0
  52. package/target/main/ts/plugins/legal/dependencies.d.ts +73 -0
  53. package/target/main/ts/plugins/legal/dependencies.js +27 -0
  54. package/target/main/ts/plugins/legal/licenses.d.ts +19 -0
  55. package/target/main/ts/plugins/legal/licenses.js +112 -0
  56. package/target/main/ts/plugins/legal/npm-lock.d.ts +3 -0
  57. package/target/main/ts/plugins/legal/npm-lock.js +30 -0
  58. package/target/main/ts/plugins/legal/policy.d.ts +72 -0
  59. package/target/main/ts/plugins/legal/policy.js +149 -0
  60. package/target/main/ts/plugins/legal/sbom.d.ts +3 -0
  61. package/target/main/ts/plugins/legal/sbom.js +131 -0
  62. package/target/main/ts/plugins/legal/unverified-lock.d.ts +1 -0
  63. package/target/main/ts/plugins/legal/unverified-lock.js +21 -0
  64. package/target/main/ts/plugins/maintainability/maintainability.d.ts +1 -2
  65. package/target/main/ts/plugins/maintainability/maintainability.js +34 -33
  66. package/target/main/ts/plugins/maintainability/structural-smells.d.ts +1 -2
  67. package/target/main/ts/plugins/maintainability/structural-smells.js +5 -5
  68. package/target/main/ts/plugins/security/actions-security.d.ts +17 -2
  69. package/target/main/ts/plugins/security/actions-security.js +21 -16
  70. package/target/main/ts/plugins/security/dockerfile.d.ts +17 -2
  71. package/target/main/ts/plugins/security/dockerfile.js +23 -18
  72. package/target/main/ts/plugins/security/npm-supply-chain.d.ts +17 -2
  73. package/target/main/ts/plugins/security/npm-supply-chain.js +32 -110
  74. package/target/main/ts/plugins/security/secrets.d.ts +18 -6
  75. package/target/main/ts/plugins/security/secrets.js +27 -23
  76. package/target/main/ts/plugins/source/forges.js +25 -32
  77. package/target/main/ts/report/html/app/viewer-issue-group.js +1 -1
  78. package/target/main/ts/report/html/app/viewer-metric-registry.js +1 -1
  79. package/target/main/ts/report/html/app/viewer-metrics.d.ts +2 -1
  80. package/target/main/ts/report/html/app/viewer-metrics.js +7 -2
  81. package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +1 -0
  82. package/target/main/ts/report/html/app/viewer-overview-cards.js +20 -1
  83. package/target/main/ts/report/html/app/viewer-overview-lead.js +4 -1
  84. package/target/main/ts/report/html/app/viewer-shell.js +3 -1
  85. package/target/main/ts/report/html/app/viewer-tokenizer.js +37 -9
  86. package/target/main/ts/report/html/app/viewer-trend-data.js +1 -0
  87. package/target/main/ts/report/html/app/viewer.js +5 -2
  88. package/target/main/ts/report/json/validation/report.js +2 -2
@@ -1,5 +1,6 @@
1
- import { isRecord, pluginApi } from '@repometry/core/internal/engine/plugin.js';
2
- import { findingResult } from '@repometry/core/internal/model/finding.js';
1
+ import { isRecord } from '@repometry/core/internal/engine/plugin.js';
2
+ import { findingResult } from '@repometry/core/internal/engine/author-contracts.js';
3
+ import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
3
4
  import { sourceFile } from '@repometry/core/internal/model/snapshot.js';
4
5
  /** A line that contains this marker is never reported. */
5
6
  export const ignoreMarker = 'repometry-ignore-secret';
@@ -143,16 +144,14 @@ function assignedSecret(line, claimed) {
143
144
  }
144
145
  return undefined;
145
146
  }
146
- const genericRule = { id: 'generic-secret-assignment', category: 'secret',
147
+ const genericRule = { id: 'generic-secret-assignment',
147
148
  description: 'Flags a quoted high-entropy literal of 16 or more characters assigned to a password, secret, token or API key name, '
148
149
  + `ignoring placeholders such as example, dummy, changeme, xxx, \${...} and process.env; ${skipped}.` };
149
- const sensitiveRule = { id: 'sensitive-file', category: 'secret',
150
+ const sensitiveRule = { id: 'sensitive-file',
150
151
  description: 'Flags files that usually hold credentials: .env and .env.* except .env.example, .env.sample and .env.template, '
151
152
  + '*.pem and *.key unless they hold only public certificates or keys, *.p12, *.pfx, id_rsa, id_dsa, id_ecdsa, id_ed25519, '
152
153
  + `.git-credentials, and .npmrc or .pypirc with a literal auth token; ${ignoreMarker} on the first line skips the file.` };
153
- export const secretRules = [
154
- ...lineRules.map(({ id, description }) => ({ id, category: 'secret', description })), genericRule, sensitiveRule,
155
- ];
154
+ const secretRules = [...lineRules.map(({ id, description }) => ({ id, description })), genericRule, sensitiveRule];
156
155
  const sshKeys = new Set(['id_rsa', 'id_dsa', 'id_ecdsa', 'id_ed25519']);
157
156
  const envTemplates = new Set(['example', 'sample', 'template']);
158
157
  const publicPem = /^(?:(?:TRUSTED |X509 )?CERTIFICATE|(?:NEW )?CERTIFICATE REQUEST|X509 CRL|(?:RSA |SSH2 )?PUBLIC KEY|PKCS7|CMS|(?:DH|EC) PARAMETERS)$/;
@@ -193,7 +192,7 @@ function sensitiveTextKind(name, lines) {
193
192
  return undefined;
194
193
  }
195
194
  function finding(rule, level, message, path, line) {
196
- return { tool: 'secrets', rule, category: 'secret', level, message, path, line, endLine: line };
195
+ return { check: rule, level, message, path, line, endLine: line };
197
196
  }
198
197
  function lineFindings(path, context) {
199
198
  const line = context.lines[context.index];
@@ -206,7 +205,7 @@ function lineFindings(path, context) {
206
205
  if (!rule.accept(match, context))
207
206
  continue;
208
207
  claimed.push([match.index ?? 0, (match.index ?? 0) + match[0].length]);
209
- if (!findings.some(item => item.rule === rule.id))
208
+ if (!findings.some(item => item.check === rule.id))
210
209
  findings.push(finding(rule.id, rule.level, rule.message, path, context.index + 1));
211
210
  }
212
211
  }
@@ -216,7 +215,7 @@ function lineFindings(path, context) {
216
215
  return findings;
217
216
  }
218
217
  /** Scans one file. Secret values never reach a finding: messages name only the kind of secret. */
219
- export function scanSecrets(path, bytes) {
218
+ function scanSecrets(path, bytes) {
220
219
  if (bytes.length > maxScannedBytes)
221
220
  return [];
222
221
  const name = path.slice(path.lastIndexOf('/') + 1);
@@ -236,19 +235,24 @@ export function scanSecrets(path, bytes) {
236
235
  }
237
236
  return findings;
238
237
  }
238
+ // The dotfile selector includes credentials stored in hidden files and directories.
239
+ const paths = ['**/*', '**/.*'];
239
240
  export const secrets = {
240
- id: 'secrets', version: '1.0.0', api: pluginApi,
241
- kinds: ['security'],
242
- // `**/*` skips dotfiles, so `**/.*` adds .env, .npmrc and files under dot directories.
243
- claims: { globs: ['**/*', '**/.*'], scanOnly: true },
244
- produces: [{ contract: findingResult.id, persistence: 'report' }],
245
- rules: secretRules,
246
- operations: [{
247
- id: 'scan', role: 'inspection', inputs: { source: sourceFile }, output: findingResult,
248
- execute(inputs) {
249
- const { path, bytes } = inputs.read('source', sourceFile);
250
- return { measurements: [], findings: scanSecrets(path, bytes) };
251
- },
252
- }],
241
+ ...bundledPlugin({
242
+ schema: pluginManifestSchema, id: 'secrets', version: '1.0.0', category: 'security',
243
+ include: paths,
244
+ checks: secretRules,
245
+ create: () => ({
246
+ produces: [{ contract: findingResult.id, persistence: 'report' }],
247
+ operations: [{
248
+ id: 'scan', role: 'inspection', inputs: { source: sourceFile }, output: findingResult,
249
+ execute(inputs) {
250
+ const { path, bytes } = inputs.read('source', sourceFile);
251
+ return { measurements: [], findings: scanSecrets(path, bytes) };
252
+ },
253
+ }],
254
+ }),
255
+ }, { tool: 'secrets', category: 'secret' }),
256
+ claims: { globs: paths, scanOnly: true },
253
257
  };
254
258
  //# sourceMappingURL=secrets.js.map
@@ -1,35 +1,28 @@
1
- import { pluginApi } from '@repometry/core/internal/engine/plugin.js';
2
- const manifest = {
3
- api: pluginApi, version: '1.0.0', kinds: ['source'],
4
- operations: [], produces: [{ contract: 'repometry.source-locator/v1', persistence: 'transient' }],
5
- };
6
- export const localSource = {
7
- ...manifest, id: 'local',
8
- locate: () => ({ provider: 'local', url: './sources/{revision}/{path}' }),
9
- };
10
- export const githubSource = {
11
- ...manifest, id: 'github',
12
- locate(context) {
13
- const project = forgeProject(context, 'github.com', context.env.GITHUB_REPOSITORY, context.env.GITHUB_SERVER_URL, 2);
14
- if (!project)
15
- return undefined;
16
- const { origin, path } = project;
17
- const url = origin === 'https://github.com' ? `https://raw.githubusercontent.com/${path}/{revision}/{path}`
18
- : `${origin}/${path}/raw/{revision}/{path}`;
19
- return { provider: 'github', url, web: `${origin}/${path}/blob/{revision}/{path}#L{line}` };
20
- },
21
- };
22
- export const gitlabSource = {
23
- ...manifest, id: 'gitlab',
24
- locate(context) {
25
- const project = forgeProject(context, 'gitlab.com', context.env.CI_PROJECT_PATH, context.env.CI_SERVER_URL);
26
- if (!project)
27
- return undefined;
28
- const { origin, path } = project;
29
- return { provider: 'gitlab', url: `${origin}/api/v4/projects/${encodeURIComponent(path)}/repository/files/{path:component}/raw?ref={revision}`,
30
- web: `${origin}/${path}/-/blob/{revision}/{path}#L{line}` };
31
- },
32
- };
1
+ import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
2
+ function sourcePlugin(id, locate) {
3
+ return { ...bundledPlugin({
4
+ schema: pluginManifestSchema, id, version: '1.0.0', category: 'source',
5
+ create: () => ({ operations: [], produces: [{ contract: 'repometry.source-locator/v1', persistence: 'transient' }] }),
6
+ }), locate };
7
+ }
8
+ export const localSource = sourcePlugin('local', () => ({ provider: 'local', url: './sources/{revision}/{path}' }));
9
+ export const githubSource = sourcePlugin('github', (context) => {
10
+ const project = forgeProject(context, 'github.com', context.env.GITHUB_REPOSITORY, context.env.GITHUB_SERVER_URL, 2);
11
+ if (!project)
12
+ return undefined;
13
+ const { origin, path } = project;
14
+ const url = origin === 'https://github.com' ? `https://raw.githubusercontent.com/${path}/{revision}/{path}`
15
+ : `${origin}/${path}/raw/{revision}/{path}`;
16
+ return { provider: 'github', url, web: `${origin}/${path}/blob/{revision}/{path}#L{line}` };
17
+ });
18
+ export const gitlabSource = sourcePlugin('gitlab', (context) => {
19
+ const project = forgeProject(context, 'gitlab.com', context.env.CI_PROJECT_PATH, context.env.CI_SERVER_URL);
20
+ if (!project)
21
+ return undefined;
22
+ const { origin, path } = project;
23
+ return { provider: 'gitlab', url: `${origin}/api/v4/projects/${encodeURIComponent(path)}/repository/files/{path:component}/raw?ref={revision}`,
24
+ web: `${origin}/${path}/-/blob/{revision}/{path}#L{line}` };
25
+ });
33
26
  function forgeProject(context, host, ciProject, ciServer, segments) {
34
27
  if (context.option !== undefined && context.option !== '') {
35
28
  const explicit = remoteProject(context.option) ?? projectAt('https://' + host, context.option);
@@ -5,7 +5,7 @@ import { duration } from './viewer-metrics.js';
5
5
  import { lineSnippet, renderExcerpt } from './viewer-source-view.js';
6
6
  import { highlighter } from './viewer-tokenizer.js';
7
7
  export const issueCategories = {
8
- structure: 'Structure', duplication: 'Duplication', lint: 'Lint', security: 'Security',
8
+ structure: 'Structure', duplication: 'Duplication', lint: 'Lint', security: 'Security', legal: 'Legal',
9
9
  dependency: 'Dependencies', secret: 'Secrets', infrastructure: 'Infrastructure',
10
10
  };
11
11
  export const issueLevels = { high: 'High', medium: 'Medium', low: 'Low', unknown: 'Unknown' };
@@ -23,7 +23,7 @@ const handDrawn = new Set([
23
23
  ]);
24
24
  /** Words that already mean something: query keys, Trends views and the series the viewer draws by hand. */
25
25
  const reserved = new Set(['lang', 'language', 'component', 'path', 'in', 'has', 'analysed', 'ignored', 'lockfile', 'lockfiles', 'remediation', 'missedlines', 'churn',
26
- 'debt', 'debt-changes', 'diff-coverage', 'effort', 'smells', 'files', 'classes', 'comments', 'code-lines', 'security',
26
+ 'debt', 'debt-changes', 'diff-coverage', 'effort', 'smells', 'files', 'classes', 'comments', 'code-lines', 'security', 'legal',
27
27
  'coverable-lines', 'covered-lines', 'uncovered-lines', 'security-high', 'security-medium', 'security-low',
28
28
  ...Object.values(builtinKeys)]);
29
29
  /** Curated groups first, in this order; groups named by plugins follow in catalog order. */
@@ -4,7 +4,7 @@ import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js
4
4
  import type { MetricDescriptor } from '../../json/wire/summary-model.js';
5
5
  import * as metricFormat from './viewer-metric-format.js';
6
6
  import type { MetricSpec } from './viewer-metric-registry.js';
7
- export type BuiltinMetric = 'coverage' | 'lines' | 'files' | 'functions' | 'complexity' | 'cognitive' | 'duplication' | 'debt' | 'effort' | 'smells' | 'code-lines' | 'classes' | 'comments' | 'security' | 'coverable-lines' | 'covered-lines' | 'uncovered-lines' | 'security-high' | 'security-medium' | 'security-low';
7
+ export type BuiltinMetric = 'coverage' | 'lines' | 'files' | 'functions' | 'complexity' | 'cognitive' | 'duplication' | 'debt' | 'effort' | 'smells' | 'code-lines' | 'classes' | 'comments' | 'security' | 'legal' | 'coverable-lines' | 'covered-lines' | 'uncovered-lines' | 'security-high' | 'security-medium' | 'security-low';
8
8
  /** Another plugin's metric, by the key the registry gives it. */
9
9
  export type PluginMetric = string & {
10
10
  readonly plugin: unique symbol;
@@ -32,6 +32,7 @@ export declare function labelOf(metric: Metric): string;
32
32
  export declare function definitionOf(metric: Metric): string;
33
33
  /** Which way is better: the green and red of changes and the flags on a chart follow it. */
34
34
  export declare function betterOf(metric: Metric): 'lower' | 'higher' | 'none';
35
+ export declare function legalFindings({ high, medium, low, unknown }: NonNullable<QualitySummary['legal']>): number;
35
36
  /** Where the maintainability grade covers only some files, as in a repository some plugins cannot measure, it says so. */
36
37
  export declare function gradeScope(quality: QualitySummary | undefined): string | undefined;
37
38
  /** A metric's value at a commit; null where the commit has no such measurement. */
@@ -5,7 +5,7 @@ export const metricLabels = {
5
5
  coverage: 'Line coverage', lines: 'Physical lines', files: 'Analysed files', functions: 'Functions',
6
6
  complexity: 'Peak cyclomatic', cognitive: 'Cognitive complexity', duplication: 'Duplication',
7
7
  debt: 'Technical debt ratio', effort: 'Remediation time', smells: 'Code smells', 'code-lines': 'Code lines',
8
- classes: 'Classes', comments: 'Comment lines', security: 'Security findings',
8
+ classes: 'Classes', comments: 'Comment lines', security: 'Security findings', legal: 'Legal findings',
9
9
  'coverable-lines': 'Measured lines', 'covered-lines': 'Covered lines', 'uncovered-lines': 'Uncovered lines',
10
10
  'security-high': 'High severity', 'security-medium': 'Medium severity', 'security-low': 'Low severity',
11
11
  };
@@ -37,6 +37,7 @@ export const metricDefinitions = {
37
37
  classes: 'Classes found in inspected source files.',
38
38
  comments: 'Lines that contain only comments.',
39
39
  security: 'Findings from imported security scanners, all severities.',
40
+ legal: 'Findings from the dependency license policy check.',
40
41
  'coverable-lines': 'Lines the coverage report measured.',
41
42
  'covered-lines': 'Measured lines executed by tests.',
42
43
  'uncovered-lines': 'Measured lines no test executed.',
@@ -45,7 +46,7 @@ export const metricDefinitions = {
45
46
  'security-low': 'Low-severity findings from imported security scanners.',
46
47
  };
47
48
  /** Metrics where a lower value is better. Coverage is better higher; the rest are neutral. */
48
- const lowerIsBetter = new Set(['complexity', 'cognitive', 'duplication', 'debt', 'effort', 'smells', 'security',
49
+ const lowerIsBetter = new Set(['complexity', 'cognitive', 'duplication', 'debt', 'effort', 'smells', 'security', 'legal',
49
50
  'uncovered-lines', 'security-high', 'security-medium', 'security-low']);
50
51
  const integers = new Intl.NumberFormat();
51
52
  const percent = new Intl.NumberFormat(undefined, { style: 'percent', maximumFractionDigits: 1 });
@@ -94,6 +95,9 @@ export function betterOf(metric) {
94
95
  return spec.descriptor.better;
95
96
  return lowerIsBetter.has(metric) ? 'lower' : metric === 'coverage' ? 'higher' : 'none';
96
97
  }
98
+ export function legalFindings({ high, medium, low, unknown }) {
99
+ return high + medium + low + unknown;
100
+ }
97
101
  function securityTotal(context) {
98
102
  return context?.security ? Object.values(context.security).reduce((total, value) => total + value, 0) : null;
99
103
  }
@@ -113,6 +117,7 @@ const readers = {
113
117
  classes: (_, quality) => quality?.classes,
114
118
  comments: (_, quality) => quality?.comments,
115
119
  security: (_, __, context) => securityTotal(context),
120
+ legal: (_, quality) => quality?.legal === undefined ? null : legalFindings(quality.legal),
116
121
  'coverable-lines': report => report.lineCoverage?.total,
117
122
  'covered-lines': report => report.lineCoverage?.covered,
118
123
  'uncovered-lines': report => report.lineCoverage ? report.lineCoverage.total - report.lineCoverage.covered : null,
@@ -6,6 +6,7 @@ export declare function detailText(id: string, text: string, link?: string): voi
6
6
  /** Where each Overview figure leads: the findings it counts, the files it ranks, the function it names. */
7
7
  export declare function smellsLink(sha: string): string;
8
8
  export declare function securityLink(sha: string, level?: string): string;
9
+ export declare function legalLink(sha: string): string;
9
10
  export declare function uncoveredLink(sha: string): string;
10
11
  export declare function renderInspection(report: PublicHistoryEntry): void;
11
12
  export declare function renderQuality(report: PublicHistoryEntry, quality: QualitySummary | undefined): void;
@@ -1,6 +1,6 @@
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, formatMetric, gradeScope, legalFindings, metricValue, pluginSpec, securityGrades, securityRisks } from './viewer-metrics.js';
4
4
  import { href } from './viewer-route.js';
5
5
  /** Coverage kinds beyond lines, by their registry keys, in the words the Overview card uses for them. */
6
6
  const coverageKinds = [['branch-coverage', 'Branches'], ['function-coverage', 'Functions']];
@@ -22,6 +22,9 @@ export function smellsLink(sha) {
22
22
  export function securityLink(sha, level) {
23
23
  return href({ page: 'issues', sha, category: securityCategories.join(','), ...level ? { level } : {} });
24
24
  }
25
+ export function legalLink(sha) {
26
+ return href({ page: 'issues', sha, category: 'legal' });
27
+ }
25
28
  export function uncoveredLink(sha) {
26
29
  return href({ page: 'hotspots', sha, rank: 'missedLines' });
27
30
  }
@@ -89,6 +92,22 @@ export function renderQuality(report, quality) {
89
92
  const scope = byId('maintainability-scope');
90
93
  scope.textContent = gradeScope(quality) ?? '';
91
94
  scope.hidden = !scope.textContent;
95
+ renderLegal(report.sha, quality?.legal);
96
+ }
97
+ function renderLegal(sha, legal) {
98
+ const mark = byId('legal-mark');
99
+ mark.textContent = legal?.grade ?? '–';
100
+ mark.dataset.grade = legal?.grade ?? 'none';
101
+ const scope = byId('legal-scope');
102
+ if (legal === undefined) {
103
+ scope.textContent = 'Add a lockfile with license data or import an SBOM.';
104
+ detailText('legal-detail', 'No license data');
105
+ return;
106
+ }
107
+ const { checked } = legal;
108
+ scope.textContent = count(checked) + (checked === 1 ? ' dependency checked' : ' dependencies checked');
109
+ const findings = legalFindings(legal);
110
+ detailText('legal-detail', findings ? quantity(findings, 'finding') : 'No findings', findings ? legalLink(sha) : undefined);
92
111
  }
93
112
  /** The words of the five steps, as every grade has them: clear A, low B, medium C, high D, critical F. */
94
113
  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 });
@@ -225,7 +252,8 @@ function scanShellPart(cursor, wordStart) {
225
252
  }
226
253
  export function sourceTokenizer(path) {
227
254
  const syntax = syntaxOf(path);
228
- if (syntax === undefined && languageIdOf(path) === 'shell' && /\.(?:sh|bash)$/i.test(path)) {
255
+ const language = languageIdOf(path);
256
+ if (syntax === undefined && (language === 'shell' || language === 'bash') && /\.(?:sh|bash)$/i.test(path)) {
229
257
  return scanLines(shellGrammar, scanShellLine);
230
258
  }
231
259
  return tokenizer(syntax);
@@ -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))