repometry 0.4.2 → 0.6.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.
- package/README.md +36 -14
- package/package.json +1 -1
- package/target/main/resources/report/json/comparison-v1.schema.json +6 -6
- package/target/main/resources/report/json/file-metrics-v1.schema.json +7 -6
- package/target/main/resources/report/json/pull-review-v1.schema.json +5 -5
- package/target/main/resources/report/json/report-v2.schema.json +210 -11
- package/target/main/resources/report/json/repository-summary-v1.schema.json +161 -14
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +518 -6
- package/target/main/resources/viewer/styles.css +7 -2
- package/target/main/ts/api/git/changes.d.ts +1 -1
- package/target/main/ts/api/git/changes.js +3 -3
- package/target/main/ts/api/git/commit-metadata.js +6 -4
- package/target/main/ts/api/git/git.d.ts +2 -1
- package/target/main/ts/api/git/git.js +16 -4
- package/target/main/ts/api/git/inspection-source.d.ts +1 -1
- package/target/main/ts/api/git/inspection-source.js +4 -10
- package/target/main/ts/api/git/local.d.ts +1 -1
- package/target/main/ts/api/git/local.js +41 -7
- package/target/main/ts/api/process/docker-tool-runner.d.ts +13 -0
- package/target/main/ts/api/process/docker-tool-runner.js +108 -0
- package/target/main/ts/api/process/failure.d.ts +1 -0
- package/target/main/ts/api/process/failure.js +12 -0
- package/target/main/ts/api/process/plugin.d.ts +10 -0
- package/target/main/ts/api/process/plugin.js +96 -0
- package/target/main/ts/api/worker/remote-executor.d.ts +1 -1
- package/target/main/ts/api/worker/remote-executor.js +2 -2
- package/target/main/ts/api/worker/worker-protocol.d.ts +2 -2
- package/target/main/ts/api/worker/worker-protocol.js +8 -8
- package/target/main/ts/api/worker/worker.d.ts +1 -1
- package/target/main/ts/api/worker/worker.js +4 -4
- package/target/main/ts/cli/main.js +4 -3
- package/target/main/ts/cli/reporting.d.ts +1 -1
- package/target/main/ts/cli/reporting.js +1 -1
- package/target/main/ts/compose/analysis-files.d.ts +13 -0
- package/target/main/ts/compose/analysis-files.js +95 -0
- package/target/main/ts/compose/analysis-imports.d.ts +7 -0
- package/target/main/ts/compose/analysis-imports.js +34 -0
- package/target/main/ts/compose/analysis-report.d.ts +5 -0
- package/target/main/ts/compose/analysis-report.js +78 -0
- package/target/main/ts/compose/analysis-repository.d.ts +6 -0
- package/target/main/ts/compose/analysis-repository.js +61 -0
- package/target/main/ts/compose/analysis-results.d.ts +38 -0
- package/target/main/ts/compose/analysis-results.js +78 -0
- package/target/main/ts/compose/analysis-sources.d.ts +73 -0
- package/target/main/ts/compose/analysis-sources.js +47 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +3 -2
- package/target/main/ts/compose/analyze-snapshot.js +19 -197
- package/target/main/ts/compose/diff-coverage.d.ts +2 -0
- package/target/main/ts/compose/diff-coverage.js +6 -4
- package/target/main/ts/compose/inspect.d.ts +5 -0
- package/target/main/ts/compose/inspect.js +14 -7
- package/target/main/ts/compose/languages.d.ts +29 -0
- package/target/main/ts/compose/languages.js +87 -0
- package/target/main/ts/compose/sources.js +14 -12
- package/target/main/ts/core/engine/execute.d.ts +3 -1
- package/target/main/ts/core/engine/execute.js +14 -2
- package/target/main/ts/core/engine/manifest.d.ts +2 -2
- package/target/main/ts/core/engine/manifest.js +25 -5
- package/target/main/ts/core/engine/operation-cache.d.ts +14 -0
- package/target/main/ts/core/engine/operation-cache.js +66 -0
- package/target/main/ts/core/engine/plan.d.ts +3 -4
- package/target/main/ts/core/engine/plan.js +28 -11
- package/target/main/ts/core/engine/plugin.d.ts +10 -2
- package/target/main/ts/core/engine/plugin.js +1 -3
- package/target/main/ts/core/engine/report-products.js +2 -13
- package/target/main/ts/core/model/clone-source.d.ts +1 -0
- package/target/main/ts/core/model/clone-source.js +2 -1
- package/target/main/ts/core/model/code-structure.d.ts +5 -0
- package/target/main/ts/core/model/code-structure.js +10 -1
- package/target/main/ts/core/model/finding-ignore.js +1 -1
- package/target/main/ts/core/model/finding.js +1 -1
- package/target/main/ts/core/model/language.d.ts +10 -0
- package/target/main/ts/core/model/language.js +6 -0
- package/target/main/ts/core/model/line-coverage.d.ts +5 -1
- package/target/main/ts/core/model/line-coverage.js +14 -11
- package/target/main/ts/core/model/measurement.d.ts +7 -6
- package/target/main/ts/core/model/measurement.js +18 -7
- package/target/main/ts/core/model/plugin-data.d.ts +5 -0
- package/target/main/ts/core/model/plugin-data.js +15 -1
- package/target/main/ts/core/model/quality-summary.js +6 -5
- package/target/main/ts/core/model/report.d.ts +1 -2
- package/target/main/ts/core/model/report.js +0 -1
- package/target/main/ts/core/model/scanner-import.js +1 -1
- package/target/main/ts/core/model/snapshot.d.ts +1 -2
- package/target/main/ts/core/model/snapshot.js +5 -7
- package/target/main/ts/core/model/source.d.ts +3 -0
- package/target/main/ts/core/model/source.js +15 -0
- package/target/main/ts/core/ports/tool-runner.d.ts +18 -0
- package/target/main/ts/core/ports/tool-runner.js +2 -0
- package/target/main/ts/core/usecases/compare.js +61 -17
- package/target/main/ts/core/usecases/inspect.js +2 -2
- package/target/main/ts/plugin.d.ts +10 -3
- package/target/main/ts/plugin.js +4 -2
- package/target/main/ts/plugins/coverage/coverage.d.ts +5 -2
- package/target/main/ts/plugins/coverage/coverage.js +35 -10
- package/target/main/ts/plugins/duplication/duplication.js +10 -4
- package/target/main/ts/plugins/language-js/babel-provider.js +8 -2
- package/target/main/ts/plugins/language-js/extensions.d.ts +3 -0
- package/target/main/ts/plugins/language-js/extensions.js +4 -0
- package/target/main/ts/plugins/language-js/function-facts.d.ts +1 -0
- package/target/main/ts/plugins/language-js/function-facts.js +30 -4
- package/target/main/ts/plugins/language-js/js-security.js +3 -2
- package/target/main/ts/report/html/app/viewer-chart-bars.d.ts +11 -0
- package/target/main/ts/report/html/app/viewer-chart-bars.js +54 -0
- package/target/main/ts/report/html/app/viewer-chart-label.d.ts +15 -0
- package/target/main/ts/report/html/app/viewer-chart-label.js +43 -0
- package/target/main/ts/report/html/app/viewer-chart-line.d.ts +24 -0
- package/target/main/ts/report/html/app/viewer-chart-line.js +89 -0
- package/target/main/ts/report/html/app/viewer-chart-points.d.ts +49 -0
- package/target/main/ts/report/html/app/viewer-chart-points.js +74 -0
- package/target/main/ts/report/html/app/viewer-chart-scale.d.ts +21 -0
- package/target/main/ts/report/html/app/viewer-chart-scale.js +93 -0
- package/target/main/ts/report/html/app/viewer-chart-svg.d.ts +28 -0
- package/target/main/ts/report/html/app/viewer-chart-svg.js +41 -0
- package/target/main/ts/report/html/app/viewer-chart-time.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-chart-time.js +150 -0
- package/target/main/ts/report/html/app/viewer-chart-tip.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-chart-tip.js +210 -0
- package/target/main/ts/report/html/app/viewer-chart-x.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-chart-x.js +50 -0
- package/target/main/ts/report/html/app/viewer-chart.d.ts +4 -98
- package/target/main/ts/report/html/app/viewer-chart.js +16 -677
- package/target/main/ts/report/html/app/viewer-code-map.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-code-map.js +175 -0
- package/target/main/ts/report/html/app/viewer-columns.d.ts +38 -0
- package/target/main/ts/report/html/app/viewer-columns.js +92 -0
- package/target/main/ts/report/html/app/viewer-commit-picker.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-commit-picker.js +229 -0
- package/target/main/ts/report/html/app/viewer-commits.d.ts +5 -9
- package/target/main/ts/report/html/app/viewer-commits.js +17 -216
- package/target/main/ts/report/html/app/viewer-controls.d.ts +43 -0
- package/target/main/ts/report/html/app/viewer-controls.js +141 -0
- package/target/main/ts/report/html/app/viewer-copy.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-copy.js +64 -0
- package/target/main/ts/report/html/app/viewer-data.d.ts +1 -1
- package/target/main/ts/report/html/app/viewer-data.js +2 -29
- package/target/main/ts/report/html/app/viewer-diagnostics.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-diagnostics.js +60 -0
- package/target/main/ts/report/html/app/viewer-dom.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-dom.js +99 -0
- package/target/main/ts/report/html/app/viewer-file-aside.d.ts +19 -0
- package/target/main/ts/report/html/app/viewer-file-aside.js +124 -0
- package/target/main/ts/report/html/app/viewer-file-figures.d.ts +15 -0
- package/target/main/ts/report/html/app/viewer-file-figures.js +60 -0
- package/target/main/ts/report/html/app/viewer-file-source.d.ts +7 -0
- package/target/main/ts/report/html/app/viewer-file-source.js +119 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +2 -118
- package/target/main/ts/report/html/app/viewer-files.js +24 -2184
- package/target/main/ts/report/html/app/viewer-filter.d.ts +3 -51
- package/target/main/ts/report/html/app/viewer-filter.js +111 -450
- package/target/main/ts/report/html/app/viewer-hotspots.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-hotspots.js +131 -0
- package/target/main/ts/report/html/app/viewer-inspection.d.ts +69 -0
- package/target/main/ts/report/html/app/viewer-inspection.js +36 -0
- package/target/main/ts/report/html/app/viewer-issue-group.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-issue-group.js +174 -0
- package/target/main/ts/report/html/app/viewer-issues.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-issues.js +173 -0
- package/target/main/ts/report/html/app/viewer-language-bar.d.ts +9 -0
- package/target/main/ts/report/html/app/viewer-language-bar.js +72 -0
- package/target/main/ts/report/html/app/viewer-languages.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-languages.js +93 -0
- package/target/main/ts/report/html/app/viewer-layout.d.ts +14 -0
- package/target/main/ts/report/html/app/viewer-layout.js +134 -0
- package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +47 -0
- package/target/main/ts/report/html/app/viewer-line-coverage.js +121 -0
- package/target/main/ts/report/html/app/viewer-locations.d.ts +16 -0
- package/target/main/ts/report/html/app/viewer-locations.js +31 -0
- package/target/main/ts/report/html/app/viewer-map-scale.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-map-scale.js +147 -0
- package/target/main/ts/report/html/app/viewer-map-shape.d.ts +42 -0
- package/target/main/ts/report/html/app/viewer-map-shape.js +102 -0
- package/target/main/ts/report/html/app/viewer-metric-format.d.ts +23 -0
- package/target/main/ts/report/html/app/viewer-metric-format.js +93 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -20
- package/target/main/ts/report/html/app/viewer-metric-registry.js +7 -84
- package/target/main/ts/report/html/app/viewer-metrics-view.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-metrics-view.js +162 -0
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +6 -1
- package/target/main/ts/report/html/app/viewer-metrics.js +53 -35
- package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-overview-cards.js +118 -0
- package/target/main/ts/report/html/app/viewer-overview-hotspots.d.ts +9 -0
- package/target/main/ts/report/html/app/viewer-overview-hotspots.js +173 -0
- package/target/main/ts/report/html/app/viewer-overview-lead.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-overview-lead.js +116 -0
- package/target/main/ts/report/html/app/viewer-profile-badges.d.ts +11 -0
- package/target/main/ts/report/html/app/viewer-profile-badges.js +119 -0
- package/target/main/ts/report/html/app/viewer-profile-table.d.ts +29 -0
- package/target/main/ts/report/html/app/viewer-profile-table.js +124 -0
- package/target/main/ts/report/html/app/viewer-profile.d.ts +2 -6
- package/target/main/ts/report/html/app/viewer-profile.js +6 -248
- package/target/main/ts/report/html/app/viewer-pull-sections.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-pull-sections.js +118 -0
- package/target/main/ts/report/html/app/viewer-pull-trend.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-pull-trend.js +63 -0
- package/target/main/ts/report/html/app/viewer-pulls.d.ts +0 -1
- package/target/main/ts/report/html/app/viewer-pulls.js +28 -178
- package/target/main/ts/report/html/app/viewer-query-field.d.ts +19 -0
- package/target/main/ts/report/html/app/viewer-query-field.js +203 -0
- package/target/main/ts/report/html/app/viewer-route.d.ts +34 -0
- package/target/main/ts/report/html/app/viewer-route.js +55 -0
- package/target/main/ts/report/html/app/viewer-shell.d.ts +20 -0
- package/target/main/ts/report/html/app/viewer-shell.js +116 -0
- package/target/main/ts/report/html/app/viewer-source-view.d.ts +49 -0
- package/target/main/ts/report/html/app/viewer-source-view.js +150 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +0 -84
- package/target/main/ts/report/html/app/viewer-source.js +7 -365
- package/target/main/ts/report/html/app/viewer-suggest.d.ts +13 -0
- package/target/main/ts/report/html/app/viewer-suggest.js +91 -0
- package/target/main/ts/report/html/app/viewer-sunburst.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-sunburst.js +40 -0
- package/target/main/ts/report/html/app/viewer-table-cells.d.ts +25 -0
- package/target/main/ts/report/html/app/viewer-table-cells.js +129 -0
- package/target/main/ts/report/html/app/viewer-table-rows.d.ts +54 -0
- package/target/main/ts/report/html/app/viewer-table-rows.js +95 -0
- package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +16 -0
- package/target/main/ts/report/html/app/viewer-tokenizer.js +192 -0
- package/target/main/ts/report/html/app/viewer-totals.d.ts +14 -0
- package/target/main/ts/report/html/app/viewer-totals.js +89 -0
- package/target/main/ts/report/html/app/viewer-treemap.d.ts +24 -0
- package/target/main/ts/report/html/app/viewer-treemap.js +112 -0
- package/target/main/ts/report/html/app/viewer-trend-data.d.ts +54 -0
- package/target/main/ts/report/html/app/viewer-trend-data.js +109 -0
- package/target/main/ts/report/html/app/viewer-trend-nav.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-trend-nav.js +85 -0
- package/target/main/ts/report/html/app/viewer-trend-points.d.ts +30 -0
- package/target/main/ts/report/html/app/viewer-trend-points.js +128 -0
- package/target/main/ts/report/html/app/viewer-trend-series.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-trend-series.js +98 -0
- package/target/main/ts/report/html/app/viewer-trends.d.ts +2 -70
- package/target/main/ts/report/html/app/viewer-trends.js +41 -392
- package/target/main/ts/report/html/app/viewer.js +152 -663
- package/target/main/ts/report/html/site/export-site.d.ts +3 -4
- package/target/main/ts/report/html/site/export-site.js +24 -41
- package/target/main/ts/report/html/site/exported-server.js +2 -1
- package/target/main/ts/report/html/site/local-server.d.ts +1 -1
- package/target/main/ts/report/html/site/local-server.js +13 -19
- package/target/main/ts/report/html/site/projects.js +8 -17
- package/target/main/ts/report/json/projections/commit-summary.d.ts +2 -2
- package/target/main/ts/report/json/projections/commit-summary.js +18 -19
- package/target/main/ts/report/json/projections/file-metrics.js +31 -24
- package/target/main/ts/report/json/projections/inspection-context.js +10 -1
- package/target/main/ts/report/json/projections/inspection-details.d.ts +1 -1
- package/target/main/ts/report/json/projections/inspection-details.js +2 -2
- package/target/main/ts/report/json/projections/metric-values.d.ts +1 -0
- package/target/main/ts/report/json/projections/metric-values.js +15 -5
- package/target/main/ts/report/json/store/local-store.js +2 -12
- package/target/main/ts/report/json/store/operation-cache.d.ts +8 -0
- package/target/main/ts/report/json/store/operation-cache.js +32 -0
- package/target/main/ts/report/json/store/pull-review-store.js +1 -2
- package/target/main/ts/report/json/store/replace-file.d.ts +1 -0
- package/target/main/ts/report/json/store/replace-file.js +14 -0
- package/target/main/ts/report/json/validation/report.d.ts +1 -1
- package/target/main/ts/report/json/validation/report.js +10 -8
- package/target/main/ts/report/json/validation/summary-validation.js +1 -3
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +2 -0
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +0 -5
- package/target/main/ts/report/json/wire/public-history-model.d.ts +0 -6
- package/target/main/ts/report/json/wire/public-history-model.js +0 -1
- package/target/main/ts/report.d.ts +3 -3
- package/target/main/ts/report.js +2 -2
- package/target/main/resources/report/json/inspection-context-v1.schema.json +0 -172
- package/target/main/resources/report/json/public-history-v1.schema.json +0 -50
- package/target/main/resources/report/json/quality-history-v1.schema.json +0 -51
- package/target/main/resources/report/json/report-v1.schema.json +0 -65
- package/target/main/resources/report/json/viewer-details-v1.schema.json +0 -346
- package/target/main/ts/report/json/projections/public-history.d.ts +0 -4
- package/target/main/ts/report/json/projections/public-history.js +0 -17
|
@@ -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
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Operation, Plugin, ProductDeclaration } from './plugin.js';
|
|
2
2
|
export type InputBinding = {
|
|
3
3
|
readonly external: string;
|
|
4
4
|
} | {
|
|
5
5
|
readonly operation: string;
|
|
6
6
|
};
|
|
7
7
|
export interface PlanRequest {
|
|
8
|
-
readonly plugins: readonly
|
|
8
|
+
readonly plugins: readonly Plugin[];
|
|
9
9
|
readonly select: readonly string[];
|
|
10
10
|
readonly inputs: ReadonlyMap<string, string>;
|
|
11
11
|
readonly bindings?: ReadonlyMap<string, Readonly<Record<string, InputBinding>>>;
|
|
12
|
-
/** Explicit migration exception for named v1 plugins that predate the manifest. */
|
|
13
|
-
readonly legacyPluginIds?: readonly string[];
|
|
14
12
|
}
|
|
15
13
|
export interface PlannedOperation {
|
|
16
14
|
readonly key: string;
|
|
@@ -18,5 +16,6 @@ export interface PlannedOperation {
|
|
|
18
16
|
readonly inputs: ReadonlyMap<string, InputBinding>;
|
|
19
17
|
readonly declaration?: ProductDeclaration;
|
|
20
18
|
readonly validateOutput?: (value: unknown) => boolean;
|
|
19
|
+
readonly cacheIdentity?: string;
|
|
21
20
|
}
|
|
22
21
|
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
|
|
6
|
+
const { operations, declarations, cacheIdentities } = indexOperations(request.plugins);
|
|
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);
|
|
@@ -59,10 +61,11 @@ function validateSchema(schema, key) {
|
|
|
59
61
|
throw new Error(`Invalid product schema for ${key}`, { cause: error });
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
|
-
function indexOperations(plugins
|
|
64
|
+
function indexOperations(plugins) {
|
|
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)
|
|
@@ -70,8 +73,15 @@ function indexOperations(plugins, legacyPlugins) {
|
|
|
70
73
|
if (ids.has(plugin.id) || !plugin.id || plugin.id.includes('/'))
|
|
71
74
|
throw new Error(`Invalid or duplicate plugin ID: ${plugin.id}`);
|
|
72
75
|
ids.add(plugin.id);
|
|
73
|
-
const products = manifestProducts(plugin
|
|
74
|
-
|
|
76
|
+
const products = manifestProducts(plugin);
|
|
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
|
+
}
|
|
84
|
+
for (const declaration of products.values()) {
|
|
75
85
|
for (const metric of declaration.metrics ?? []) {
|
|
76
86
|
const owner = metricOwners.get(metric.id);
|
|
77
87
|
if (owner !== undefined)
|
|
@@ -83,16 +93,23 @@ 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}`);
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
if (operation.scope !== undefined && operation.scope !== 'file' && operation.scope !== 'repository') {
|
|
97
|
+
throw new Error(`Invalid operation scope: ${key}`);
|
|
98
|
+
}
|
|
99
|
+
const declaration = products.get(operation.output.id);
|
|
100
|
+
if (!declaration)
|
|
101
|
+
throw new Error(`Undeclared output for ${key}: ${operation.output.id}`);
|
|
102
|
+
declarations.set(key, declaration);
|
|
103
|
+
if (declaration.persistence === 'cache') {
|
|
104
|
+
cacheIdentities.set(key, JSON.stringify([
|
|
105
|
+
plugin.api, plugin.version, Object.entries(plugin.tools ?? {}).sort(), plugin.settings, operation.scope, operation.implementation,
|
|
106
|
+
declaration.contract, declaration.schema,
|
|
107
|
+
]));
|
|
91
108
|
}
|
|
92
109
|
operations.set(key, operation);
|
|
93
110
|
}
|
|
94
111
|
}
|
|
95
|
-
return { operations, declarations };
|
|
112
|
+
return { operations, declarations, cacheIdentities };
|
|
96
113
|
}
|
|
97
114
|
function candidatesFor(contract, inputs, operations) {
|
|
98
115
|
const candidates = [];
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { MetricDescriptor } from '../model/metric-descriptor.js';
|
|
2
|
+
import type { ProvidedLanguage } from '../model/language.js';
|
|
3
|
+
import type { JsonValue } from '../model/plugin-data.js';
|
|
2
4
|
export type { MetricDescriptor, MetricScope } from '../model/metric-descriptor.js';
|
|
5
|
+
export { isRecord } from '../model/plugin-data.js';
|
|
3
6
|
export declare const pluginApi = "repometry.plugin/v1";
|
|
4
7
|
export interface DataContract<T = unknown> {
|
|
5
8
|
readonly id: string;
|
|
@@ -11,12 +14,16 @@ export interface Product {
|
|
|
11
14
|
}
|
|
12
15
|
export interface InspectionInputs {
|
|
13
16
|
read<T>(port: string, contract: DataContract<T>): T;
|
|
17
|
+
emitDiagnostic?(message: string): void;
|
|
14
18
|
}
|
|
15
19
|
export interface Operation {
|
|
16
20
|
readonly id: string;
|
|
17
21
|
readonly role: 'provider' | 'inspection';
|
|
22
|
+
readonly scope?: 'file' | 'repository';
|
|
18
23
|
readonly inputs: Readonly<Record<string, DataContract>>;
|
|
19
24
|
readonly output: DataContract;
|
|
25
|
+
/** Fingerprint for executable details that the declared versions and inputs do not carry. */
|
|
26
|
+
readonly implementation?: string;
|
|
20
27
|
execute(inputs: InspectionInputs): unknown | Promise<unknown>;
|
|
21
28
|
}
|
|
22
29
|
export interface RuleDescriptor {
|
|
@@ -53,9 +60,10 @@ export interface Plugin {
|
|
|
53
60
|
readonly operations: readonly Operation[];
|
|
54
61
|
readonly rules?: readonly RuleDescriptor[];
|
|
55
62
|
readonly config?: PluginConfigSchema;
|
|
63
|
+
/** Effective non-secret settings saved with inspection provenance. */
|
|
64
|
+
readonly settings?: JsonValue;
|
|
56
65
|
readonly kinds: readonly PluginKind[];
|
|
57
66
|
readonly claims?: FileClaims;
|
|
67
|
+
readonly providesLanguages?: readonly ProvidedLanguage[];
|
|
58
68
|
readonly produces: readonly ProductDeclaration[];
|
|
59
69
|
}
|
|
60
|
-
export type LegacyPlugin = Omit<Plugin, 'kinds' | 'claims' | 'produces'>;
|
|
61
|
-
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
@@ -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 (!
|
|
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 '
|
|
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
|
|
@@ -9,6 +9,7 @@ function isCount(value) {
|
|
|
9
9
|
}
|
|
10
10
|
export function isCloneSource(value) {
|
|
11
11
|
return isRecord(value) && typeof value.path === 'string' && Array.isArray(value.codeLines)
|
|
12
|
+
&& (value.scheme === undefined || typeof value.scheme === 'string' && value.scheme.length > 0)
|
|
12
13
|
&& value.codeLines.every((line, index, lines) => isCount(line) && line > (lines[index - 1] ?? 0))
|
|
13
14
|
&& Array.isArray(value.candidates) && value.candidates.every(isCandidate);
|
|
14
15
|
}
|
|
@@ -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,7 +25,11 @@ 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
|
}
|
|
30
33
|
export declare const codeStructure: DataContract<CodeStructure>;
|
|
34
|
+
/** A repository provider returns at most one structure per input path. */
|
|
35
|
+
export declare const codeStructures: DataContract<readonly CodeStructure[]>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { isRecord } from '
|
|
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,7 +27,15 @@ 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
|
};
|
|
35
|
+
/** A repository provider returns at most one structure per input path. */
|
|
36
|
+
export const codeStructures = {
|
|
37
|
+
id: 'repometry.code-structures/v1',
|
|
38
|
+
accepts: (value) => Array.isArray(value) && value.every(codeStructure.accepts)
|
|
39
|
+
&& new Set(value.map(({ path }) => path)).size === value.length,
|
|
40
|
+
};
|
|
32
41
|
//# sourceMappingURL=code-structure.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isRecord } from '
|
|
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 '
|
|
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'];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface LanguageDisplay {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
readonly label: string;
|
|
4
|
+
readonly color?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ProvidedLanguage extends LanguageDisplay {
|
|
7
|
+
readonly extensions?: readonly string[];
|
|
8
|
+
readonly globs?: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function isLanguageDisplay(value: unknown): value is LanguageDisplay;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { isRecord } from './plugin-data.js';
|
|
2
|
+
export function isLanguageDisplay(value) {
|
|
3
|
+
return isRecord(value) && typeof value.id === 'string' && /^[a-z][a-z0-9-]*$/.test(value.id)
|
|
4
|
+
&& typeof value.label === 'string' && value.label.trim().length > 0
|
|
5
|
+
&& (value.color === undefined || typeof value.color === 'string' && /^#[a-f\d]{6}$/i.test(value.color));
|
|
6
|
+
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { DataContract } from '../engine/plugin.js';
|
|
2
|
-
|
|
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>;
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import { isRecord } from '
|
|
1
|
+
import { isRecord } from './plugin-data.js';
|
|
2
|
+
import { isMergedLineRanges } from './source.js';
|
|
2
3
|
export const lcovLines = {
|
|
3
4
|
id: 'repometry.lcov-lines/v1',
|
|
4
|
-
accepts: (value) => isRecord(value) && Object.values(value).every(file => isRecord(file) &&
|
|
5
|
-
(file.partial === undefined ||
|
|
5
|
+
accepts: (value) => isRecord(value) && Object.values(value).every(file => isRecord(file) && isMergedLineRanges(file.covered) && isMergedLineRanges(file.uncovered)
|
|
6
|
+
&& (file.partial === undefined || isMergedLineRanges(file.partial)) && (file.hits === undefined || isMergedHits(file.hits))
|
|
7
|
+
&& (file.functionCalls === undefined || isOrderedCallCounts(file.functionCalls))
|
|
8
|
+
&& (file.functionBodies === undefined || isMergedLineRanges(file.functionBodies))),
|
|
6
9
|
};
|
|
7
|
-
function
|
|
10
|
+
function isOrderedCallCounts(value) {
|
|
8
11
|
if (!Array.isArray(value))
|
|
9
12
|
return false;
|
|
10
|
-
let previous =
|
|
11
|
-
for (const
|
|
12
|
-
if (!Array.isArray(
|
|
13
|
+
let previous = 1;
|
|
14
|
+
for (const call of value) {
|
|
15
|
+
if (!Array.isArray(call) || call.length !== 2)
|
|
13
16
|
return false;
|
|
14
|
-
const [
|
|
15
|
-
if (typeof
|
|
16
|
-
||
|
|
17
|
+
const [line, count] = call;
|
|
18
|
+
if (typeof line !== 'number' || typeof count !== 'number' || !Number.isSafeInteger(line) || !Number.isSafeInteger(count)
|
|
19
|
+
|| line < previous || count < 0)
|
|
17
20
|
return false;
|
|
18
|
-
previous =
|
|
21
|
+
previous = line;
|
|
19
22
|
}
|
|
20
23
|
return true;
|
|
21
24
|
}
|
|
@@ -2,7 +2,7 @@ import type { DataContract } from '../engine/plugin.js';
|
|
|
2
2
|
export declare const definitions: {
|
|
3
3
|
readonly lines: 'repometry.physical-lines/v1';
|
|
4
4
|
readonly functions: 'repometry.functions/v1';
|
|
5
|
-
readonly complexity: 'repometry.cyclomatic-
|
|
5
|
+
readonly complexity: 'repometry.cyclomatic-complexity/v1';
|
|
6
6
|
readonly coverage: 'repometry.lcov-line-coverage/v1';
|
|
7
7
|
readonly coveredLines: 'repometry.lcov-covered-lines/v1';
|
|
8
8
|
readonly coverableLines: 'repometry.lcov-coverable-lines/v1';
|
|
@@ -12,13 +12,14 @@ export declare const definitions: {
|
|
|
12
12
|
readonly functionCoverage: 'repometry.lcov-function-coverage/v1';
|
|
13
13
|
readonly coveredFunctions: 'repometry.lcov-covered-functions/v1';
|
|
14
14
|
readonly coverableFunctions: 'repometry.lcov-coverable-functions/v1';
|
|
15
|
-
readonly codeLines: 'repometry.code-lines
|
|
16
|
-
readonly comments: 'repometry.comment-lines
|
|
17
|
-
readonly classes: 'repometry.classes
|
|
18
|
-
readonly cognitiveComplexity: 'repometry.cognitive-
|
|
19
|
-
readonly duplicatedLines: 'repometry.duplicated-lines
|
|
15
|
+
readonly codeLines: 'repometry.code-lines/v1';
|
|
16
|
+
readonly comments: 'repometry.comment-lines/v1';
|
|
17
|
+
readonly classes: 'repometry.classes/v1';
|
|
18
|
+
readonly cognitiveComplexity: 'repometry.cognitive-complexity/v1';
|
|
19
|
+
readonly duplicatedLines: 'repometry.duplicated-lines/v1';
|
|
20
20
|
readonly churn: 'repometry.git-change-frequency/v1';
|
|
21
21
|
};
|
|
22
|
+
export declare function canonicalMetricId(id: string): string;
|
|
22
23
|
export interface Measurement {
|
|
23
24
|
readonly definition: string;
|
|
24
25
|
readonly target: 'repository' | 'file' | 'function';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { isRecord } from '
|
|
1
|
+
import { isRecord } from './plugin-data.js';
|
|
2
2
|
export const definitions = {
|
|
3
3
|
lines: 'repometry.physical-lines/v1',
|
|
4
4
|
functions: 'repometry.functions/v1',
|
|
5
|
-
complexity: 'repometry.cyclomatic-
|
|
5
|
+
complexity: 'repometry.cyclomatic-complexity/v1',
|
|
6
6
|
coverage: 'repometry.lcov-line-coverage/v1',
|
|
7
7
|
coveredLines: 'repometry.lcov-covered-lines/v1',
|
|
8
8
|
coverableLines: 'repometry.lcov-coverable-lines/v1',
|
|
@@ -12,13 +12,24 @@ export const definitions = {
|
|
|
12
12
|
functionCoverage: 'repometry.lcov-function-coverage/v1',
|
|
13
13
|
coveredFunctions: 'repometry.lcov-covered-functions/v1',
|
|
14
14
|
coverableFunctions: 'repometry.lcov-coverable-functions/v1',
|
|
15
|
-
codeLines: 'repometry.code-lines
|
|
16
|
-
comments: 'repometry.comment-lines
|
|
17
|
-
classes: 'repometry.classes
|
|
18
|
-
cognitiveComplexity: 'repometry.cognitive-
|
|
19
|
-
duplicatedLines: 'repometry.duplicated-lines
|
|
15
|
+
codeLines: 'repometry.code-lines/v1',
|
|
16
|
+
comments: 'repometry.comment-lines/v1',
|
|
17
|
+
classes: 'repometry.classes/v1',
|
|
18
|
+
cognitiveComplexity: 'repometry.cognitive-complexity/v1',
|
|
19
|
+
duplicatedLines: 'repometry.duplicated-lines/v1',
|
|
20
20
|
churn: 'repometry.git-change-frequency/v1',
|
|
21
21
|
};
|
|
22
|
+
const earlierMetricIds = new Map([
|
|
23
|
+
['repometry.cyclomatic-babel/v1', definitions.complexity],
|
|
24
|
+
['repometry.code-lines-babel/v1', definitions.codeLines],
|
|
25
|
+
['repometry.comment-lines-babel/v1', definitions.comments],
|
|
26
|
+
['repometry.classes-babel/v1', definitions.classes],
|
|
27
|
+
['repometry.cognitive-babel/v1', definitions.cognitiveComplexity],
|
|
28
|
+
['repometry.duplicated-lines-babel/v1', definitions.duplicatedLines],
|
|
29
|
+
]);
|
|
30
|
+
export function canonicalMetricId(id) {
|
|
31
|
+
return earlierMetricIds.get(id) ?? id;
|
|
32
|
+
}
|
|
22
33
|
function isMeasurement(value) {
|
|
23
34
|
return isRecord(value) && typeof value.definition === 'string'
|
|
24
35
|
&& (value.target === 'repository' || value.target === 'file' || value.target === 'function')
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { MetricDescriptor, PluginConfigSchema, RuleDescriptor } from '../engine/plugin.js';
|
|
2
2
|
import type { InventoryFile } from './source.js';
|
|
3
|
+
import type { LanguageDisplay } from './language.js';
|
|
3
4
|
export type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
|
|
4
5
|
readonly [key: string]: JsonValue;
|
|
5
6
|
};
|
|
7
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
8
|
+
export declare function isJsonValue(value: unknown, depth?: number): value is JsonValue;
|
|
6
9
|
export interface PersistedProduct {
|
|
7
10
|
readonly operation: string;
|
|
8
11
|
readonly path?: string;
|
|
@@ -18,8 +21,10 @@ export interface PluginData {
|
|
|
18
21
|
}[];
|
|
19
22
|
readonly products: Readonly<Record<string, readonly PersistedProduct[]>>;
|
|
20
23
|
readonly contracts?: Readonly<Record<string, PluginConfigSchema>>;
|
|
24
|
+
readonly languages?: readonly LanguageDisplay[];
|
|
21
25
|
readonly inventory?: readonly (InventoryFile & {
|
|
22
26
|
readonly language: string;
|
|
23
27
|
readonly analysed: boolean;
|
|
28
|
+
readonly provider?: string;
|
|
24
29
|
})[];
|
|
25
30
|
}
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export function isRecord(value) {
|
|
2
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
export function isJsonValue(value, depth = 0) {
|
|
5
|
+
if (depth > 512)
|
|
6
|
+
return false;
|
|
7
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'string')
|
|
8
|
+
return true;
|
|
9
|
+
if (typeof value === 'number')
|
|
10
|
+
return Number.isFinite(value);
|
|
11
|
+
if (Array.isArray(value))
|
|
12
|
+
return value.every(item => isJsonValue(item, depth + 1));
|
|
13
|
+
return isRecord(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)
|
|
14
|
+
&& Object.values(value).every(item => isJsonValue(item, depth + 1));
|
|
15
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isRecord } from '
|
|
2
|
-
import { definitions } from './measurement.js';
|
|
1
|
+
import { isRecord } from './plugin-data.js';
|
|
2
|
+
import { canonicalMetricId, definitions } from './measurement.js';
|
|
3
3
|
export const debtModel = { name: 'basic-cocomo-organic', scale: 2.4, exponent: 1.05, minutesPerPersonMonth: 9600 };
|
|
4
4
|
export function qualitySummary(report) {
|
|
5
5
|
const totals = new Map();
|
|
@@ -8,11 +8,12 @@ export function qualitySummary(report) {
|
|
|
8
8
|
for (const item of report.measurements) {
|
|
9
9
|
if (item.target !== 'file' || item.value === null || !Number.isSafeInteger(item.value) || item.value < 0)
|
|
10
10
|
continue;
|
|
11
|
-
|
|
11
|
+
const id = canonicalMetricId(item.definition);
|
|
12
|
+
if (id === definitions.codeLines)
|
|
12
13
|
codeMeasuredFiles++;
|
|
13
|
-
if (
|
|
14
|
+
if (id === definitions.duplicatedLines)
|
|
14
15
|
duplicationMeasuredFiles++;
|
|
15
|
-
totals.set(
|
|
16
|
+
totals.set(id, (totals.get(id) ?? 0) + item.value);
|
|
16
17
|
}
|
|
17
18
|
const codeLines = totals.get(definitions.codeLines) ?? null;
|
|
18
19
|
const duplicatedLines = totals.get(definitions.duplicatedLines) ?? null;
|
|
@@ -3,7 +3,6 @@ import type { Finding } from './finding.js';
|
|
|
3
3
|
import type { IgnoredFinding } from './ignore-rule.js';
|
|
4
4
|
import type { PluginData } from './plugin-data.js';
|
|
5
5
|
import type { Subject } from './source.js';
|
|
6
|
-
export declare const legacyReportSchema = "urn:repometry:schema:report:1";
|
|
7
6
|
export declare const reportSchema = "urn:repometry:schema:report:2";
|
|
8
7
|
export interface Diagnostic {
|
|
9
8
|
readonly operation: string;
|
|
@@ -12,7 +11,7 @@ export interface Diagnostic {
|
|
|
12
11
|
readonly path?: string;
|
|
13
12
|
}
|
|
14
13
|
export interface Report {
|
|
15
|
-
readonly schema: typeof reportSchema
|
|
14
|
+
readonly schema: typeof reportSchema;
|
|
16
15
|
readonly subject: Subject;
|
|
17
16
|
readonly generatedAt: string;
|
|
18
17
|
readonly committedAt?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isRecord } from '
|
|
1
|
+
import { isRecord } from './plugin-data.js';
|
|
2
2
|
import { findingCategories } from './finding.js';
|
|
3
3
|
/** Keep scanner identity in profile comparisons while dropping the per-snapshot inputs and counts. */
|
|
4
4
|
export function findingImportMethods(value) {
|
|
@@ -2,9 +2,8 @@ import type { DataContract } from '../engine/plugin.js';
|
|
|
2
2
|
import type { SourceFile, SourceSnapshot } from './source.js';
|
|
3
3
|
export type { Subject, SourceFile, SourceSnapshot } from './source.js';
|
|
4
4
|
export declare const sourceFile: DataContract<SourceFile>;
|
|
5
|
+
export declare const sourceFiles: DataContract<readonly SourceFile[]>;
|
|
5
6
|
export declare const sourceDirectoriesExcluded: readonly ['.git', '.repometry', 'node_modules', 'target'];
|
|
6
|
-
export declare const sourceExtensions: readonly ['.js', '.mjs', '.cjs', '.jsx', '.ts', '.mts', '.cts', '.tsx'];
|
|
7
|
-
export declare function isSourcePath(path: string): boolean;
|
|
8
7
|
export declare function isExcludedDirectory(name: string): boolean;
|
|
9
8
|
export declare function digest(bytes: Uint8Array | string): string;
|
|
10
9
|
export declare function utf8(bytes: Uint8Array): string;
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
-
import { isRecord } from '../engine/plugin.js';
|
|
2
|
+
import { isRecord } from './plugin-data.js';
|
|
4
3
|
export const sourceFile = {
|
|
5
4
|
id: 'repometry.source-file/v1',
|
|
6
5
|
accepts: (value) => isRecord(value) && typeof value.path === 'string' && value.bytes instanceof Uint8Array,
|
|
7
6
|
};
|
|
7
|
+
export const sourceFiles = {
|
|
8
|
+
id: 'repometry.source-files/v1',
|
|
9
|
+
accepts: (value) => Array.isArray(value) && value.every(sourceFile.accepts),
|
|
10
|
+
};
|
|
8
11
|
export const sourceDirectoriesExcluded = ['.git', '.repometry', 'node_modules', 'target'];
|
|
9
|
-
export const sourceExtensions = ['.js', '.mjs', '.cjs', '.jsx', '.ts', '.mts', '.cts', '.tsx'];
|
|
10
12
|
const excluded = new Set(sourceDirectoriesExcluded);
|
|
11
|
-
const extensions = new Set(sourceExtensions);
|
|
12
|
-
export function isSourcePath(path) {
|
|
13
|
-
return extensions.has(extname(path)) && !path.split('/').slice(0, -1).some(isExcludedDirectory);
|
|
14
|
-
}
|
|
15
13
|
export function isExcludedDirectory(name) {
|
|
16
14
|
return excluded.has(name);
|
|
17
15
|
}
|
|
@@ -9,6 +9,9 @@ export interface SourceFile {
|
|
|
9
9
|
readonly path: string;
|
|
10
10
|
readonly bytes: Uint8Array;
|
|
11
11
|
}
|
|
12
|
+
/** A 1-based inclusive range in source text. */
|
|
13
|
+
export type SourceLineRange = readonly [first: number, last: number];
|
|
14
|
+
export declare function isMergedLineRanges(value: unknown): value is readonly SourceLineRange[];
|
|
12
15
|
export declare const maxClaimedFileBytes: number;
|
|
13
16
|
export declare function isClaimedText(bytes: Uint8Array): boolean;
|
|
14
17
|
export interface InventoryFile {
|