repometry 0.4.1 → 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 (190) hide show
  1. package/README.md +4 -0
  2. package/package.json +1 -1
  3. package/target/main/resources/report/json/report-v2.schema.json +13 -1
  4. package/target/main/resources/viewer/files.css +7 -3
  5. package/target/main/resources/viewer/styles.css +2 -2
  6. package/target/main/ts/api/git/git.d.ts +1 -0
  7. package/target/main/ts/api/git/git.js +12 -0
  8. package/target/main/ts/api/git/inspection-source.js +2 -8
  9. package/target/main/ts/api/git/local.d.ts +1 -1
  10. package/target/main/ts/api/git/local.js +39 -5
  11. package/target/main/ts/api/process/docker-tool-runner.d.ts +13 -0
  12. package/target/main/ts/api/process/docker-tool-runner.js +108 -0
  13. package/target/main/ts/api/process/failure.d.ts +1 -0
  14. package/target/main/ts/api/process/failure.js +12 -0
  15. package/target/main/ts/api/process/plugin.d.ts +10 -0
  16. package/target/main/ts/api/process/plugin.js +96 -0
  17. package/target/main/ts/compose/analyze-snapshot.d.ts +3 -2
  18. package/target/main/ts/compose/analyze-snapshot.js +82 -29
  19. package/target/main/ts/compose/inspect.d.ts +5 -0
  20. package/target/main/ts/compose/inspect.js +10 -6
  21. package/target/main/ts/core/engine/execute.d.ts +3 -1
  22. package/target/main/ts/core/engine/execute.js +14 -2
  23. package/target/main/ts/core/engine/operation-cache.d.ts +14 -0
  24. package/target/main/ts/core/engine/operation-cache.js +66 -0
  25. package/target/main/ts/core/engine/plan.d.ts +1 -0
  26. package/target/main/ts/core/engine/plan.js +22 -3
  27. package/target/main/ts/core/engine/plugin.d.ts +8 -1
  28. package/target/main/ts/core/engine/plugin.js +1 -3
  29. package/target/main/ts/core/engine/report-products.js +2 -13
  30. package/target/main/ts/core/model/clone-source.js +1 -1
  31. package/target/main/ts/core/model/code-structure.d.ts +3 -0
  32. package/target/main/ts/core/model/code-structure.js +4 -1
  33. package/target/main/ts/core/model/finding-ignore.js +1 -1
  34. package/target/main/ts/core/model/finding.js +1 -1
  35. package/target/main/ts/core/model/line-coverage.d.ts +5 -1
  36. package/target/main/ts/core/model/line-coverage.js +14 -11
  37. package/target/main/ts/core/model/measurement.js +1 -1
  38. package/target/main/ts/core/model/plugin-data.d.ts +2 -0
  39. package/target/main/ts/core/model/plugin-data.js +15 -1
  40. package/target/main/ts/core/model/quality-summary.js +1 -1
  41. package/target/main/ts/core/model/scanner-import.js +1 -1
  42. package/target/main/ts/core/model/snapshot.d.ts +1 -0
  43. package/target/main/ts/core/model/snapshot.js +5 -1
  44. package/target/main/ts/core/model/source.d.ts +3 -0
  45. package/target/main/ts/core/model/source.js +15 -0
  46. package/target/main/ts/core/ports/tool-runner.d.ts +18 -0
  47. package/target/main/ts/core/ports/tool-runner.js +2 -0
  48. package/target/main/ts/plugin.d.ts +7 -1
  49. package/target/main/ts/plugin.js +3 -1
  50. package/target/main/ts/plugins/coverage/coverage.d.ts +5 -2
  51. package/target/main/ts/plugins/coverage/coverage.js +35 -10
  52. package/target/main/ts/plugins/language-js/function-facts.d.ts +1 -0
  53. package/target/main/ts/plugins/language-js/function-facts.js +30 -4
  54. package/target/main/ts/report/html/app/viewer-chart-bars.d.ts +11 -0
  55. package/target/main/ts/report/html/app/viewer-chart-bars.js +54 -0
  56. package/target/main/ts/report/html/app/viewer-chart-label.d.ts +15 -0
  57. package/target/main/ts/report/html/app/viewer-chart-label.js +43 -0
  58. package/target/main/ts/report/html/app/viewer-chart-line.d.ts +24 -0
  59. package/target/main/ts/report/html/app/viewer-chart-line.js +89 -0
  60. package/target/main/ts/report/html/app/viewer-chart-points.d.ts +49 -0
  61. package/target/main/ts/report/html/app/viewer-chart-points.js +74 -0
  62. package/target/main/ts/report/html/app/viewer-chart-scale.d.ts +21 -0
  63. package/target/main/ts/report/html/app/viewer-chart-scale.js +93 -0
  64. package/target/main/ts/report/html/app/viewer-chart-svg.d.ts +28 -0
  65. package/target/main/ts/report/html/app/viewer-chart-svg.js +41 -0
  66. package/target/main/ts/report/html/app/viewer-chart-time.d.ts +26 -0
  67. package/target/main/ts/report/html/app/viewer-chart-time.js +150 -0
  68. package/target/main/ts/report/html/app/viewer-chart-tip.d.ts +4 -0
  69. package/target/main/ts/report/html/app/viewer-chart-tip.js +210 -0
  70. package/target/main/ts/report/html/app/viewer-chart-x.d.ts +12 -0
  71. package/target/main/ts/report/html/app/viewer-chart-x.js +50 -0
  72. package/target/main/ts/report/html/app/viewer-chart.d.ts +4 -98
  73. package/target/main/ts/report/html/app/viewer-chart.js +16 -677
  74. package/target/main/ts/report/html/app/viewer-code-map.d.ts +27 -0
  75. package/target/main/ts/report/html/app/viewer-code-map.js +175 -0
  76. package/target/main/ts/report/html/app/viewer-columns.d.ts +38 -0
  77. package/target/main/ts/report/html/app/viewer-columns.js +92 -0
  78. package/target/main/ts/report/html/app/viewer-commit-picker.d.ts +12 -0
  79. package/target/main/ts/report/html/app/viewer-commit-picker.js +229 -0
  80. package/target/main/ts/report/html/app/viewer-commits.d.ts +5 -9
  81. package/target/main/ts/report/html/app/viewer-commits.js +17 -216
  82. package/target/main/ts/report/html/app/viewer-controls.d.ts +43 -0
  83. package/target/main/ts/report/html/app/viewer-controls.js +141 -0
  84. package/target/main/ts/report/html/app/viewer-copy.d.ts +17 -0
  85. package/target/main/ts/report/html/app/viewer-copy.js +64 -0
  86. package/target/main/ts/report/html/app/viewer-diagnostics.d.ts +4 -0
  87. package/target/main/ts/report/html/app/viewer-diagnostics.js +60 -0
  88. package/target/main/ts/report/html/app/viewer-dom.d.ts +27 -0
  89. package/target/main/ts/report/html/app/viewer-dom.js +99 -0
  90. package/target/main/ts/report/html/app/viewer-file-aside.d.ts +19 -0
  91. package/target/main/ts/report/html/app/viewer-file-aside.js +124 -0
  92. package/target/main/ts/report/html/app/viewer-file-figures.d.ts +15 -0
  93. package/target/main/ts/report/html/app/viewer-file-figures.js +60 -0
  94. package/target/main/ts/report/html/app/viewer-file-source.d.ts +7 -0
  95. package/target/main/ts/report/html/app/viewer-file-source.js +119 -0
  96. package/target/main/ts/report/html/app/viewer-files.d.ts +2 -118
  97. package/target/main/ts/report/html/app/viewer-files.js +24 -2184
  98. package/target/main/ts/report/html/app/viewer-filter.d.ts +3 -51
  99. package/target/main/ts/report/html/app/viewer-filter.js +111 -450
  100. package/target/main/ts/report/html/app/viewer-hotspots.d.ts +4 -0
  101. package/target/main/ts/report/html/app/viewer-hotspots.js +131 -0
  102. package/target/main/ts/report/html/app/viewer-inspection.d.ts +69 -0
  103. package/target/main/ts/report/html/app/viewer-inspection.js +36 -0
  104. package/target/main/ts/report/html/app/viewer-issue-group.d.ts +27 -0
  105. package/target/main/ts/report/html/app/viewer-issue-group.js +174 -0
  106. package/target/main/ts/report/html/app/viewer-issues.d.ts +4 -0
  107. package/target/main/ts/report/html/app/viewer-issues.js +173 -0
  108. package/target/main/ts/report/html/app/viewer-language-bar.d.ts +9 -0
  109. package/target/main/ts/report/html/app/viewer-language-bar.js +72 -0
  110. package/target/main/ts/report/html/app/viewer-languages.d.ts +27 -0
  111. package/target/main/ts/report/html/app/viewer-languages.js +93 -0
  112. package/target/main/ts/report/html/app/viewer-layout.d.ts +14 -0
  113. package/target/main/ts/report/html/app/viewer-layout.js +134 -0
  114. package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +47 -0
  115. package/target/main/ts/report/html/app/viewer-line-coverage.js +121 -0
  116. package/target/main/ts/report/html/app/viewer-locations.d.ts +16 -0
  117. package/target/main/ts/report/html/app/viewer-locations.js +31 -0
  118. package/target/main/ts/report/html/app/viewer-map-scale.d.ts +26 -0
  119. package/target/main/ts/report/html/app/viewer-map-scale.js +147 -0
  120. package/target/main/ts/report/html/app/viewer-map-shape.d.ts +42 -0
  121. package/target/main/ts/report/html/app/viewer-map-shape.js +102 -0
  122. package/target/main/ts/report/html/app/viewer-metric-format.d.ts +23 -0
  123. package/target/main/ts/report/html/app/viewer-metric-format.js +93 -0
  124. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -20
  125. package/target/main/ts/report/html/app/viewer-metric-registry.js +0 -77
  126. package/target/main/ts/report/html/app/viewer-metrics-view.d.ts +4 -0
  127. package/target/main/ts/report/html/app/viewer-metrics-view.js +162 -0
  128. package/target/main/ts/report/html/app/viewer-metrics.d.ts +6 -1
  129. package/target/main/ts/report/html/app/viewer-metrics.js +53 -35
  130. package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +12 -0
  131. package/target/main/ts/report/html/app/viewer-overview-cards.js +112 -0
  132. package/target/main/ts/report/html/app/viewer-overview-hotspots.d.ts +9 -0
  133. package/target/main/ts/report/html/app/viewer-overview-hotspots.js +173 -0
  134. package/target/main/ts/report/html/app/viewer-overview-lead.d.ts +12 -0
  135. package/target/main/ts/report/html/app/viewer-overview-lead.js +116 -0
  136. package/target/main/ts/report/html/app/viewer-profile-badges.d.ts +11 -0
  137. package/target/main/ts/report/html/app/viewer-profile-badges.js +119 -0
  138. package/target/main/ts/report/html/app/viewer-profile-table.d.ts +29 -0
  139. package/target/main/ts/report/html/app/viewer-profile-table.js +124 -0
  140. package/target/main/ts/report/html/app/viewer-profile.d.ts +2 -6
  141. package/target/main/ts/report/html/app/viewer-profile.js +6 -248
  142. package/target/main/ts/report/html/app/viewer-pull-sections.d.ts +4 -0
  143. package/target/main/ts/report/html/app/viewer-pull-sections.js +118 -0
  144. package/target/main/ts/report/html/app/viewer-pull-trend.d.ts +5 -0
  145. package/target/main/ts/report/html/app/viewer-pull-trend.js +63 -0
  146. package/target/main/ts/report/html/app/viewer-pulls.d.ts +0 -1
  147. package/target/main/ts/report/html/app/viewer-pulls.js +28 -178
  148. package/target/main/ts/report/html/app/viewer-query-field.d.ts +19 -0
  149. package/target/main/ts/report/html/app/viewer-query-field.js +203 -0
  150. package/target/main/ts/report/html/app/viewer-route.d.ts +34 -0
  151. package/target/main/ts/report/html/app/viewer-route.js +55 -0
  152. package/target/main/ts/report/html/app/viewer-shell.d.ts +20 -0
  153. package/target/main/ts/report/html/app/viewer-shell.js +116 -0
  154. package/target/main/ts/report/html/app/viewer-source-view.d.ts +49 -0
  155. package/target/main/ts/report/html/app/viewer-source-view.js +150 -0
  156. package/target/main/ts/report/html/app/viewer-source.d.ts +0 -84
  157. package/target/main/ts/report/html/app/viewer-source.js +7 -363
  158. package/target/main/ts/report/html/app/viewer-suggest.d.ts +13 -0
  159. package/target/main/ts/report/html/app/viewer-suggest.js +91 -0
  160. package/target/main/ts/report/html/app/viewer-sunburst.d.ts +5 -0
  161. package/target/main/ts/report/html/app/viewer-sunburst.js +40 -0
  162. package/target/main/ts/report/html/app/viewer-table-cells.d.ts +25 -0
  163. package/target/main/ts/report/html/app/viewer-table-cells.js +129 -0
  164. package/target/main/ts/report/html/app/viewer-table-rows.d.ts +54 -0
  165. package/target/main/ts/report/html/app/viewer-table-rows.js +95 -0
  166. package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +16 -0
  167. package/target/main/ts/report/html/app/viewer-tokenizer.js +192 -0
  168. package/target/main/ts/report/html/app/viewer-totals.d.ts +14 -0
  169. package/target/main/ts/report/html/app/viewer-totals.js +89 -0
  170. package/target/main/ts/report/html/app/viewer-treemap.d.ts +24 -0
  171. package/target/main/ts/report/html/app/viewer-treemap.js +112 -0
  172. package/target/main/ts/report/html/app/viewer-trend-data.d.ts +49 -0
  173. package/target/main/ts/report/html/app/viewer-trend-data.js +105 -0
  174. package/target/main/ts/report/html/app/viewer-trend-nav.d.ts +5 -0
  175. package/target/main/ts/report/html/app/viewer-trend-nav.js +85 -0
  176. package/target/main/ts/report/html/app/viewer-trend-points.d.ts +30 -0
  177. package/target/main/ts/report/html/app/viewer-trend-points.js +128 -0
  178. package/target/main/ts/report/html/app/viewer-trend-series.d.ts +26 -0
  179. package/target/main/ts/report/html/app/viewer-trend-series.js +98 -0
  180. package/target/main/ts/report/html/app/viewer-trends.d.ts +2 -70
  181. package/target/main/ts/report/html/app/viewer-trends.js +41 -392
  182. package/target/main/ts/report/html/app/viewer.js +152 -663
  183. package/target/main/ts/report/html/site/badges.js +41 -18
  184. package/target/main/ts/report/json/store/local-store.js +2 -12
  185. package/target/main/ts/report/json/store/operation-cache.d.ts +8 -0
  186. package/target/main/ts/report/json/store/operation-cache.js +32 -0
  187. package/target/main/ts/report/json/store/replace-file.d.ts +1 -0
  188. package/target/main/ts/report/json/store/replace-file.js +14 -0
  189. package/target/main/ts/report.d.ts +1 -0
  190. package/target/main/ts/report.js +1 -0
@@ -2,10 +2,11 @@ import { extname } from 'node:path';
2
2
  import { execute } from '../core/engine/execute.js';
3
3
  import { plan } from '../core/engine/plan.js';
4
4
  import { ReportProducts } from '../core/engine/report-products.js';
5
+ import { codeStructure } from '../core/model/code-structure.js';
5
6
  import { definitions } from '../core/model/measurement.js';
6
7
  import { debtModel } from '../core/model/quality-summary.js';
7
8
  import { reportSchema } from '../core/model/report.js';
8
- import { comparePaths, digest, isSourcePath, sourceDirectoriesExcluded, sourceExtensions, sourceFile, sourceLineCounts, textLineCount } from '../core/model/snapshot.js';
9
+ import { comparePaths, digest, isSourcePath, sourceDirectoriesExcluded, sourceExtensions, sourceFile, sourceFiles as sourceFileSet, sourceLineCounts, textLineCount } from '../core/model/snapshot.js';
9
10
  import { isClaimedText, maxClaimedFileBytes } from '../core/model/source.js';
10
11
  import { defaultSourceExclusions, exclusionMatcher, generatedSourcePolicy, sourceExclusionMatcher } from '../core/profile/exclusions.js';
11
12
  import { duplicationSettings, structuralRules } from '../core/profile/maintainability.js';
@@ -22,8 +23,9 @@ const sourcePlan = plan({ plugins: sourcePlugins, select: selected, inputs: new
22
23
  const duplicationPlan = plan({ plugins: [duplication], select: ['duplication/detect'], inputs: new Map([['sources', duplicationInput.id]]) });
23
24
  const coveragePlan = plan({ plugins: [coverage], select: ['lcov/import', 'lcov/lines'], inputs: new Map([['lcov', lcovInput.id]]) });
24
25
  const securityClaims = securityPlugins.map(plugin => claimMatcher(plugin.claims));
25
- export function claimsNativeFile(path) {
26
- return securityClaims.some(match => match(path));
26
+ export function inspectionFileMatcher(additional) {
27
+ const matches = [...securityClaims, ...additional.map(plugin => claimMatcher(plugin.claims))];
28
+ return path => matches.some(match => match(path));
27
29
  }
28
30
  const measurementDefinitions = {
29
31
  [definitions.lines]: 'Physical lines including blank lines and comments. A final line terminator does not add a line.',
@@ -36,11 +38,12 @@ const measurementDefinitions = {
36
38
  [definitions.cognitiveComplexity]: 'Flow breaks plus nesting weight and logical operator sequences. Nested functions are measured separately. File complexity sums functions and module-level flow breaks.',
37
39
  [definitions.duplicatedLines]: 'Distinct code lines inside repeated Babel syntax subtrees, including original and repeated occurrences. Identifier and literal spellings are ignored for similar-code matches.',
38
40
  };
39
- export async function analyzeSnapshot({ snapshot, excludedOutput, excludedPaths = [], coverage: inputCoverage }, additional = []) {
41
+ export async function analyzeSnapshot({ snapshot, excludedOutput, excludedPaths = [], coverage: inputCoverage }, additional = [], cache) {
40
42
  const rows = [];
41
43
  const diagnostics = (snapshot.oversizedClaims ?? []).map(oversizedClaim);
42
44
  const findings = [];
43
45
  const cloneSources = [];
46
+ const functionBodies = new Map();
44
47
  const sourceFiles = snapshot.files.filter(file => isSourcePath(file.path));
45
48
  const claimedPlugins = [...securityPlugins.filter(plugin => !additional.includes(plugin)), ...additional];
46
49
  const enabled = [...sourcePlugins, duplication, ...(inputCoverage === undefined ? [] : [coverage])];
@@ -51,35 +54,49 @@ export async function analyzeSnapshot({ snapshot, excludedOutput, excludedPaths
51
54
  throw new Error('An additional plugin uses a built-in plugin ID');
52
55
  const reportProducts = new ReportProducts(plugins);
53
56
  const sourcePlans = new Map([['[true]', sourcePlan]]);
54
- const usedPlans = new Map(sourcePlan.map(task => [task.key, task]));
57
+ const usedPlans = new Map(sourcePlan.map(task => [operationBindingKey(task), task]));
55
58
  const matches = claimedPlugins.map(plugin => claimMatcher(plugin.claims));
59
+ const repositoryPlugins = claimedPlugins.flatMap((plugin, index) => {
60
+ if (!plugin.operations.some(operation => operation.scope === 'repository'))
61
+ return [];
62
+ return [{ plugin: pluginForScope(plugin, 'repository'), matches: matches[index] }];
63
+ });
64
+ const filePlugins = repositoryPlugins.length ? claimedPlugins.map(plugin => pluginForScope(plugin, 'file')) : claimedPlugins;
56
65
  const parsed = new Set();
57
66
  const inspected = new Set();
58
67
  const scanned = new Set();
59
- let completedFileInspection = false;
68
+ let completedInspection = false;
60
69
  const scanOnlyOperations = new Set(plugins.filter(plugin => plugin.claims?.scanOnly).flatMap(({ id, operations }) => operations.map(operation => `${id}/${operation.id}`)));
61
70
  const securityOperations = new Map(claimedPlugins.filter(plugin => plugin.kinds.includes('security')).flatMap(plugin => plugin.operations.filter(operation => operation.role === 'inspection').map(operation => [`${plugin.id}/${operation.id}`, plugin.id])));
62
71
  for (const file of snapshot.files) {
63
72
  const source = isSourcePath(file.path);
64
- const claimed = claimedPlugins.filter((_, index) => matches[index](file.path));
65
- const selectedPlugins = isClaimedText(file.bytes) ? claimed : [];
66
- if (claimed.length && file.bytes.byteLength > maxClaimedFileBytes)
73
+ const matching = filePlugins.filter((_, index) => matches[index](file.path));
74
+ const selectedPlugins = isClaimedText(file.bytes) ? matching : [];
75
+ if (matching.length && file.bytes.byteLength > maxClaimedFileBytes)
67
76
  diagnostics.push(oversizedClaim(file.path));
68
77
  if (!source && !selectedPlugins.length)
69
78
  continue;
70
79
  const groupKey = JSON.stringify([source, ...selectedPlugins.map(plugin => plugin.id)]);
71
- const tasks = sourcePlans.get(groupKey) ?? plan({
72
- plugins: source ? [...sourcePlugins, ...claimedPlugins] : selectedPlugins,
73
- select: [...(source ? selected : []), ...selectedPlugins.flatMap(plugin => plugin.operations
74
- .filter(operation => operation.role === 'inspection').map(operation => `${plugin.id}/${operation.id}`))],
75
- inputs: new Map([['file', sourceFile.id]]), ...(source ? { bindings } : {}),
76
- });
77
- sourcePlans.set(groupKey, tasks);
78
- const results = await execute(tasks, new Map([['file', { contract: sourceFile.id, value: file }]]));
79
- if (results.get('babel-syntax/parse')?.state === 'completed')
80
+ let tasks = sourcePlans.get(groupKey);
81
+ if (!tasks) {
82
+ tasks = plan({
83
+ plugins: source ? [...sourcePlugins, ...selectedPlugins] : selectedPlugins,
84
+ select: [...(source ? selected : []), ...selectedPlugins.flatMap(inspectionKeys)],
85
+ inputs: new Map([['file', sourceFile.id]]), ...(source ? { bindings } : {}),
86
+ });
87
+ sourcePlans.set(groupKey, tasks);
88
+ for (const task of tasks)
89
+ usedPlans.set(operationBindingKey(task), task);
90
+ }
91
+ const results = await execute(tasks, new Map([['file', { contract: sourceFile.id, value: file }]]), cache);
92
+ const syntax = results.get('babel-syntax/parse');
93
+ if (syntax?.state === 'completed') {
80
94
  parsed.add(file.path);
95
+ if (inputCoverage !== undefined && codeStructure.accepts(syntax.product.value) && syntax.product.value.functionBodies !== undefined) {
96
+ functionBodies.set(file.path, syntax.product.value.functionBodies);
97
+ }
98
+ }
81
99
  for (const task of tasks) {
82
- usedPlans.set(task.key, task);
83
100
  const outcome = results.get(task.key);
84
101
  record(task, outcome, file.path);
85
102
  if (outcome.state === 'completed' && outcome.product.contract === fileQuality.id && fileQuality.accepts(outcome.product.value)) {
@@ -87,14 +104,30 @@ export async function analyzeSnapshot({ snapshot, excludedOutput, excludedPaths
87
104
  }
88
105
  }
89
106
  }
90
- const copies = (await execute(duplicationPlan, new Map([['sources', { contract: duplicationInput.id, value: cloneSources }]])))
107
+ for (const { plugin, matches } of repositoryPlugins) {
108
+ const select = inspectionKeys(plugin);
109
+ if (!select.length)
110
+ continue;
111
+ const files = snapshot.files.filter(file => matches(file.path) && isClaimedText(file.bytes));
112
+ if (!files.length)
113
+ continue;
114
+ const tasks = plan({ plugins: [plugin], select, inputs: new Map([['files', sourceFileSet.id]]) });
115
+ const results = await execute(tasks, new Map([['files', { contract: sourceFileSet.id, value: files }]]), cache);
116
+ const paths = files.map(({ path }) => path);
117
+ for (const task of tasks) {
118
+ usedPlans.set(operationBindingKey(task), task);
119
+ record(task, results.get(task.key), undefined, paths);
120
+ }
121
+ }
122
+ const copies = (await execute(duplicationPlan, new Map([['sources', { contract: duplicationInput.id, value: cloneSources }]]), cache))
91
123
  .get('duplication/detect');
92
124
  record(duplicationPlan[0], copies);
93
125
  if (inputCoverage !== undefined) {
94
126
  const value = { text: inputCoverage.text, root: inputCoverage.sourceRoot, sourceLines: sourceLineCounts(sourceFiles),
95
127
  codeLines: new Map(cloneSources.map(({ path, codeLines }) => [path, new Set(codeLines)])),
128
+ functionBodies,
96
129
  excludes: sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded) };
97
- const outcomes = await execute(coveragePlan, new Map([['lcov', { contract: lcovInput.id, value }]]));
130
+ const outcomes = await execute(coveragePlan, new Map([['lcov', { contract: lcovInput.id, value }]]), cache);
98
131
  for (const task of coveragePlan)
99
132
  record(task, outcomes.get(task.key));
100
133
  const result = outcomes.get('lcov/import');
@@ -124,31 +157,41 @@ export async function analyzeSnapshot({ snapshot, excludedOutput, excludedPaths
124
157
  coverage: inputCoverage === undefined ? null : { inputDigest: digest(inputCoverage.text), pathBase: inputCoverage.sourceRoot,
125
158
  merge: 'any-hit', hitCounts: 'sum', lines: 'code-only' },
126
159
  ...(securityScanners.length ? { securityScanners } : {}),
127
- plugins: plugins.map(({ id, version, api, tools, kinds, claims }) => ({ id, version, api, tools: tools ?? {}, ...(kinds === undefined ? {} : { kinds }), ...(claims === undefined ? {} : { claims }) })),
160
+ plugins: plugins.map(({ id, version, api, tools, kinds, claims, settings }) => ({ id, version, api, tools: tools ?? {},
161
+ ...(kinds === undefined ? {} : { kinds }), ...(claims === undefined ? {} : { claims }), ...(settings === undefined ? {} : { settings }) })),
128
162
  operations: [...usedPlans.values(), ...duplicationPlan, ...(inputCoverage === undefined ? [] : coveragePlan)]
129
- .map(task => ({ key: task.key, inputs: Object.fromEntries(task.inputs) })),
163
+ .map(task => ({ key: task.key, inputs: Object.fromEntries(task.inputs),
164
+ ...(task.operation.scope === 'repository' ? { scope: task.operation.scope } : {}) })),
130
165
  },
131
166
  definitions: { ...Object.fromEntries((pluginData?.metrics ?? []).map(metric => [metric.id, metric.description ?? metric.label])),
132
167
  ...measurementDefinitions },
133
168
  scope: { files: sourceFiles.length, parsed: parsed.size },
134
- status: diagnostics.length > 0 ? 'partial' : sourceFiles.length === 0 && !completedFileInspection ? 'not-applicable' : 'complete',
169
+ status: diagnostics.length > 0 ? 'partial' : sourceFiles.length === 0 && !completedInspection ? 'not-applicable' : 'complete',
135
170
  measurements: rows,
136
171
  diagnostics,
137
172
  findings,
138
173
  ...(pluginData === undefined ? {} : { pluginData: { ...pluginData,
139
174
  inventory: [...inventory].sort(([left], [right]) => comparePaths(left, right)).map(([path, { lines, bytes }]) => ({ path, lines, ...(bytes === undefined ? {} : { bytes }), language: languageId(path), analysed: parsed.has(path) || inspected.has(path) })) } }),
140
175
  };
141
- function record(task, outcome, path) {
176
+ function record(task, outcome, path, paths) {
142
177
  if (outcome.state !== 'completed') {
143
178
  diagnostics.push(diagnostic(task.key, outcome, path));
144
179
  return;
145
180
  }
146
181
  try {
147
182
  const stored = reportProducts.record(task, outcome.product, path);
148
- if (path !== undefined && task.operation.role === 'inspection') {
149
- completedFileInspection = true;
150
- if (!scanOnlyOperations.has(task.key))
151
- inspected.add(path);
183
+ for (const message of outcome.diagnostics ?? [])
184
+ diagnostics.push({ operation: task.key, state: 'partial', message,
185
+ ...(path === undefined ? {} : { path }) });
186
+ if (task.operation.role === 'inspection' && (path !== undefined || paths?.length)) {
187
+ completedInspection = true;
188
+ if (!scanOnlyOperations.has(task.key)) {
189
+ if (path !== undefined)
190
+ inspected.add(path);
191
+ else
192
+ for (const file of paths ?? [])
193
+ inspected.add(file);
194
+ }
152
195
  }
153
196
  const scanner = securityOperations.get(task.key);
154
197
  if (scanner)
@@ -163,6 +206,16 @@ export async function analyzeSnapshot({ snapshot, excludedOutput, excludedPaths
163
206
  }
164
207
  }
165
208
  }
209
+ function pluginForScope(plugin, scope) {
210
+ const operations = plugin.operations.filter(operation => (operation.scope ?? 'file') === scope);
211
+ return operations.length === plugin.operations.length ? plugin : { ...plugin, operations };
212
+ }
213
+ function inspectionKeys(plugin) {
214
+ return plugin.operations.filter(operation => operation.role === 'inspection').map(operation => `${plugin.id}/${operation.id}`);
215
+ }
216
+ function operationBindingKey(task) {
217
+ return JSON.stringify([task.key, [...task.inputs]]);
218
+ }
166
219
  function oversizedClaim(path) {
167
220
  return { operation: 'source/claims', state: 'partial', path, message: 'Plugin inspection skipped a file larger than 1 MiB' };
168
221
  }
@@ -1,4 +1,6 @@
1
1
  import type { LcovFiles } from '../api/import/lcov-files.js';
2
+ import type { OperationCacheOptions } from '../core/engine/operation-cache.js';
3
+ import type { Plugin } from '../core/engine/plugin.js';
2
4
  import type { FindingIgnoreRule } from '../core/model/finding-ignore.js';
3
5
  import type { Report } from '../core/model/report.js';
4
6
  import type { FindingInput } from '../core/model/scanner-import.js';
@@ -18,6 +20,9 @@ export interface InspectRequest {
18
20
  readonly findingInputs?: readonly FindingInput[];
19
21
  readonly findingRoot?: string;
20
22
  readonly ignore?: readonly FindingIgnoreRule[];
23
+ /** Trusted in-process plugins for the default executor. */
24
+ readonly plugins?: readonly Plugin[];
25
+ readonly operationCache?: OperationCacheOptions;
21
26
  }
22
27
  export declare function inspect(request: InspectRequest, overrides?: AnalysisExecutor | Partial<InspectionPorts>): Promise<Report>;
23
28
  export declare function attachFindings(report: Report, inputs: readonly FindingInput[], root: string, findingRoot: string, excludes: (path: string) => boolean): Promise<Report>;
@@ -7,14 +7,18 @@ import { reportSchema } from '../core/model/report.js';
7
7
  import { isExcludedDirectory } from '../core/model/snapshot.js';
8
8
  import { executeInspection } from '../core/usecases/inspect.js';
9
9
  import { LocalReportStore } from '../report/json/store/local-store.js';
10
- import { analyzeSnapshot, claimsNativeFile } from './analyze-snapshot.js';
10
+ import { analyzeSnapshot, inspectionFileMatcher } from './analyze-snapshot.js';
11
11
  import { attachChurn } from './attach-churn.js';
12
12
  export { analyzeSnapshot } from './analyze-snapshot.js';
13
13
  export async function inspect(request, overrides) {
14
- const { lcov, findingInputs = [] } = request;
14
+ const { lcov, findingInputs = [], plugins = [], operationCache } = request;
15
+ if ((plugins.length || operationCache) && (typeof overrides === 'function' || overrides?.analyze)) {
16
+ throw new Error('Configure plugins and the operation cache on the custom executor');
17
+ }
18
+ const claims = inspectionFileMatcher(plugins);
15
19
  const ports = {
16
- readSource: excludes => readSource(request, excludes),
17
- analyze: analyzeSnapshot,
20
+ readSource: excludes => readSource(request, excludes, claims),
21
+ analyze: input => analyzeSnapshot(input, plugins, operationCache),
18
22
  ...(lcov === undefined ? {} : { readCoverage: () => readLcovFiles(lcov) }),
19
23
  ...(findingInputs.length === 0 ? {} : { importFindings: (report, root, excludes) => attachFindings(report, findingInputs, root, request.findingRoot === undefined ? root : resolve(request.findingRoot), excludes) }),
20
24
  recordChurn: attachChurn,
@@ -22,8 +26,8 @@ export async function inspect(request, overrides) {
22
26
  };
23
27
  return executeInspection(request, ports);
24
28
  }
25
- async function readSource(request, excludes) {
26
- const source = await readInspectionSource(request, excludes, claimsNativeFile);
29
+ async function readSource(request, excludes, claims) {
30
+ const source = await readInspectionSource(request, excludes, claims);
27
31
  const store = new LocalReportStore(source.output);
28
32
  return { ...source, save: (report) => store.save(report) };
29
33
  }
@@ -1,10 +1,12 @@
1
+ import type { OperationCacheOptions } from './operation-cache.js';
1
2
  import type { Product } from './plugin.js';
2
3
  import type { PlannedOperation } from './plan.js';
3
4
  export type Outcome = {
4
5
  readonly state: 'completed';
5
6
  readonly product: Product;
7
+ readonly diagnostics?: readonly string[];
6
8
  } | {
7
9
  readonly state: 'failed' | 'blocked';
8
10
  readonly reason: string;
9
11
  };
10
- export declare function execute(plan: readonly PlannedOperation[], external: ReadonlyMap<string, Product>): Promise<ReadonlyMap<string, Outcome>>;
12
+ export declare function execute(plan: readonly PlannedOperation[], external: ReadonlyMap<string, Product>, cache?: OperationCacheOptions): Promise<ReadonlyMap<string, Outcome>>;
@@ -1,4 +1,5 @@
1
- export async function execute(plan, external) {
1
+ import { operationCacheKey, readCachedOperation, writeCachedOperation } from './operation-cache.js';
2
+ export async function execute(plan, external, cache) {
2
3
  const results = new Map();
3
4
  for (const task of plan) {
4
5
  const inputs = new Map();
@@ -18,6 +19,13 @@ export async function execute(plan, external) {
18
19
  for (const [name, contract] of Object.entries(task.operation.inputs)) {
19
20
  readInput(inputs, name, contract);
20
21
  }
22
+ const key = cache && operationCacheKey(task, inputs, cache.configurationDigest);
23
+ const hit = key && cache ? await readCachedOperation(cache.store, key, task) : undefined;
24
+ if (hit) {
25
+ results.set(task.key, { state: 'completed', product: hit });
26
+ continue;
27
+ }
28
+ const diagnostics = [];
21
29
  const context = {
22
30
  read: (port, contract) => {
23
31
  if (!Object.hasOwn(task.operation.inputs, port) || task.operation.inputs[port]?.id !== contract.id) {
@@ -25,6 +33,7 @@ export async function execute(plan, external) {
25
33
  }
26
34
  return readInput(inputs, port, contract);
27
35
  },
36
+ emitDiagnostic: message => diagnostics.push(message),
28
37
  };
29
38
  const value = await task.operation.execute(context);
30
39
  const { output } = task.operation;
@@ -32,7 +41,10 @@ export async function execute(plan, external) {
32
41
  throw new Error(`Invalid output for ${output.id}`);
33
42
  if (task.validateOutput && !task.validateOutput(value))
34
43
  throw new Error(`Output violates the schema for ${output.id}`);
35
- results.set(task.key, { state: 'completed', product: { contract: output.id, value } });
44
+ const product = { contract: output.id, value };
45
+ if (key && cache && diagnostics.length === 0)
46
+ await writeCachedOperation(cache.store, key, product);
47
+ results.set(task.key, { state: 'completed', product, ...(diagnostics.length ? { diagnostics } : {}) });
36
48
  }
37
49
  catch (error) {
38
50
  results.set(task.key, { state: 'failed', reason: error instanceof Error ? error.message : String(error) });
@@ -0,0 +1,14 @@
1
+ import type { PlannedOperation } from './plan.js';
2
+ import type { Product } from './plugin.js';
3
+ export interface OperationCache {
4
+ read(key: string): Promise<Uint8Array | undefined>;
5
+ write(key: string, bytes: Uint8Array): Promise<void>;
6
+ }
7
+ export interface OperationCacheOptions {
8
+ readonly store: OperationCache;
9
+ /** Digest of effective settings that the input products do not carry. */
10
+ readonly configurationDigest: string;
11
+ }
12
+ export declare function operationCacheKey(task: PlannedOperation, inputs: ReadonlyMap<string, Product>, configurationDigest: string): string | undefined;
13
+ export declare function readCachedOperation(store: OperationCache, key: string, task: PlannedOperation): Promise<Product | undefined>;
14
+ export declare function writeCachedOperation(store: OperationCache, key: string, product: Product): Promise<void>;
@@ -0,0 +1,66 @@
1
+ import { deserialize, serialize } from 'node:v8';
2
+ import { digest } from '../model/snapshot.js';
3
+ import { isRecord } from './plugin.js';
4
+ export function operationCacheKey(task, inputs, configurationDigest) {
5
+ if (task.cacheIdentity === undefined)
6
+ return undefined;
7
+ const argumentsByPort = [...inputs];
8
+ try {
9
+ if (argumentsByPort.some(([, { value }]) => !cacheData(value)))
10
+ return undefined;
11
+ return digest(serialize([
12
+ 'repometry.operation-cache/v1', process.version, task.key, task.cacheIdentity, configurationDigest,
13
+ [...task.inputs], argumentsByPort,
14
+ ]));
15
+ }
16
+ catch {
17
+ return undefined;
18
+ }
19
+ }
20
+ export async function readCachedOperation(store, key, task) {
21
+ try {
22
+ const bytes = await store.read(key);
23
+ if (!bytes)
24
+ return undefined;
25
+ const product = deserialize(bytes);
26
+ const output = task.operation.output;
27
+ if (isRecord(product) && product.contract === output.id && Object.hasOwn(product, 'value') && cacheData(product.value)
28
+ && output.accepts(product.value) && (!task.validateOutput || task.validateOutput(product.value))) {
29
+ return { contract: output.id, value: product.value };
30
+ }
31
+ }
32
+ catch {
33
+ // Unreadable cache entries are misses.
34
+ }
35
+ return undefined;
36
+ }
37
+ export async function writeCachedOperation(store, key, product) {
38
+ try {
39
+ if (cacheData(product.value))
40
+ await store.write(key, serialize(product));
41
+ }
42
+ catch {
43
+ // Cache publication is optional once an inspection has a valid result.
44
+ }
45
+ }
46
+ function cacheData(value, seen = new Set()) {
47
+ if (value === null)
48
+ return true;
49
+ if (typeof value !== 'object')
50
+ return ['undefined', 'boolean', 'number', 'bigint', 'string'].includes(typeof value);
51
+ const prototype = Object.getPrototypeOf(value);
52
+ if (ArrayBuffer.isView(value))
53
+ return prototype === Buffer.prototype || prototype === Uint8Array.prototype;
54
+ const array = Array.isArray(value);
55
+ if (prototype !== (array ? Array.prototype : Object.prototype))
56
+ return false;
57
+ if (seen.has(value))
58
+ return true;
59
+ seen.add(value);
60
+ return Reflect.ownKeys(value).every(key => {
61
+ const property = Object.getOwnPropertyDescriptor(value, key);
62
+ return typeof key === 'string' && property !== undefined && 'value' in property
63
+ && (property.enumerable || (array && key === 'length')) && cacheData(property.value, seen);
64
+ });
65
+ }
66
+ //# sourceMappingURL=operation-cache.js.map
@@ -18,5 +18,6 @@ export interface PlannedOperation {
18
18
  readonly inputs: ReadonlyMap<string, InputBinding>;
19
19
  readonly declaration?: ProductDeclaration;
20
20
  readonly validateOutput?: (value: unknown) => boolean;
21
+ readonly cacheIdentity?: string;
21
22
  }
22
23
  export declare function plan(request: PlanRequest): readonly PlannedOperation[];
@@ -1,8 +1,9 @@
1
1
  import { Ajv2020 } from 'ajv/dist/2020.js';
2
+ import { isJsonValue } from '../model/plugin-data.js';
2
3
  import { pluginApi } from './plugin.js';
3
4
  import { manifestProducts } from './manifest.js';
4
5
  export function plan(request) {
5
- const { operations, declarations } = indexOperations(request.plugins, new Set(request.legacyPluginIds));
6
+ const { operations, declarations, cacheIdentities } = indexOperations(request.plugins, new Set(request.legacyPluginIds));
6
7
  const resolved = new Map();
7
8
  const path = [];
8
9
  function visit(key) {
@@ -44,8 +45,9 @@ export function plan(request) {
44
45
  path.pop();
45
46
  const declaration = declarations.get(key);
46
47
  const validateOutput = declaration?.schema === undefined ? undefined : validateSchema(declaration.schema, key);
48
+ const cacheIdentity = cacheIdentities.get(key);
47
49
  resolved.set(key, { key, operation, inputs, ...(declaration === undefined ? {} : { declaration }),
48
- ...(validateOutput === undefined ? {} : { validateOutput }) });
50
+ ...(validateOutput === undefined ? {} : { validateOutput }), ...(cacheIdentity === undefined ? {} : { cacheIdentity }) });
49
51
  }
50
52
  for (const key of request.select)
51
53
  visit(key);
@@ -63,6 +65,7 @@ function indexOperations(plugins, legacyPlugins) {
63
65
  const ids = new Set();
64
66
  const operations = new Map();
65
67
  const declarations = new Map();
68
+ const cacheIdentities = new Map();
66
69
  const metricOwners = new Map();
67
70
  for (const plugin of plugins) {
68
71
  if (plugin.api !== pluginApi)
@@ -71,6 +74,13 @@ function indexOperations(plugins, legacyPlugins) {
71
74
  throw new Error(`Invalid or duplicate plugin ID: ${plugin.id}`);
72
75
  ids.add(plugin.id);
73
76
  const products = manifestProducts(plugin, legacyPlugins.has(plugin.id));
77
+ if (plugin.settings !== undefined) {
78
+ if (!isJsonValue(plugin.settings))
79
+ throw new Error(`Plugin settings must be JSON data: ${plugin.id}`);
80
+ if (plugin.config !== undefined && !new Ajv2020().validate(plugin.config, plugin.settings)) {
81
+ throw new Error(`Plugin settings violate the configuration schema: ${plugin.id}`);
82
+ }
83
+ }
74
84
  for (const declaration of products?.values() ?? []) {
75
85
  for (const metric of declaration.metrics ?? []) {
76
86
  const owner = metricOwners.get(metric.id);
@@ -83,16 +93,25 @@ function indexOperations(plugins, legacyPlugins) {
83
93
  const key = `${plugin.id}/${operation.id}`;
84
94
  if (operations.has(key) || !operation.id || operation.id.includes('/'))
85
95
  throw new Error(`Invalid or duplicate operation: ${key}`);
96
+ if (operation.scope !== undefined && operation.scope !== 'file' && operation.scope !== 'repository') {
97
+ throw new Error(`Invalid operation scope: ${key}`);
98
+ }
86
99
  if (products !== undefined) {
87
100
  const declaration = products.get(operation.output.id);
88
101
  if (!declaration)
89
102
  throw new Error(`Undeclared output for ${key}: ${operation.output.id}`);
90
103
  declarations.set(key, declaration);
104
+ if (declaration.persistence === 'cache') {
105
+ cacheIdentities.set(key, JSON.stringify([
106
+ plugin.api, plugin.version, Object.entries(plugin.tools ?? {}).sort(), plugin.settings, operation.scope, operation.implementation,
107
+ declaration.contract, declaration.schema,
108
+ ]));
109
+ }
91
110
  }
92
111
  operations.set(key, operation);
93
112
  }
94
113
  }
95
- return { operations, declarations };
114
+ return { operations, declarations, cacheIdentities };
96
115
  }
97
116
  function candidatesFor(contract, inputs, operations) {
98
117
  const candidates = [];
@@ -1,5 +1,7 @@
1
1
  import type { MetricDescriptor } from '../model/metric-descriptor.js';
2
+ import type { JsonValue } from '../model/plugin-data.js';
2
3
  export type { MetricDescriptor, MetricScope } from '../model/metric-descriptor.js';
4
+ export { isRecord } from '../model/plugin-data.js';
3
5
  export declare const pluginApi = "repometry.plugin/v1";
4
6
  export interface DataContract<T = unknown> {
5
7
  readonly id: string;
@@ -11,12 +13,16 @@ export interface Product {
11
13
  }
12
14
  export interface InspectionInputs {
13
15
  read<T>(port: string, contract: DataContract<T>): T;
16
+ emitDiagnostic?(message: string): void;
14
17
  }
15
18
  export interface Operation {
16
19
  readonly id: string;
17
20
  readonly role: 'provider' | 'inspection';
21
+ readonly scope?: 'file' | 'repository';
18
22
  readonly inputs: Readonly<Record<string, DataContract>>;
19
23
  readonly output: DataContract;
24
+ /** Fingerprint for executable details that the declared versions and inputs do not carry. */
25
+ readonly implementation?: string;
20
26
  execute(inputs: InspectionInputs): unknown | Promise<unknown>;
21
27
  }
22
28
  export interface RuleDescriptor {
@@ -53,9 +59,10 @@ export interface Plugin {
53
59
  readonly operations: readonly Operation[];
54
60
  readonly rules?: readonly RuleDescriptor[];
55
61
  readonly config?: PluginConfigSchema;
62
+ /** Effective non-secret settings saved with inspection provenance. */
63
+ readonly settings?: JsonValue;
56
64
  readonly kinds: readonly PluginKind[];
57
65
  readonly claims?: FileClaims;
58
66
  readonly produces: readonly ProductDeclaration[];
59
67
  }
60
68
  export type LegacyPlugin = Omit<Plugin, 'kinds' | 'claims' | 'produces'>;
61
- export declare function isRecord(value: unknown): value is Record<string, unknown>;
@@ -1,4 +1,2 @@
1
+ export { isRecord } from '../model/plugin-data.js';
1
2
  export const pluginApi = 'repometry.plugin/v1';
2
- export function isRecord(value) {
3
- return typeof value === 'object' && value !== null && !Array.isArray(value);
4
- }
@@ -1,6 +1,7 @@
1
1
  import { isDeepStrictEqual } from 'node:util';
2
2
  import { findingResult } from '../model/finding.js';
3
3
  import { measurements } from '../model/measurement.js';
4
+ import { isJsonValue } from '../model/plugin-data.js';
4
5
  import { isRecord } from './plugin.js';
5
6
  import { isCoreReportProduct } from './manifest.js';
6
7
  export class ReportProducts {
@@ -49,7 +50,7 @@ export class ReportProducts {
49
50
  throw new Error(`Undeclared metric from ${task.key}: ${unknown.definition}`);
50
51
  }
51
52
  if (!isCoreReportProduct(contract)) {
52
- if (!isJson(value))
53
+ if (!isJsonValue(value))
53
54
  throw new Error(`Report product ${contract} is not JSON data`);
54
55
  const record = { operation: task.key, ...(path === undefined ? {} : { path }), value };
55
56
  const existing = this.products.get(contract);
@@ -71,16 +72,4 @@ export class ReportProducts {
71
72
  rules: this.rules, products: Object.fromEntries(this.products) };
72
73
  }
73
74
  }
74
- function isJson(value, depth = 0) {
75
- if (depth > 512)
76
- return false;
77
- if (value === null || typeof value === 'boolean' || typeof value === 'string')
78
- return true;
79
- if (typeof value === 'number')
80
- return Number.isFinite(value);
81
- if (Array.isArray(value))
82
- return value.every(item => isJson(item, depth + 1));
83
- return isRecord(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)
84
- && Object.values(value).every(item => isJson(item, depth + 1));
85
- }
86
75
  //# sourceMappingURL=report-products.js.map
@@ -1,4 +1,4 @@
1
- import { isRecord } from '../engine/plugin.js';
1
+ import { isRecord } from './plugin-data.js';
2
2
  function isCandidate(value) {
3
3
  return isRecord(value) && isCount(value.start) && isCount(value.end) && value.start < value.end
4
4
  && isCount(value.line) && value.line > 0 && isCount(value.endLine) && value.endLine >= value.line
@@ -1,5 +1,6 @@
1
1
  import type { DataContract } from '../engine/plugin.js';
2
2
  import type { CloneSource } from './clone-source.js';
3
+ import type { SourceLineRange } from './source.js';
3
4
  export declare const structuralCheckIds: readonly ['function-parameters', 'return-statements', 'boolean-logic', 'nested-control-flow', 'function-complexity', 'file-complexity'];
4
5
  export type StructuralCheck = typeof structuralCheckIds[number];
5
6
  export interface FunctionComplexity {
@@ -24,6 +25,8 @@ export interface CodeStructure {
24
25
  readonly commentLines: number;
25
26
  readonly cyclomaticFunctions: readonly FunctionComplexity[];
26
27
  readonly cognitiveFunctions: readonly FunctionComplexity[];
28
+ /** Sorted, merged lines containing code inside a function body. An empty list means the provider found none. */
29
+ readonly functionBodies?: readonly SourceLineRange[];
27
30
  readonly observations: readonly StructuralObservation[];
28
31
  readonly clones: CloneSource;
29
32
  }
@@ -1,5 +1,6 @@
1
- import { isRecord } from '../engine/plugin.js';
1
+ import { isRecord } from './plugin-data.js';
2
2
  import { isCloneSource } from './clone-source.js';
3
+ import { isMergedLineRanges } from './source.js';
3
4
  export const structuralCheckIds = [
4
5
  'function-parameters', 'return-statements', 'boolean-logic', 'nested-control-flow',
5
6
  'function-complexity', 'file-complexity',
@@ -26,6 +27,8 @@ export const codeStructure = {
26
27
  && isCount(value.cognitiveComplexity) && isCount(value.commentLines)
27
28
  && Array.isArray(value.cyclomaticFunctions) && value.cyclomaticFunctions.every(isFunctionComplexity)
28
29
  && Array.isArray(value.cognitiveFunctions) && value.cognitiveFunctions.every(isFunctionComplexity)
30
+ && (value.functionBodies === undefined
31
+ || isMergedLineRanges(value.functionBodies) && (value.functionBodies.at(-1)?.[1] ?? 0) <= value.lines)
29
32
  && Array.isArray(value.observations) && value.observations.every(isObservation)
30
33
  && isCloneSource(value.clones) && value.clones.path === value.path,
31
34
  };
@@ -1,4 +1,4 @@
1
- import { isRecord } from '../engine/plugin.js';
1
+ import { isRecord } from './plugin-data.js';
2
2
  import { exclusionMatcher, normalizeExclusions } from '../profile/exclusions.js';
3
3
  const fields = new Set(['tool', 'rule', 'path', 'reason']);
4
4
  export function normalizeFindingIgnore(value) {
@@ -1,4 +1,4 @@
1
- import { isRecord } from '../engine/plugin.js';
1
+ import { isRecord } from './plugin-data.js';
2
2
  import { measurements } from './measurement.js';
3
3
  export const findingCategories = ['structure', 'duplication', 'lint', 'security', 'dependency', 'secret', 'infrastructure'];
4
4
  export const findingLevels = ['low', 'medium', 'high', 'unknown'];
@@ -1,11 +1,15 @@
1
1
  import type { DataContract } from '../engine/plugin.js';
2
- export type CoveredLineRange = readonly [first: number, last: number];
2
+ import type { SourceLineRange } from './source.js';
3
+ export type CoveredLineRange = SourceLineRange;
3
4
  export type HitRun = readonly [first: number, last: number, count: number];
5
+ export type FunctionCallCount = readonly [line: number, calls: number];
4
6
  export interface FileLineCoverage {
5
7
  readonly covered: readonly CoveredLineRange[];
6
8
  readonly uncovered: readonly CoveredLineRange[];
7
9
  readonly partial?: readonly CoveredLineRange[];
8
10
  readonly hits?: readonly HitRun[];
11
+ readonly functionCalls?: readonly FunctionCallCount[];
12
+ readonly functionBodies?: readonly SourceLineRange[];
9
13
  }
10
14
  export type LineCoverage = Readonly<Record<string, FileLineCoverage>>;
11
15
  export declare const lcovLines: DataContract<LineCoverage>;