repometry 0.10.1 → 0.11.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 (147) hide show
  1. package/README.md +4 -2
  2. package/package.json +1 -1
  3. package/target/main/resources/config/process-plugins-v1.schema.json +22 -0
  4. package/target/main/resources/report/json/config-v1.schema.json +41 -0
  5. package/target/main/resources/report/json/file-metrics-v1.schema.json +23 -1
  6. package/target/main/resources/report/json/pull-review-v2.schema.json +100 -0
  7. package/target/main/ts/api/cache/root.d.ts +1 -1
  8. package/target/main/ts/api/cache/root.js +2 -2
  9. package/target/main/ts/api/gh/github.d.ts +0 -4
  10. package/target/main/ts/api/gh/github.js +3 -33
  11. package/target/main/ts/api/git/commit-metadata.d.ts +0 -1
  12. package/target/main/ts/api/git/commit-metadata.js +1 -10
  13. package/target/main/ts/api/import/cobertura.d.ts +2 -0
  14. package/target/main/ts/api/import/cobertura.js +160 -0
  15. package/target/main/ts/api/import/coverage-xml.d.ts +7 -0
  16. package/target/main/ts/api/import/coverage-xml.js +135 -0
  17. package/target/main/ts/api/import/lcov-files.d.ts +3 -1
  18. package/target/main/ts/api/import/lcov-files.js +23 -4
  19. package/target/main/ts/cli/arguments.js +2 -4
  20. package/target/main/ts/cli/config.d.ts +10 -6
  21. package/target/main/ts/cli/config.js +36 -6
  22. package/target/main/ts/cli/imports.d.ts +1 -0
  23. package/target/main/ts/cli/imports.js +6 -2
  24. package/target/main/ts/cli/main.js +47 -139
  25. package/target/main/ts/cli/range-inspection.d.ts +0 -3
  26. package/target/main/ts/cli/range-inspection.js +5 -17
  27. package/target/main/ts/cli/range-jobs.js +1 -3
  28. package/target/main/ts/cli/reporting.d.ts +2 -7
  29. package/target/main/ts/cli/reporting.js +23 -37
  30. package/target/main/ts/compose/analysis-report.d.ts +1 -1
  31. package/target/main/ts/compose/analysis-report.js +4 -5
  32. package/target/main/ts/compose/analysis-results.d.ts +1 -1
  33. package/target/main/ts/compose/analysis-results.js +4 -6
  34. package/target/main/ts/compose/analysis-steps.d.ts +23 -0
  35. package/target/main/ts/compose/analysis-steps.js +215 -0
  36. package/target/main/ts/compose/analyze-snapshot.d.ts +1 -1
  37. package/target/main/ts/compose/analyze-snapshot.js +8 -12
  38. package/target/main/ts/compose/built-ins.d.ts +3 -0
  39. package/target/main/ts/compose/built-ins.js +5 -0
  40. package/target/main/ts/compose/diff-coverage.d.ts +2 -4
  41. package/target/main/ts/compose/diff-coverage.js +15 -12
  42. package/target/main/ts/compose/history-cache.d.ts +1 -1
  43. package/target/main/ts/compose/inspect.d.ts +6 -9
  44. package/target/main/ts/compose/inspect.js +8 -9
  45. package/target/main/ts/compose/languages.d.ts +4 -1
  46. package/target/main/ts/compose/languages.js +9 -6
  47. package/target/main/ts/compose/native-language-plugins.d.ts +0 -1
  48. package/target/main/ts/compose/native-language-plugins.js +4 -11
  49. package/target/main/ts/compose/phases.d.ts +126 -0
  50. package/target/main/ts/compose/phases.js +154 -0
  51. package/target/main/ts/compose/plugin-list.d.ts +8 -2
  52. package/target/main/ts/compose/plugin-list.js +4 -13
  53. package/target/main/ts/compose/process-plugins.js +1 -1
  54. package/target/main/ts/compose/review.d.ts +2 -4
  55. package/target/main/ts/compose/review.js +10 -9
  56. package/target/main/ts/compose/sources.d.ts +1 -2
  57. package/target/main/ts/compose/sources.js +7 -7
  58. package/target/main/ts/core/engine/execute.d.ts +4 -1
  59. package/target/main/ts/core/engine/execute.js +1 -1
  60. package/target/main/ts/core/engine/manifest.d.ts +0 -1
  61. package/target/main/ts/core/engine/manifest.js +9 -13
  62. package/target/main/ts/core/engine/plugin.d.ts +1 -1
  63. package/target/main/ts/core/engine/report-products.js +3 -2
  64. package/target/main/ts/core/model/changes.d.ts +2 -0
  65. package/target/main/ts/core/model/changes.js +5 -1
  66. package/target/main/ts/core/model/clone-source.d.ts +2 -0
  67. package/target/main/ts/core/model/clone-source.js +4 -0
  68. package/target/main/ts/core/model/code-structure.d.ts +4 -1
  69. package/target/main/ts/core/model/code-structure.js +3 -1
  70. package/target/main/ts/core/model/coverage-input.d.ts +12 -0
  71. package/target/main/ts/core/model/coverage-input.js +11 -0
  72. package/target/main/ts/core/model/diff-coverage.d.ts +2 -0
  73. package/target/main/ts/core/model/diff-coverage.js +9 -1
  74. package/target/main/ts/core/model/language.d.ts +28 -0
  75. package/target/main/ts/core/model/language.js +25 -1
  76. package/target/main/ts/core/model/quality-summary.js +1 -1
  77. package/target/main/ts/core/model/report.d.ts +0 -2
  78. package/target/main/ts/core/model/report.js +0 -20
  79. package/target/main/ts/core/ports/tool-runner.d.ts +13 -0
  80. package/target/main/ts/core/usecases/inspect.d.ts +1 -2
  81. package/target/main/ts/core/usecases/review.js +11 -3
  82. package/target/main/ts/index.d.ts +6 -33
  83. package/target/main/ts/index.js +3 -18
  84. package/target/main/ts/plugin.d.ts +7 -3
  85. package/target/main/ts/plugin.js +3 -0
  86. package/target/main/ts/plugins/built-in.d.ts +6 -0
  87. package/target/main/ts/plugins/built-in.js +39 -0
  88. package/target/main/ts/plugins/coverage/coverage.d.ts +3 -24
  89. package/target/main/ts/plugins/coverage/coverage.js +8 -11
  90. package/target/main/ts/plugins/coverage/diff-coverage.d.ts +1 -5
  91. package/target/main/ts/plugins/coverage/diff-coverage.js +5 -14
  92. package/target/main/ts/plugins/duplication/duplication.d.ts +1 -3
  93. package/target/main/ts/plugins/duplication/duplication.js +2 -6
  94. package/target/main/ts/plugins/language-js/babel-provider.js +3 -2
  95. package/target/main/ts/plugins/language-js/structural-observations.js +1 -1
  96. package/target/main/ts/plugins/language-js/syntax.d.ts +2 -0
  97. package/target/main/ts/plugins/language-js/syntax.js +11 -0
  98. package/target/main/ts/plugins/maintainability/maintainability.d.ts +1 -8
  99. package/target/main/ts/plugins/maintainability/maintainability.js +4 -10
  100. package/target/main/ts/plugins/source/forges.js +1 -1
  101. package/target/main/ts/report/html/app/viewer-languages.d.ts +3 -1
  102. package/target/main/ts/report/html/app/viewer-languages.js +11 -1
  103. package/target/main/ts/report/html/app/viewer-metrics-view.js +1 -1
  104. package/target/main/ts/report/html/app/viewer-source-view.js +2 -2
  105. package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +7 -6
  106. package/target/main/ts/report/html/app/viewer-tokenizer.js +72 -71
  107. package/target/main/ts/report/html/site/export-site.d.ts +1 -5
  108. package/target/main/ts/report/html/site/export-site.js +2 -6
  109. package/target/main/ts/report/html/site/projects.d.ts +1 -3
  110. package/target/main/ts/report/html/site/projects.js +2 -4
  111. package/target/main/ts/report/json/projections/file-metrics.js +1 -1
  112. package/target/main/ts/report/json/projections/inspection-context.d.ts +1 -0
  113. package/target/main/ts/report/json/projections/inspection-context.js +19 -1
  114. package/target/main/ts/report/json/projections/inspection-details.js +7 -2
  115. package/target/main/ts/report/json/store/local-store.js +2 -0
  116. package/target/main/ts/report/json/store/replace-file.d.ts +1 -1
  117. package/target/main/ts/report/json/store/replace-file.js +24 -3
  118. package/target/main/ts/report/json/store/store-check.js +10 -1
  119. package/target/main/ts/report/json/validation/metabranch.d.ts +1 -1
  120. package/target/main/ts/report/json/validation/metabranch.js +6 -3
  121. package/target/main/ts/report/json/wire/file-metrics-model.d.ts +3 -1
  122. package/target/main/ts/report.d.ts +13 -1
  123. package/target/main/ts/report.js +7 -1
  124. package/target/main/ts/api/git/metabranch-worktree.d.ts +0 -1
  125. package/target/main/ts/api/git/metabranch-worktree.js +0 -35
  126. package/target/main/ts/api/worker/remote-executor.d.ts +0 -2
  127. package/target/main/ts/api/worker/remote-executor.js +0 -46
  128. package/target/main/ts/api/worker/worker-protocol.d.ts +0 -7
  129. package/target/main/ts/api/worker/worker-protocol.js +0 -127
  130. package/target/main/ts/api/worker/worker.d.ts +0 -5
  131. package/target/main/ts/api/worker/worker.js +0 -86
  132. package/target/main/ts/compose/analysis-files.d.ts +0 -15
  133. package/target/main/ts/compose/analysis-files.js +0 -129
  134. package/target/main/ts/compose/analysis-imports.d.ts +0 -7
  135. package/target/main/ts/compose/analysis-imports.js +0 -36
  136. package/target/main/ts/compose/analysis-repository.d.ts +0 -7
  137. package/target/main/ts/compose/analysis-repository.js +0 -99
  138. package/target/main/ts/compose/analysis-sources.d.ts +0 -48
  139. package/target/main/ts/compose/analysis-sources.js +0 -54
  140. package/target/main/ts/compose/prepare-metabranch.d.ts +0 -9
  141. package/target/main/ts/compose/prepare-metabranch.js +0 -17
  142. package/target/main/ts/compose/security-plugins.d.ts +0 -1
  143. package/target/main/ts/compose/security-plugins.js +0 -7
  144. package/target/main/ts/core/usecases/compare.d.ts +0 -6
  145. package/target/main/ts/core/usecases/compare.js +0 -189
  146. package/target/main/ts/report/json/store/components.d.ts +0 -2
  147. package/target/main/ts/report/json/store/components.js +0 -32
@@ -0,0 +1,135 @@
1
+ const entities = new Map([['lt', '<'], ['gt', '>'], ['amp', '&'], ['quot', '"'], ['apos', "'"]]);
2
+ export function readCoverageXml(input, invalid, visitor) {
3
+ const text = input.replace(/^\uFEFF/, '').replace(/\r\n?/g, '\n');
4
+ const parents = [];
5
+ let root = false;
6
+ let line = 1;
7
+ let offset = 0;
8
+ const fail = (reason, position = offset) => invalid(line + text.slice(offset, position).split('\n').length - 1, reason);
9
+ while (offset < text.length) {
10
+ const token = readToken(text, offset, fail);
11
+ if (token.kind === 'open') {
12
+ if (parents.length === 0) {
13
+ if (root || token.name !== 'coverage')
14
+ invalid(line, 'expected a <coverage> root element');
15
+ root = true;
16
+ }
17
+ visitor.open(token.name, token.attributes, parents, line);
18
+ if (token.empty)
19
+ visitor.close(token.name, parents);
20
+ else
21
+ parents.push(token.name);
22
+ }
23
+ else if (token.kind === 'close') {
24
+ if (parents.pop() !== token.name)
25
+ invalid(line, 'unexpected </' + token.name + '>');
26
+ visitor.close(token.name, parents);
27
+ }
28
+ else if (token.kind === 'text') {
29
+ if (!parents.length && token.value.trim())
30
+ fail('expected a <coverage> root element', offset + text.slice(offset).search(/\S/));
31
+ visitor.text(token.value, parents);
32
+ }
33
+ for (; offset < token.end; offset++)
34
+ if (text.charCodeAt(offset) === 10)
35
+ line++;
36
+ }
37
+ if (parents.length)
38
+ invalid(line, 'unclosed <' + parents.at(-1) + '>');
39
+ if (!root)
40
+ invalid(1, 'expected a <coverage> root element');
41
+ }
42
+ function readToken(text, offset, fail) {
43
+ if (text[offset] !== '<') {
44
+ const next = text.indexOf('<', offset);
45
+ const end = next === -1 ? text.length : next;
46
+ return { kind: 'text', end, value: decode(text.slice(offset, end), offset, fail) };
47
+ }
48
+ if (text.startsWith('<![CDATA[', offset)) {
49
+ const end = sectionEnd(text, offset + 9, ']]>', fail);
50
+ return { kind: 'text', end, value: text.slice(offset + 9, end - 3) };
51
+ }
52
+ if (text.startsWith('<!--', offset))
53
+ return { kind: 'skip', end: sectionEnd(text, offset + 4, '-->', fail) };
54
+ if (text.startsWith('<?', offset))
55
+ return { kind: 'skip', end: sectionEnd(text, offset + 2, '?>', fail) };
56
+ if (text.startsWith('<!DOCTYPE', offset))
57
+ return { kind: 'skip', end: doctypeEnd(text, offset, fail) };
58
+ return readTag(text, offset, fail);
59
+ }
60
+ function sectionEnd(text, start, separator, fail) {
61
+ const end = text.indexOf(separator, start);
62
+ if (end === -1)
63
+ fail('malformed tag');
64
+ return end + separator.length;
65
+ }
66
+ function doctypeEnd(text, offset, fail) {
67
+ const name = /<!DOCTYPE\s+[A-Za-z_:][\w:.-]*/y;
68
+ name.lastIndex = offset;
69
+ if (!name.test(text))
70
+ fail('malformed tag');
71
+ // Quoted identifiers can contain brackets. Stop before reading any unquoted internal subset.
72
+ for (let index = name.lastIndex; index < text.length; index++) {
73
+ const char = text[index];
74
+ if (char === '>')
75
+ return index + 1;
76
+ if (char === '[')
77
+ fail('DOCTYPE with an internal subset is not supported', index);
78
+ if (char === '"' || char === "'")
79
+ index = text.indexOf(char, index + 1);
80
+ if (index === -1)
81
+ break;
82
+ }
83
+ return fail('malformed tag');
84
+ }
85
+ function readTag(text, offset, fail) {
86
+ const tag = /<(\/?)([A-Za-z_:][\w:.-]*)/y;
87
+ tag.lastIndex = offset;
88
+ const match = tag.exec(text);
89
+ if (!match)
90
+ fail('malformed tag');
91
+ const name = match[2];
92
+ const ending = /\s*(\/?)>/y;
93
+ if (match[1]) {
94
+ ending.lastIndex = tag.lastIndex;
95
+ const close = ending.exec(text);
96
+ if (!close || close[1])
97
+ fail('malformed tag');
98
+ return { kind: 'close', end: ending.lastIndex, name };
99
+ }
100
+ const attributes = new Map();
101
+ const attr = /\s+([A-Za-z_:][\w:.-]*)\s*=\s*(?:"([^"<]*)"|'([^'<]*)')/y;
102
+ for (let end = tag.lastIndex;; end = attr.lastIndex) {
103
+ ending.lastIndex = end;
104
+ const edge = ending.exec(text);
105
+ if (edge)
106
+ return { kind: 'open', end: ending.lastIndex, name, attributes, empty: edge[1] === '/' };
107
+ attr.lastIndex = end;
108
+ const value = attr.exec(text);
109
+ if (!value)
110
+ fail('malformed attribute', end + text.slice(end).search(/\S/));
111
+ const key = value[1];
112
+ const raw = value[2] ?? value[3];
113
+ if (attributes.has(key))
114
+ fail('duplicate attribute ' + key, end + value[0].search(/\S/));
115
+ attributes.set(key, decode(raw, attr.lastIndex - raw.length - 1, fail));
116
+ }
117
+ }
118
+ function decode(value, start, fail) {
119
+ return value.replace(/&(?:[^&;<\s]*;)?/g, (reference, index) => {
120
+ const entity = reference.slice(1, -1);
121
+ const named = entities.get(entity);
122
+ if (named !== undefined)
123
+ return named;
124
+ const code = /^#x[\da-f]+$/i.test(entity) ? Number.parseInt(entity.slice(2), 16)
125
+ : /^#\d+$/.test(entity) ? Number(entity.slice(1)) : NaN;
126
+ if (!xmlCharacter(code))
127
+ fail('unknown entity ' + reference, start + index);
128
+ return String.fromCodePoint(code);
129
+ });
130
+ }
131
+ function xmlCharacter(code) {
132
+ return code === 9 || code === 10 || code === 13 || (code >= 32 && code <= 0xd7ff)
133
+ || (code >= 0xe000 && code <= 0xfffd) || (code >= 0x10000 && code <= 0x10ffff);
134
+ }
135
+ //# sourceMappingURL=coverage-xml.js.map
@@ -3,8 +3,10 @@ export type LcovFiles = string | readonly string[];
3
3
  export interface CoverageInputs {
4
4
  readonly lcov?: LcovFiles;
5
5
  readonly goCover?: LcovFiles;
6
+ readonly cobertura?: LcovFiles;
6
7
  }
7
- export declare function readCoverageFiles({ lcov, goCover }: CoverageInputs, source: CoverageSource): Promise<{
8
+ export declare function hasCoverageInputs({ lcov, goCover, cobertura }: CoverageInputs): boolean;
9
+ export declare function readCoverageFiles({ lcov, goCover, cobertura }: CoverageInputs, source: CoverageSource): Promise<{
8
10
  text: string;
9
11
  inputDigests: string[];
10
12
  }>;
@@ -1,20 +1,28 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import { comparePaths, digest, utf8 } from '../../core/model/snapshot.js';
3
+ import { coberturaToLcov } from './cobertura.js';
3
4
  import { goCoverSource, goCoverToLcov } from './go-cover.js';
4
- export async function readCoverageFiles({ lcov, goCover }, source) {
5
+ export function hasCoverageInputs({ lcov, goCover, cobertura }) {
6
+ return lcov !== undefined || goCover !== undefined || cobertura !== undefined;
7
+ }
8
+ export async function readCoverageFiles({ lcov, goCover, cobertura }, source) {
5
9
  const lcovPaths = paths(lcov);
6
10
  const goPaths = paths(goCover);
11
+ const coberturaPaths = paths(cobertura);
7
12
  if (lcov !== undefined && lcovPaths.length === 0)
8
13
  throw new Error('Provide at least one LCOV file');
9
14
  if (goCover !== undefined && goPaths.length === 0)
10
15
  throw new Error('Provide at least one Go coverprofile');
11
- if (lcovPaths.length === 0 && goPaths.length === 0)
16
+ if (cobertura !== undefined && coberturaPaths.length === 0)
17
+ throw new Error('Provide at least one Cobertura file');
18
+ if (lcovPaths.length === 0 && goPaths.length === 0 && coberturaPaths.length === 0)
12
19
  throw new Error('Provide at least one coverage input');
13
- const [lcovSources, goSources] = await Promise.all([
20
+ const [lcovSources, goSources, coberturaSources] = await Promise.all([
14
21
  Promise.all(lcovPaths.map(readInput)),
15
22
  readGoCoverFiles(goPaths, source),
23
+ Promise.all(coberturaPaths.map(file => readCobertura(file, source))),
16
24
  ]);
17
- const sources = [...lcovSources, ...goSources];
25
+ const sources = [...lcovSources, ...goSources, ...coberturaSources];
18
26
  sources.sort((a, b) => comparePaths(a.digest, b.digest));
19
27
  return { text: sources.map(source => source.text).join('\n'), inputDigests: sources.map(source => source.digest) };
20
28
  }
@@ -27,6 +35,17 @@ async function readGoCoverFiles(files, source) {
27
35
  const [goSource, inputs] = await Promise.all([goCoverSource(source), Promise.all(files.map(readInput))]);
28
36
  return inputs.map((input, index) => ({ ...input, text: goCoverToLcov(input.text, files[index], goSource) }));
29
37
  }
38
+ async function readCobertura(path, source) {
39
+ const bytes = await readFile(path);
40
+ let text;
41
+ try {
42
+ text = utf8(bytes);
43
+ }
44
+ catch (error) {
45
+ throw new Error('Invalid Cobertura report ' + path + ' at line 1: invalid UTF-8', { cause: error });
46
+ }
47
+ return { text: coberturaToLcov(text, path, source), digest: digest(text) };
48
+ }
30
49
  async function readInput(path) {
31
50
  const text = utf8(await readFile(path));
32
51
  return { text, digest: digest(text) };
@@ -8,11 +8,9 @@ export function flag(description, short) {
8
8
  const globals = {
9
9
  help: flag('Show command help.', 'h'),
10
10
  version: flag('Show the installed version.', 'V'),
11
- repo: option('DIR', 'Run in the given repository.', { short: 'C' }),
12
- store: option('PATH|git:REF', 'Select a report store.'),
13
11
  };
14
12
  export async function dispatch(commands, input, version) {
15
- const [name, ...rest] = placeGlobalOptions(input);
13
+ const [name, ...rest] = placeLeadingOptions(input);
16
14
  if (name === '--version' || name === '-V') {
17
15
  process.stdout.write(version + '\n');
18
16
  return 0;
@@ -59,7 +57,7 @@ export async function dispatch(commands, input, version) {
59
57
  });
60
58
  return result ?? 0;
61
59
  }
62
- function placeGlobalOptions(input) {
60
+ function placeLeadingOptions(input) {
63
61
  const leading = [];
64
62
  let index = 0;
65
63
  while (index < input.length) {
@@ -1,3 +1,4 @@
1
+ import type { Component } from '../report/json/wire/component-model.js';
1
2
  import type { Invocation } from './arguments.js';
2
3
  export declare function parseConfig(value: unknown): {
3
4
  exclude: readonly string[];
@@ -7,9 +8,10 @@ export declare function parseConfig(value: unknown): {
7
8
  reports: readonly string[];
8
9
  sources: string | undefined;
9
10
  branch: string | undefined;
10
- minCoverage: string | undefined;
11
- minLines: string | undefined;
12
- maxNewIssues: string | undefined;
11
+ components: readonly Component[];
12
+ minCoverage: number | undefined;
13
+ minLines: number | undefined;
14
+ maxNewIssues: number | undefined;
13
15
  };
14
16
  /** The configuration file in effect, or undefined under --no-config. */
15
17
  export declare function configFile(root: string, input: Invocation): string | undefined;
@@ -21,8 +23,10 @@ export declare function readConfig(root: string, input: Invocation): Promise<{
21
23
  reports: readonly string[];
22
24
  sources: string | undefined;
23
25
  branch: string | undefined;
24
- minCoverage: string | undefined;
25
- minLines: string | undefined;
26
- maxNewIssues: string | undefined;
26
+ components: readonly Component[];
27
+ minCoverage: number | undefined;
28
+ minLines: number | undefined;
29
+ maxNewIssues: number | undefined;
27
30
  }>;
28
31
  export declare function readConfigValue(root: string, input: Invocation): Promise<unknown>;
32
+ export declare function listOption(input: Invocation, name: string, configured: readonly string[]): readonly string[];
@@ -5,7 +5,7 @@ import { normalizeProfile } from '../core/profile/profile.js';
5
5
  import { readProcessPlugins } from '../compose/process-plugins.js';
6
6
  import { invocationDirectory } from './store.js';
7
7
  const keys = new Set(['$schema', 'exclude', 'ignore', 'imports', 'reports', 'sources', 'branch',
8
- 'minCoverage', 'minLines', 'maxNewIssues', 'plugins']);
8
+ 'minCoverage', 'minLines', 'maxNewIssues', 'plugins', 'components']);
9
9
  export function parseConfig(value) {
10
10
  if (!isRecord(value) || Object.keys(value).some(key => !keys.has(key)))
11
11
  throw new Error('Invalid Repometry JSON configuration');
@@ -13,7 +13,8 @@ export function parseConfig(value) {
13
13
  const profile = normalizeProfile({ exclude: value.exclude, ignore: value.ignore });
14
14
  return { ...profile, plugins: readProcessPlugins(value.plugins), imports: list(value.imports, 'imports'), reports: list(value.reports, 'reports'),
15
15
  sources: string(value.sources, 'sources'), branch: string(value.branch, 'branch'),
16
- minCoverage: number(value.minCoverage, 'minCoverage'), minLines: number(value.minLines, 'minLines'),
16
+ components: parseComponents(value.components),
17
+ minCoverage: number(value.minCoverage, 'minCoverage', 100), minLines: number(value.minLines, 'minLines'),
17
18
  maxNewIssues: number(value.maxNewIssues, 'maxNewIssues') };
18
19
  }
19
20
  /** The configuration file in effect, or undefined under --no-config. */
@@ -45,6 +46,10 @@ export async function readConfigValue(root, input) {
45
46
  }
46
47
  return JSON.parse(json);
47
48
  }
49
+ export function listOption(input, name, configured) {
50
+ const typed = input.many(name);
51
+ return typed.length ? typed : configured;
52
+ }
48
53
  function list(value, key) {
49
54
  if (value === undefined)
50
55
  return [];
@@ -59,11 +64,36 @@ function string(value, key) {
59
64
  throw new Error(`Config ${key} must be a nonempty string`);
60
65
  return value;
61
66
  }
62
- function number(value, key) {
67
+ function number(value, key, max) {
63
68
  if (value === undefined)
64
69
  return undefined;
65
- if (typeof value !== 'number' || !Number.isFinite(value))
66
- throw new Error(`Config ${key} must be a number`);
67
- return String(value);
70
+ if (typeof value !== 'number' || value < 0 || (max === undefined
71
+ ? !Number.isSafeInteger(value) : !Number.isFinite(value) || value > max)) {
72
+ throw new Error('Invalid config ' + key + (max === undefined ? ': expected a non-negative integer' : ': expected a number from 0 to ' + max));
73
+ }
74
+ return value;
75
+ }
76
+ function parseComponents(config) {
77
+ if (config === undefined)
78
+ return [];
79
+ if (!Array.isArray(config))
80
+ throw new Error('Expected an array of component definitions');
81
+ const names = new Set();
82
+ return config.map((entry) => {
83
+ if (!isRecord(entry) || typeof entry.name !== 'string' || !entry.name.trim() || entry.name.length > 100
84
+ || !Array.isArray(entry.pathGlobs) || entry.pathGlobs.length === 0 || !entry.pathGlobs.every(validPattern)
85
+ || (entry.description !== undefined && typeof entry.description !== 'string')) {
86
+ throw new Error('Each component requires a name and one or more root-relative pathGlobs');
87
+ }
88
+ const name = entry.name.trim();
89
+ if (names.has(name))
90
+ throw new Error(`Duplicate component name: ${name}`);
91
+ names.add(name);
92
+ return { name, pathGlobs: [...new Set(entry.pathGlobs)], description: entry.description };
93
+ });
94
+ }
95
+ function validPattern(pattern) {
96
+ return typeof pattern === 'string' && !/^[A-Za-z]:|[\\\0]/.test(pattern)
97
+ && pattern.split('/').every(part => part !== '' && part !== '.' && part !== '..');
68
98
  }
69
99
  //# sourceMappingURL=config.js.map
@@ -4,5 +4,6 @@ export declare const importerIds: string[];
4
4
  export declare function readInputs(base: string, inputs: readonly string[]): {
5
5
  lcov: string[] | undefined;
6
6
  goCover: string[] | undefined;
7
+ cobertura: string[] | undefined;
7
8
  findings: FindingInput[];
8
9
  };
@@ -6,11 +6,12 @@ const scanners = {
6
6
  eslint: { format: 'eslint', category: 'lint' },
7
7
  osv: { format: 'osv', category: 'dependency' },
8
8
  };
9
- export const importerIds = ['lcov', 'go-cover', ...Object.keys(scanners)];
9
+ export const importerIds = ['lcov', 'go-cover', 'cobertura', ...Object.keys(scanners)];
10
10
  /** Typed imports resolve against the invocation directory, imports from the config against the repository root. */
11
11
  export function readInputs(base, inputs) {
12
12
  const lcov = [];
13
13
  const goCover = [];
14
+ const cobertura = [];
14
15
  const findings = [];
15
16
  for (const value of inputs) {
16
17
  const equal = value.indexOf('=');
@@ -22,12 +23,15 @@ export function readInputs(base, inputs) {
22
23
  lcov.push(resolve(base, file));
23
24
  else if (format === 'go-cover')
24
25
  goCover.push(resolve(base, file));
26
+ else if (format === 'cobertura')
27
+ cobertura.push(resolve(base, file));
25
28
  else {
26
29
  if (!Object.hasOwn(scanners, format))
27
30
  throw new Error(`Unknown import format: ${format}. Choose ${importerIds.join(', ')}.`);
28
31
  findings.push({ ...scanners[format], file: resolve(base, file) });
29
32
  }
30
33
  }
31
- return { lcov: lcov.length ? lcov : undefined, goCover: goCover.length ? goCover : undefined, findings };
34
+ return { lcov: lcov.length ? lcov : undefined, goCover: goCover.length ? goCover : undefined,
35
+ cobertura: cobertura.length ? cobertura : undefined, findings };
32
36
  }
33
37
  //# sourceMappingURL=imports.js.map