repometry 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +27 -2
- package/package.json +63 -4
- package/target/main/resources/report/json/compact-json-v1.schema.json +24 -0
- package/target/main/resources/report/json/comparison-v1.schema.json +65 -0
- package/target/main/resources/report/json/config-v1.schema.json +34 -0
- package/target/main/resources/report/json/diff-coverage-v1.schema.json +55 -0
- package/target/main/resources/report/json/file-metrics-v1.schema.json +134 -0
- package/target/main/resources/report/json/inspection-context-v1.schema.json +172 -0
- package/target/main/resources/report/json/metabranch-v1.schema.json +9 -0
- package/target/main/resources/report/json/metric-catalog-v1.schema.json +31 -0
- package/target/main/resources/report/json/public-history-v1.schema.json +50 -0
- package/target/main/resources/report/json/pull-review-v1.schema.json +97 -0
- package/target/main/resources/report/json/quality-history-v1.schema.json +51 -0
- package/target/main/resources/report/json/report-v1.schema.json +65 -0
- package/target/main/resources/report/json/report-v2.schema.json +238 -0
- package/target/main/resources/report/json/repository-summary-v1.schema.json +181 -0
- package/target/main/resources/report/json/viewer-details-v1.schema.json +343 -0
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +13 -0
- package/target/main/resources/viewer/files.css +578 -0
- package/target/main/resources/viewer/index.html +130 -0
- package/target/main/resources/viewer/projects.html +52 -0
- package/target/main/resources/viewer/styles.css +586 -0
- package/target/main/resources/viewer/viewer-pulls.css +64 -0
- package/target/main/ts/api/gh/github-pr-comment.d.ts +4 -0
- package/target/main/ts/api/gh/github-pr-comment.js +107 -0
- package/target/main/ts/api/gh/github.d.ts +6 -0
- package/target/main/ts/api/gh/github.js +91 -0
- package/target/main/ts/api/git/blob-batch.d.ts +10 -0
- package/target/main/ts/api/git/blob-batch.js +105 -0
- package/target/main/ts/api/git/changes.d.ts +22 -0
- package/target/main/ts/api/git/changes.js +107 -0
- package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
- package/target/main/ts/api/git/commit-metadata.js +54 -0
- package/target/main/ts/api/git/git-churn.d.ts +9 -0
- package/target/main/ts/api/git/git-churn.js +70 -0
- package/target/main/ts/api/git/git-reader.d.ts +16 -0
- package/target/main/ts/api/git/git-reader.js +73 -0
- package/target/main/ts/api/git/git.d.ts +21 -0
- package/target/main/ts/api/git/git.js +152 -0
- package/target/main/ts/api/git/inspection-source.d.ts +15 -0
- package/target/main/ts/api/git/inspection-source.js +30 -0
- package/target/main/ts/api/git/local-sources.d.ts +5 -0
- package/target/main/ts/api/git/local-sources.js +46 -0
- package/target/main/ts/api/git/local.d.ts +3 -0
- package/target/main/ts/api/git/local.js +35 -0
- package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
- package/target/main/ts/api/git/metabranch-worktree.js +34 -0
- package/target/main/ts/api/git/source-cache.d.ts +3 -0
- package/target/main/ts/api/git/source-cache.js +56 -0
- package/target/main/ts/api/import/finding-import.d.ts +9 -0
- package/target/main/ts/api/import/finding-import.js +226 -0
- package/target/main/ts/api/import/lcov-files.d.ts +5 -0
- package/target/main/ts/api/import/lcov-files.js +13 -0
- package/target/main/ts/api/import/profile-file.d.ts +4 -0
- package/target/main/ts/api/import/profile-file.js +16 -0
- package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
- package/target/main/ts/api/worker/remote-executor.js +45 -0
- package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
- package/target/main/ts/api/worker/worker-protocol.js +101 -0
- package/target/main/ts/api/worker/worker.d.ts +5 -0
- package/target/main/ts/api/worker/worker.js +85 -0
- package/target/main/ts/cli/arguments.d.ts +28 -0
- package/target/main/ts/cli/arguments.js +110 -0
- package/target/main/ts/cli/config.d.ts +14 -0
- package/target/main/ts/cli/config.js +60 -0
- package/target/main/ts/cli/github-pr-comment.d.ts +1 -0
- package/target/main/ts/cli/github-pr-comment.js +12 -0
- package/target/main/ts/cli/imports.d.ts +7 -0
- package/target/main/ts/cli/imports.js +29 -0
- package/target/main/ts/cli/main.d.ts +2 -0
- package/target/main/ts/cli/main.js +378 -0
- package/target/main/ts/cli/reporting.d.ts +18 -0
- package/target/main/ts/cli/reporting.js +108 -0
- package/target/main/ts/cli/revisions.d.ts +6 -0
- package/target/main/ts/cli/revisions.js +15 -0
- package/target/main/ts/cli/store.d.ts +13 -0
- package/target/main/ts/cli/store.js +38 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
- package/target/main/ts/compose/analyze-snapshot.js +163 -0
- package/target/main/ts/compose/attach-churn.d.ts +2 -0
- package/target/main/ts/compose/attach-churn.js +37 -0
- package/target/main/ts/compose/diff-coverage.d.ts +20 -0
- package/target/main/ts/compose/diff-coverage.js +56 -0
- package/target/main/ts/compose/inspect.d.ts +23 -0
- package/target/main/ts/compose/inspect.js +44 -0
- package/target/main/ts/compose/plugin-list.d.ts +6 -0
- package/target/main/ts/compose/plugin-list.js +9 -0
- package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
- package/target/main/ts/compose/prepare-metabranch.js +16 -0
- package/target/main/ts/compose/review.d.ts +16 -0
- package/target/main/ts/compose/review.js +38 -0
- package/target/main/ts/compose/sources.d.ts +3 -0
- package/target/main/ts/compose/sources.js +29 -0
- package/target/main/ts/core/engine/execute.d.ts +10 -0
- package/target/main/ts/core/engine/execute.js +49 -0
- package/target/main/ts/core/engine/manifest.d.ts +4 -0
- package/target/main/ts/core/engine/manifest.js +104 -0
- package/target/main/ts/core/engine/plan.d.ts +22 -0
- package/target/main/ts/core/engine/plan.js +106 -0
- package/target/main/ts/core/engine/plugin.d.ts +59 -0
- package/target/main/ts/core/engine/plugin.js +4 -0
- package/target/main/ts/core/engine/report-products.d.ts +16 -0
- package/target/main/ts/core/engine/report-products.js +85 -0
- package/target/main/ts/core/model/changes.d.ts +8 -0
- package/target/main/ts/core/model/changes.js +1 -0
- package/target/main/ts/core/model/churn.d.ts +11 -0
- package/target/main/ts/core/model/churn.js +5 -0
- package/target/main/ts/core/model/clone-source.d.ts +16 -0
- package/target/main/ts/core/model/clone-source.js +14 -0
- package/target/main/ts/core/model/code-structure.d.ts +30 -0
- package/target/main/ts/core/model/code-structure.js +31 -0
- package/target/main/ts/core/model/comparison.d.ts +24 -0
- package/target/main/ts/core/model/comparison.js +1 -0
- package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
- package/target/main/ts/core/model/diff-coverage.js +1 -0
- package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
- package/target/main/ts/core/model/finding-ignore.js +35 -0
- package/target/main/ts/core/model/finding.d.ts +28 -0
- package/target/main/ts/core/model/finding.js +29 -0
- package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
- package/target/main/ts/core/model/ignore-rule.js +1 -0
- package/target/main/ts/core/model/measurement.d.ts +27 -0
- package/target/main/ts/core/model/measurement.js +24 -0
- package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
- package/target/main/ts/core/model/metric-descriptor.js +1 -0
- package/target/main/ts/core/model/plugin-data.d.ts +25 -0
- package/target/main/ts/core/model/plugin-data.js +1 -0
- package/target/main/ts/core/model/pull-review.d.ts +48 -0
- package/target/main/ts/core/model/pull-review.js +1 -0
- package/target/main/ts/core/model/quality-summary.d.ts +42 -0
- package/target/main/ts/core/model/quality-summary.js +64 -0
- package/target/main/ts/core/model/report.d.ts +32 -0
- package/target/main/ts/core/model/report.js +5 -0
- package/target/main/ts/core/model/scanner-import.d.ts +39 -0
- package/target/main/ts/core/model/scanner-import.js +28 -0
- package/target/main/ts/core/model/snapshot.d.ts +15 -0
- package/target/main/ts/core/model/snapshot.js +50 -0
- package/target/main/ts/core/model/source-locator.d.ts +7 -0
- package/target/main/ts/core/model/source-locator.js +1 -0
- package/target/main/ts/core/model/source.d.ts +23 -0
- package/target/main/ts/core/model/source.js +1 -0
- package/target/main/ts/core/ports/report.d.ts +9 -0
- package/target/main/ts/core/ports/report.js +1 -0
- package/target/main/ts/core/ports/source-provider.d.ts +14 -0
- package/target/main/ts/core/ports/source-provider.js +4 -0
- package/target/main/ts/core/profile/exclusions.d.ts +11 -0
- package/target/main/ts/core/profile/exclusions.js +57 -0
- package/target/main/ts/core/profile/maintainability.d.ts +31 -0
- package/target/main/ts/core/profile/maintainability.js +9 -0
- package/target/main/ts/core/profile/profile.d.ts +4 -0
- package/target/main/ts/core/profile/profile.js +10 -0
- package/target/main/ts/core/usecases/compare.d.ts +6 -0
- package/target/main/ts/core/usecases/compare.js +145 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.js +10 -0
- package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
- package/target/main/ts/core/usecases/diff-coverage.js +15 -0
- package/target/main/ts/core/usecases/inspect.d.ts +38 -0
- package/target/main/ts/core/usecases/inspect.js +41 -0
- package/target/main/ts/core/usecases/review.d.ts +31 -0
- package/target/main/ts/core/usecases/review.js +128 -0
- package/target/main/ts/index.d.ts +35 -0
- package/target/main/ts/index.js +17 -0
- package/target/main/ts/plugin.d.ts +14 -0
- package/target/main/ts/plugin.js +5 -0
- package/target/main/ts/plugins/coverage/coverage.d.ts +23 -0
- package/target/main/ts/plugins/coverage/coverage.js +120 -0
- package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
- package/target/main/ts/plugins/coverage/diff-coverage.js +89 -0
- package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
- package/target/main/ts/plugins/duplication/duplication.js +93 -0
- package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
- package/target/main/ts/plugins/language-js/babel-provider.js +46 -0
- package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
- package/target/main/ts/plugins/language-js/clone-candidates.js +64 -0
- package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
- package/target/main/ts/plugins/language-js/code-lines.js +35 -0
- package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
- package/target/main/ts/plugins/language-js/function-facts.js +60 -0
- package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
- package/target/main/ts/plugins/language-js/structural-observations.js +79 -0
- package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
- package/target/main/ts/plugins/maintainability/maintainability.js +42 -0
- package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
- package/target/main/ts/plugins/maintainability/structural-smells.js +15 -0
- package/target/main/ts/plugins/source/forges.d.ts +4 -0
- package/target/main/ts/plugins/source/forges.js +79 -0
- package/target/main/ts/plugins/structure/structure.d.ts +2 -0
- package/target/main/ts/plugins/structure/structure.js +37 -0
- package/target/main/ts/report/html/app/viewer-access.d.ts +19 -0
- package/target/main/ts/report/html/app/viewer-access.js +25 -0
- package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
- package/target/main/ts/report/html/app/viewer-chart.js +711 -0
- package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
- package/target/main/ts/report/html/app/viewer-commits.js +280 -0
- package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
- package/target/main/ts/report/html/app/viewer-data.js +105 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
- package/target/main/ts/report/html/app/viewer-files.js +2087 -0
- package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
- package/target/main/ts/report/html/app/viewer-filter.js +492 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +68 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.js +206 -0
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
- package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
- package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-profile.js +401 -0
- package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer-projects.js +90 -0
- package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
- package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
- package/target/main/ts/report/html/app/viewer-source.js +313 -0
- package/target/main/ts/report/html/app/viewer-trends.d.ts +74 -0
- package/target/main/ts/report/html/app/viewer-trends.js +413 -0
- package/target/main/ts/report/html/app/viewer.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer.js +794 -0
- package/target/main/ts/report/html/site/badges.d.ts +14 -0
- package/target/main/ts/report/html/site/badges.js +39 -0
- package/target/main/ts/report/html/site/export-site.d.ts +21 -0
- package/target/main/ts/report/html/site/export-site.js +157 -0
- package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
- package/target/main/ts/report/html/site/exported-server.js +70 -0
- package/target/main/ts/report/html/site/local-server.d.ts +7 -0
- package/target/main/ts/report/html/site/local-server.js +64 -0
- package/target/main/ts/report/html/site/projects.d.ts +3 -0
- package/target/main/ts/report/html/site/projects.js +79 -0
- package/target/main/ts/report/html/site/server.d.ts +4 -0
- package/target/main/ts/report/html/site/server.js +64 -0
- package/target/main/ts/report/html/site/source-route.d.ts +6 -0
- package/target/main/ts/report/html/site/source-route.js +22 -0
- package/target/main/ts/report/json/projections/commit-summary.d.ts +11 -0
- package/target/main/ts/report/json/projections/commit-summary.js +118 -0
- package/target/main/ts/report/json/projections/components.d.ts +4 -0
- package/target/main/ts/report/json/projections/components.js +29 -0
- package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
- package/target/main/ts/report/json/projections/file-metrics.js +243 -0
- package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
- package/target/main/ts/report/json/projections/inspection-context.js +92 -0
- package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
- package/target/main/ts/report/json/projections/inspection-details.js +69 -0
- package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
- package/target/main/ts/report/json/projections/metric-values.js +57 -0
- package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
- package/target/main/ts/report/json/projections/public-history.js +16 -0
- package/target/main/ts/report/json/store/components.d.ts +2 -0
- package/target/main/ts/report/json/store/components.js +31 -0
- package/target/main/ts/report/json/store/local-store.d.ts +13 -0
- package/target/main/ts/report/json/store/local-store.js +179 -0
- package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
- package/target/main/ts/report/json/store/pull-review-store.js +51 -0
- package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
- package/target/main/ts/report/json/validation/metabranch.js +7 -0
- package/target/main/ts/report/json/validation/report.d.ts +15 -0
- package/target/main/ts/report/json/validation/report.js +64 -0
- package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
- package/target/main/ts/report/json/validation/summary-validation.js +27 -0
- package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
- package/target/main/ts/report/json/wire/compact-json.js +76 -0
- package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
- package/target/main/ts/report/json/wire/component-model.js +1 -0
- package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
- package/target/main/ts/report/json/wire/domain-types.js +1 -0
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
- package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
- package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
- package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
- package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/project-model.js +1 -0
- package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
- package/target/main/ts/report/json/wire/public-history-model.js +6 -0
- package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
- package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
- package/target/main/ts/report/json/wire/summary-model.js +1 -0
- package/target/main/ts/report.d.ts +11 -0
- package/target/main/ts/report.js +5 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { isRecord } from './plugin.js';
|
|
2
|
+
import { definitions } from '../model/measurement.js';
|
|
3
|
+
const kinds = new Set(['language', 'analysis', 'coverage', 'security', 'import', 'source']);
|
|
4
|
+
const persistence = new Set(['report', 'cache', 'transient']);
|
|
5
|
+
const units = new Set(['count', 'ratio', 'minutes']);
|
|
6
|
+
const scopes = new Set(['repository', 'file', 'function']);
|
|
7
|
+
const aggregates = new Set(['sum', 'max', 'none']);
|
|
8
|
+
const directions = new Set(['lower', 'higher', 'none']);
|
|
9
|
+
const coreMetrics = new Set(Object.values(definitions));
|
|
10
|
+
const coreProducts = new Set([
|
|
11
|
+
'repometry.measurements/v1', 'repometry.findings-and-measurements/v1',
|
|
12
|
+
'repometry.maintainability-file/v1', 'repometry.coverage-result/v1',
|
|
13
|
+
'repometry.source-locator/v1',
|
|
14
|
+
]);
|
|
15
|
+
export function isCoreReportProduct(contract) {
|
|
16
|
+
return coreProducts.has(contract);
|
|
17
|
+
}
|
|
18
|
+
export function manifestProducts(plugin, allowLegacy) {
|
|
19
|
+
const { id, kinds: declaredKinds, claims, produces, rules, config } = plugin;
|
|
20
|
+
if (declaredKinds === undefined && claims === undefined && produces === undefined) {
|
|
21
|
+
if (allowLegacy)
|
|
22
|
+
return undefined;
|
|
23
|
+
throw new Error(`Missing plugin manifest for ${id}. Declare kinds and produces.`);
|
|
24
|
+
}
|
|
25
|
+
if (Object.hasOwn(plugin, 'languages'))
|
|
26
|
+
throw new Error(`Plugin ${id} must declare languages in claims.languages`);
|
|
27
|
+
if (!strings(declaredKinds) || declaredKinds.length === 0 || declaredKinds.some(kind => !kinds.has(kind))) {
|
|
28
|
+
throw new Error(`Invalid kinds for plugin ${id}`);
|
|
29
|
+
}
|
|
30
|
+
if (claims !== undefined && (!isRecord(claims) || Object.entries(claims).some(([key, values]) => !['extensions', 'globs', 'languages'].includes(key) || !strings(values)
|
|
31
|
+
|| (key === 'extensions' && values.some(extension => !/^\.[\w-]+$/.test(extension)))))) {
|
|
32
|
+
throw new Error(`Invalid file claims for plugin ${id}`);
|
|
33
|
+
}
|
|
34
|
+
if (!Array.isArray(produces))
|
|
35
|
+
throw new Error(`Plugin ${id} must declare its products`);
|
|
36
|
+
if (rules !== undefined && (!Array.isArray(rules) || !rules.every(isRuleDescriptor)
|
|
37
|
+
|| new Set(rules.map(rule => rule.id)).size !== rules.length))
|
|
38
|
+
throw new Error(`Invalid or duplicate rules for plugin ${id}`);
|
|
39
|
+
if (config !== undefined && typeof config !== 'boolean' && !isRecord(config))
|
|
40
|
+
throw new Error(`Invalid configuration schema for plugin ${id}`);
|
|
41
|
+
const products = new Map();
|
|
42
|
+
const catalog = new Map();
|
|
43
|
+
for (const product of produces) {
|
|
44
|
+
if (!isRecord(product) || !text(product.contract) || !text(product.persistence) || !persistence.has(product.persistence)
|
|
45
|
+
|| products.has(product.contract))
|
|
46
|
+
throw new Error(`Invalid or duplicate product for plugin ${id}`);
|
|
47
|
+
const { contract, schema, metrics } = product;
|
|
48
|
+
if ((schema === undefined && product.persistence !== 'transient' && !isCoreReportProduct(contract))
|
|
49
|
+
|| (schema !== undefined && typeof schema !== 'boolean' && !isRecord(schema))) {
|
|
50
|
+
throw new Error(`Missing or invalid product schema for ${contract} in plugin ${id}`);
|
|
51
|
+
}
|
|
52
|
+
if (metrics !== undefined && (!Array.isArray(metrics) || !metrics.every(isMetricDescriptor))) {
|
|
53
|
+
throw new Error(`Invalid metric descriptors for ${contract} in plugin ${id}`);
|
|
54
|
+
}
|
|
55
|
+
const declaration = product;
|
|
56
|
+
for (const metric of declaration.metrics ?? []) {
|
|
57
|
+
if (catalog.has(metric.id))
|
|
58
|
+
throw new Error(`Duplicate metric ${metric.id} in plugin ${id}`);
|
|
59
|
+
catalog.set(metric.id, metric);
|
|
60
|
+
}
|
|
61
|
+
products.set(contract, declaration);
|
|
62
|
+
}
|
|
63
|
+
for (const rule of rules ?? []) {
|
|
64
|
+
if (rule.measure !== undefined && !catalog.has(rule.measure)) {
|
|
65
|
+
throw new Error(`Rule ${rule.id} in plugin ${id} references undeclared metric ${rule.measure}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
for (const metric of catalog.values()) {
|
|
69
|
+
if (!metric.ratio)
|
|
70
|
+
continue;
|
|
71
|
+
for (const component of [metric.ratio.of, metric.ratio.over]) {
|
|
72
|
+
if (component === metric.id || (!catalog.has(component) && !coreMetrics.has(component))) {
|
|
73
|
+
throw new Error(`Ratio ${metric.id} in plugin ${id} references invalid component ${component}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return products;
|
|
78
|
+
}
|
|
79
|
+
function isRuleDescriptor(value) {
|
|
80
|
+
return isRecord(value) && text(value.id) && text(value.category) && optionalText(value.description)
|
|
81
|
+
&& optionalText(value.measure) && (value.per === undefined || (Array.isArray(value.per) && value.per.length === 2 && value.per.every(text)))
|
|
82
|
+
&& (value.defaults === undefined || (isRecord(value.defaults)
|
|
83
|
+
&& Object.entries(value.defaults).every(([key, amount]) => (key === 'limit' || key === 'cost')
|
|
84
|
+
&& (amount === undefined || (typeof amount === 'number' && Number.isFinite(amount) && amount >= 0)))));
|
|
85
|
+
}
|
|
86
|
+
export function isMetricDescriptor(value) {
|
|
87
|
+
return isRecord(value) && text(value.id) && text(value.label)
|
|
88
|
+
&& text(value.unit) && units.has(value.unit) && text(value.scope) && scopes.has(value.scope)
|
|
89
|
+
&& text(value.aggregate) && aggregates.has(value.aggregate) && text(value.better) && directions.has(value.better)
|
|
90
|
+
&& optionalText(value.short) && optionalText(value.description) && optionalText(value.group)
|
|
91
|
+
&& (value.ratio === undefined || (value.unit === 'ratio' && isRecord(value.ratio) && text(value.ratio.of) && text(value.ratio.over)))
|
|
92
|
+
&& (value.bands === undefined || (Array.isArray(value.bands) && value.bands.length === 4
|
|
93
|
+
&& value.bands.every((limit, index, array) => typeof limit === 'number' && Number.isFinite(limit)
|
|
94
|
+
&& (index === 0 || limit > array[index - 1]))));
|
|
95
|
+
}
|
|
96
|
+
function strings(value) {
|
|
97
|
+
return Array.isArray(value) && value.every(text) && new Set(value).size === value.length;
|
|
98
|
+
}
|
|
99
|
+
function text(value) {
|
|
100
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
101
|
+
}
|
|
102
|
+
function optionalText(value) {
|
|
103
|
+
return value === undefined || text(value);
|
|
104
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { LegacyPlugin, Operation, Plugin, ProductDeclaration } from './plugin.js';
|
|
2
|
+
export type InputBinding = {
|
|
3
|
+
readonly external: string;
|
|
4
|
+
} | {
|
|
5
|
+
readonly operation: string;
|
|
6
|
+
};
|
|
7
|
+
export interface PlanRequest {
|
|
8
|
+
readonly plugins: readonly (Plugin | LegacyPlugin)[];
|
|
9
|
+
readonly select: readonly string[];
|
|
10
|
+
readonly inputs: ReadonlyMap<string, string>;
|
|
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
|
+
}
|
|
15
|
+
export interface PlannedOperation {
|
|
16
|
+
readonly key: string;
|
|
17
|
+
readonly operation: Operation;
|
|
18
|
+
readonly inputs: ReadonlyMap<string, InputBinding>;
|
|
19
|
+
readonly declaration?: ProductDeclaration;
|
|
20
|
+
readonly validateOutput?: (value: unknown) => boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function plan(request: PlanRequest): readonly PlannedOperation[];
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
2
|
+
import { pluginApi } from './plugin.js';
|
|
3
|
+
import { manifestProducts } from './manifest.js';
|
|
4
|
+
export function plan(request) {
|
|
5
|
+
const { operations, declarations } = indexOperations(request.plugins, new Set(request.legacyPluginIds));
|
|
6
|
+
const resolved = new Map();
|
|
7
|
+
const path = [];
|
|
8
|
+
function visit(key) {
|
|
9
|
+
const cycle = path.indexOf(key);
|
|
10
|
+
if (cycle >= 0)
|
|
11
|
+
throw new Error(`Plugin dependency cycle: ${[...path.slice(cycle), key].join(' -> ')}`);
|
|
12
|
+
if (resolved.has(key))
|
|
13
|
+
return;
|
|
14
|
+
const operation = operations.get(key);
|
|
15
|
+
if (!operation)
|
|
16
|
+
throw new Error(`Unknown operation: ${key}`);
|
|
17
|
+
path.push(key);
|
|
18
|
+
const inputs = new Map();
|
|
19
|
+
const declared = request.bindings?.get(key);
|
|
20
|
+
for (const name of Object.keys(declared ?? {})) {
|
|
21
|
+
if (!Object.hasOwn(operation.inputs, name))
|
|
22
|
+
throw new Error(`Unknown input port: ${key}.${name}`);
|
|
23
|
+
}
|
|
24
|
+
for (const [name, contract] of Object.entries(operation.inputs)) {
|
|
25
|
+
const explicit = declared && Object.hasOwn(declared, name) ? declared[name] : undefined;
|
|
26
|
+
const candidates = explicit ? [explicit] : candidatesFor(contract.id, request.inputs, operations);
|
|
27
|
+
const binding = candidates[0];
|
|
28
|
+
if (!binding)
|
|
29
|
+
throw new Error(`Missing input ${key}.${name} (${contract.id})`);
|
|
30
|
+
if (candidates.length > 1)
|
|
31
|
+
throw new Error(`Ambiguous input ${key}.${name} (${contract.id})`);
|
|
32
|
+
if (('external' in binding) === ('operation' in binding)) {
|
|
33
|
+
throw new Error(`Expected one binding for ${key}.${name}`);
|
|
34
|
+
}
|
|
35
|
+
const actual = 'external' in binding
|
|
36
|
+
? request.inputs.get(binding.external)
|
|
37
|
+
: operations.get(binding.operation)?.output.id;
|
|
38
|
+
if (actual !== contract.id)
|
|
39
|
+
throw new Error(`Incompatible input ${key}.${name}: expected ${contract.id}, got ${actual ?? 'missing'}`);
|
|
40
|
+
if ('operation' in binding)
|
|
41
|
+
visit(binding.operation);
|
|
42
|
+
inputs.set(name, binding);
|
|
43
|
+
}
|
|
44
|
+
path.pop();
|
|
45
|
+
const declaration = declarations.get(key);
|
|
46
|
+
const validateOutput = declaration?.schema === undefined ? undefined : validateSchema(declaration.schema, key);
|
|
47
|
+
resolved.set(key, { key, operation, inputs, ...(declaration === undefined ? {} : { declaration }),
|
|
48
|
+
...(validateOutput === undefined ? {} : { validateOutput }) });
|
|
49
|
+
}
|
|
50
|
+
for (const key of request.select)
|
|
51
|
+
visit(key);
|
|
52
|
+
return [...resolved.values()];
|
|
53
|
+
}
|
|
54
|
+
function validateSchema(schema, key) {
|
|
55
|
+
try {
|
|
56
|
+
return new Ajv2020().compile(schema);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
throw new Error(`Invalid product schema for ${key}`, { cause: error });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function indexOperations(plugins, legacyPlugins) {
|
|
63
|
+
const ids = new Set();
|
|
64
|
+
const operations = new Map();
|
|
65
|
+
const declarations = new Map();
|
|
66
|
+
const metricOwners = new Map();
|
|
67
|
+
for (const plugin of plugins) {
|
|
68
|
+
if (plugin.api !== pluginApi)
|
|
69
|
+
throw new Error(`Unsupported plugin API for ${plugin.id}: ${plugin.api}`);
|
|
70
|
+
if (ids.has(plugin.id) || !plugin.id || plugin.id.includes('/'))
|
|
71
|
+
throw new Error(`Invalid or duplicate plugin ID: ${plugin.id}`);
|
|
72
|
+
ids.add(plugin.id);
|
|
73
|
+
const products = manifestProducts(plugin, legacyPlugins.has(plugin.id));
|
|
74
|
+
for (const declaration of products?.values() ?? []) {
|
|
75
|
+
for (const metric of declaration.metrics ?? []) {
|
|
76
|
+
const owner = metricOwners.get(metric.id);
|
|
77
|
+
if (owner !== undefined)
|
|
78
|
+
throw new Error(`Duplicate metric ${metric.id} in plugins ${owner} and ${plugin.id}`);
|
|
79
|
+
metricOwners.set(metric.id, plugin.id);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
for (const operation of plugin.operations) {
|
|
83
|
+
const key = `${plugin.id}/${operation.id}`;
|
|
84
|
+
if (operations.has(key) || !operation.id || operation.id.includes('/'))
|
|
85
|
+
throw new Error(`Invalid or duplicate operation: ${key}`);
|
|
86
|
+
if (products !== undefined) {
|
|
87
|
+
const declaration = products.get(operation.output.id);
|
|
88
|
+
if (!declaration)
|
|
89
|
+
throw new Error(`Undeclared output for ${key}: ${operation.output.id}`);
|
|
90
|
+
declarations.set(key, declaration);
|
|
91
|
+
}
|
|
92
|
+
operations.set(key, operation);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { operations, declarations };
|
|
96
|
+
}
|
|
97
|
+
function candidatesFor(contract, inputs, operations) {
|
|
98
|
+
const candidates = [];
|
|
99
|
+
for (const [external, id] of inputs)
|
|
100
|
+
if (id === contract)
|
|
101
|
+
candidates.push({ external });
|
|
102
|
+
for (const [operation, candidate] of operations)
|
|
103
|
+
if (candidate.output.id === contract)
|
|
104
|
+
candidates.push({ operation });
|
|
105
|
+
return candidates;
|
|
106
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { MetricDescriptor } from '../model/metric-descriptor.js';
|
|
2
|
+
export type { MetricDescriptor, MetricScope } from '../model/metric-descriptor.js';
|
|
3
|
+
export declare const pluginApi = "repometry.plugin/v1";
|
|
4
|
+
export interface DataContract<T = unknown> {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly accepts: (value: unknown) => value is T;
|
|
7
|
+
}
|
|
8
|
+
export interface Product {
|
|
9
|
+
readonly contract: string;
|
|
10
|
+
readonly value: unknown;
|
|
11
|
+
}
|
|
12
|
+
export interface InspectionInputs {
|
|
13
|
+
read<T>(port: string, contract: DataContract<T>): T;
|
|
14
|
+
}
|
|
15
|
+
export interface Operation {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
readonly role: 'provider' | 'inspection';
|
|
18
|
+
readonly inputs: Readonly<Record<string, DataContract>>;
|
|
19
|
+
readonly output: DataContract;
|
|
20
|
+
execute(inputs: InspectionInputs): unknown | Promise<unknown>;
|
|
21
|
+
}
|
|
22
|
+
export interface RuleDescriptor {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly category: string;
|
|
25
|
+
readonly description?: string;
|
|
26
|
+
readonly defaults?: {
|
|
27
|
+
readonly limit?: number;
|
|
28
|
+
readonly cost?: number;
|
|
29
|
+
};
|
|
30
|
+
readonly measure?: string;
|
|
31
|
+
readonly per?: readonly [singular: string, plural: string];
|
|
32
|
+
}
|
|
33
|
+
export type PluginConfigSchema = boolean | Readonly<Record<string, unknown>>;
|
|
34
|
+
export type PluginKind = 'language' | 'analysis' | 'coverage' | 'security' | 'import' | 'source';
|
|
35
|
+
export interface FileClaims {
|
|
36
|
+
readonly extensions?: readonly string[];
|
|
37
|
+
readonly globs?: readonly string[];
|
|
38
|
+
readonly languages?: readonly string[];
|
|
39
|
+
}
|
|
40
|
+
export interface ProductDeclaration {
|
|
41
|
+
readonly contract: string;
|
|
42
|
+
readonly persistence: 'report' | 'cache' | 'transient';
|
|
43
|
+
readonly schema?: PluginConfigSchema;
|
|
44
|
+
readonly metrics?: readonly MetricDescriptor[];
|
|
45
|
+
}
|
|
46
|
+
export interface Plugin {
|
|
47
|
+
readonly id: string;
|
|
48
|
+
readonly version: string;
|
|
49
|
+
readonly api: string;
|
|
50
|
+
readonly tools?: Readonly<Record<string, string>>;
|
|
51
|
+
readonly operations: readonly Operation[];
|
|
52
|
+
readonly rules?: readonly RuleDescriptor[];
|
|
53
|
+
readonly config?: PluginConfigSchema;
|
|
54
|
+
readonly kinds: readonly PluginKind[];
|
|
55
|
+
readonly claims?: FileClaims;
|
|
56
|
+
readonly produces: readonly ProductDeclaration[];
|
|
57
|
+
}
|
|
58
|
+
export type LegacyPlugin = Omit<Plugin, 'kinds' | 'claims' | 'produces'>;
|
|
59
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FindingResult } from '../model/finding.js';
|
|
2
|
+
import type { PluginData } from '../model/plugin-data.js';
|
|
3
|
+
import type { Plugin, Product } from './plugin.js';
|
|
4
|
+
import type { PlannedOperation } from './plan.js';
|
|
5
|
+
export declare class ReportProducts {
|
|
6
|
+
private readonly metrics;
|
|
7
|
+
private readonly measured;
|
|
8
|
+
private readonly privateMetrics;
|
|
9
|
+
private readonly products;
|
|
10
|
+
private readonly contracts;
|
|
11
|
+
private readonly rules;
|
|
12
|
+
private readonly declared;
|
|
13
|
+
constructor(plugins: readonly Plugin[]);
|
|
14
|
+
record(task: PlannedOperation, { contract, value }: Product, path?: string): FindingResult | undefined;
|
|
15
|
+
result(): PluginData | undefined;
|
|
16
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { findingResult } from '../model/finding.js';
|
|
3
|
+
import { measurements } from '../model/measurement.js';
|
|
4
|
+
import { isRecord } from './plugin.js';
|
|
5
|
+
import { isCoreReportProduct } from './manifest.js';
|
|
6
|
+
export class ReportProducts {
|
|
7
|
+
metrics = new Map();
|
|
8
|
+
measured = new Set();
|
|
9
|
+
privateMetrics = new Set();
|
|
10
|
+
products = new Map();
|
|
11
|
+
contracts = new Map();
|
|
12
|
+
rules;
|
|
13
|
+
declared;
|
|
14
|
+
constructor(plugins) {
|
|
15
|
+
this.declared = plugins.some(plugin => plugin.produces !== undefined);
|
|
16
|
+
this.rules = plugins.flatMap(({ id, rules }) => rules?.length ? [{ plugin: id, rules }] : []);
|
|
17
|
+
for (const plugin of plugins) {
|
|
18
|
+
for (const product of plugin.produces ?? []) {
|
|
19
|
+
if (product.persistence !== 'report')
|
|
20
|
+
continue;
|
|
21
|
+
if (product.schema !== undefined) {
|
|
22
|
+
const previous = this.contracts.get(product.contract);
|
|
23
|
+
if (previous !== undefined && !isDeepStrictEqual(previous, product.schema)) {
|
|
24
|
+
throw new Error(`Conflicting product schemas: ${product.contract}`);
|
|
25
|
+
}
|
|
26
|
+
this.contracts.set(product.contract, product.schema);
|
|
27
|
+
}
|
|
28
|
+
for (const metric of product.metrics ?? []) {
|
|
29
|
+
const existing = this.metrics.get(metric.id);
|
|
30
|
+
if (existing && !isDeepStrictEqual(existing, metric))
|
|
31
|
+
throw new Error(`Conflicting metric declaration: ${metric.id}`);
|
|
32
|
+
this.metrics.set(metric.id, metric);
|
|
33
|
+
if (plugin.kinds?.includes('security'))
|
|
34
|
+
this.privateMetrics.add(metric.id);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
record(task, { contract, value }, path) {
|
|
40
|
+
if (task.declaration?.persistence !== 'report')
|
|
41
|
+
return undefined;
|
|
42
|
+
const rows = measurements.accepts(value) ? { measurements: value, findings: [] }
|
|
43
|
+
: findingResult.accepts(value) ? value
|
|
44
|
+
: isRecord(value) && measurements.accepts(value.measurements) ? { measurements: value.measurements, findings: [] } : undefined;
|
|
45
|
+
if (rows) {
|
|
46
|
+
const declared = new Set(task.declaration.metrics?.map(metric => metric.id));
|
|
47
|
+
const unknown = rows.measurements.find(row => !declared.has(row.definition));
|
|
48
|
+
if (unknown)
|
|
49
|
+
throw new Error(`Undeclared metric from ${task.key}: ${unknown.definition}`);
|
|
50
|
+
}
|
|
51
|
+
if (!isCoreReportProduct(contract)) {
|
|
52
|
+
if (!isJson(value))
|
|
53
|
+
throw new Error(`Report product ${contract} is not JSON data`);
|
|
54
|
+
const record = { operation: task.key, ...(path === undefined ? {} : { path }), value };
|
|
55
|
+
const existing = this.products.get(contract);
|
|
56
|
+
if (existing)
|
|
57
|
+
existing.push(record);
|
|
58
|
+
else
|
|
59
|
+
this.products.set(contract, [record]);
|
|
60
|
+
}
|
|
61
|
+
for (const metric of task.declaration.metrics ?? [])
|
|
62
|
+
this.measured.add(metric.id);
|
|
63
|
+
return rows;
|
|
64
|
+
}
|
|
65
|
+
result() {
|
|
66
|
+
if (!this.declared)
|
|
67
|
+
return undefined;
|
|
68
|
+
return { metrics: [...this.metrics.values()], measured: [...this.measured],
|
|
69
|
+
...(this.privateMetrics.size ? { privateMetrics: [...this.privateMetrics] } : {}),
|
|
70
|
+
...(this.contracts.size ? { contracts: Object.fromEntries(this.contracts) } : {}),
|
|
71
|
+
rules: this.rules, products: Object.fromEntries(this.products) };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const churnSettings: {
|
|
2
|
+
readonly method: 'first-parent-path-touches/v1';
|
|
3
|
+
readonly lookbackDays: 90;
|
|
4
|
+
readonly maxCommits: 512;
|
|
5
|
+
};
|
|
6
|
+
export interface ChurnWindow {
|
|
7
|
+
readonly endingAt: string;
|
|
8
|
+
readonly commits: number;
|
|
9
|
+
readonly shallow: boolean;
|
|
10
|
+
readonly capReached: boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Candidate {
|
|
2
|
+
readonly start: number;
|
|
3
|
+
readonly end: number;
|
|
4
|
+
readonly line: number;
|
|
5
|
+
readonly endLine: number;
|
|
6
|
+
readonly codeLines: number;
|
|
7
|
+
readonly nodes: number;
|
|
8
|
+
readonly exact: string;
|
|
9
|
+
readonly similar: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CloneSource {
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly codeLines: readonly number[];
|
|
14
|
+
readonly candidates: readonly Candidate[];
|
|
15
|
+
}
|
|
16
|
+
export declare function isCloneSource(value: unknown): value is CloneSource;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isRecord } from '../engine/plugin.js';
|
|
2
|
+
function isCandidate(value) {
|
|
3
|
+
return isRecord(value) && isCount(value.start) && isCount(value.end) && value.start < value.end
|
|
4
|
+
&& isCount(value.line) && value.line > 0 && isCount(value.endLine) && value.endLine >= value.line
|
|
5
|
+
&& isCount(value.codeLines) && isCount(value.nodes) && typeof value.exact === 'string' && typeof value.similar === 'string';
|
|
6
|
+
}
|
|
7
|
+
function isCount(value) {
|
|
8
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
9
|
+
}
|
|
10
|
+
export function isCloneSource(value) {
|
|
11
|
+
return isRecord(value) && typeof value.path === 'string' && Array.isArray(value.codeLines)
|
|
12
|
+
&& value.codeLines.every((line, index, lines) => isCount(line) && line > (lines[index - 1] ?? 0))
|
|
13
|
+
&& Array.isArray(value.candidates) && value.candidates.every(isCandidate);
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DataContract } from '../engine/plugin.js';
|
|
2
|
+
import type { CloneSource } from './clone-source.js';
|
|
3
|
+
export declare const structuralCheckIds: readonly ['function-parameters', 'return-statements', 'boolean-logic', 'nested-control-flow', 'function-complexity', 'file-complexity'];
|
|
4
|
+
export type StructuralCheck = typeof structuralCheckIds[number];
|
|
5
|
+
export interface FunctionComplexity {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly line?: number;
|
|
8
|
+
readonly column?: number;
|
|
9
|
+
readonly value: number;
|
|
10
|
+
}
|
|
11
|
+
export interface StructuralObservation {
|
|
12
|
+
readonly rule: StructuralCheck;
|
|
13
|
+
readonly value: number;
|
|
14
|
+
readonly label: string;
|
|
15
|
+
readonly line?: number;
|
|
16
|
+
readonly endLine?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface CodeStructure {
|
|
19
|
+
readonly path: string;
|
|
20
|
+
readonly lines: number;
|
|
21
|
+
readonly functions: number;
|
|
22
|
+
readonly classes: number;
|
|
23
|
+
readonly cognitiveComplexity: number;
|
|
24
|
+
readonly commentLines: number;
|
|
25
|
+
readonly cyclomaticFunctions: readonly FunctionComplexity[];
|
|
26
|
+
readonly cognitiveFunctions: readonly FunctionComplexity[];
|
|
27
|
+
readonly observations: readonly StructuralObservation[];
|
|
28
|
+
readonly clones: CloneSource;
|
|
29
|
+
}
|
|
30
|
+
export declare const codeStructure: DataContract<CodeStructure>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isRecord } from '../engine/plugin.js';
|
|
2
|
+
import { isCloneSource } from './clone-source.js';
|
|
3
|
+
export const structuralCheckIds = [
|
|
4
|
+
'function-parameters', 'return-statements', 'boolean-logic', 'nested-control-flow',
|
|
5
|
+
'function-complexity', 'file-complexity',
|
|
6
|
+
];
|
|
7
|
+
const checkIds = new Set(structuralCheckIds);
|
|
8
|
+
function isCount(value) {
|
|
9
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
10
|
+
}
|
|
11
|
+
function isPosition(value) {
|
|
12
|
+
return value === undefined || (isCount(value) && value > 0);
|
|
13
|
+
}
|
|
14
|
+
function isFunctionComplexity(value) {
|
|
15
|
+
return isRecord(value) && typeof value.name === 'string' && isCount(value.value)
|
|
16
|
+
&& isPosition(value.line) && isPosition(value.column);
|
|
17
|
+
}
|
|
18
|
+
function isObservation(value) {
|
|
19
|
+
return isRecord(value) && typeof value.rule === 'string' && checkIds.has(value.rule)
|
|
20
|
+
&& typeof value.label === 'string' && isCount(value.value) && isPosition(value.line) && isPosition(value.endLine);
|
|
21
|
+
}
|
|
22
|
+
export const codeStructure = {
|
|
23
|
+
id: 'repometry.code-structure/v1',
|
|
24
|
+
accepts: (value) => isRecord(value)
|
|
25
|
+
&& typeof value.path === 'string' && isCount(value.lines) && isCount(value.functions) && isCount(value.classes)
|
|
26
|
+
&& isCount(value.cognitiveComplexity) && isCount(value.commentLines)
|
|
27
|
+
&& Array.isArray(value.cyclomaticFunctions) && value.cyclomaticFunctions.every(isFunctionComplexity)
|
|
28
|
+
&& Array.isArray(value.cognitiveFunctions) && value.cognitiveFunctions.every(isFunctionComplexity)
|
|
29
|
+
&& Array.isArray(value.observations) && value.observations.every(isObservation)
|
|
30
|
+
&& isCloneSource(value.clones) && value.clones.path === value.path,
|
|
31
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Report } from './report.js';
|
|
2
|
+
export declare const comparisonSchema = "urn:repometry:schema:comparison:1";
|
|
3
|
+
export interface Observation {
|
|
4
|
+
readonly status: 'complete' | 'partial' | 'not-applicable' | 'unavailable';
|
|
5
|
+
readonly value: number | null;
|
|
6
|
+
readonly covered?: number;
|
|
7
|
+
readonly total?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface MetricComparison {
|
|
10
|
+
readonly definition: string;
|
|
11
|
+
readonly unit: 'count' | 'percent';
|
|
12
|
+
readonly baseline: Observation;
|
|
13
|
+
readonly current: Observation;
|
|
14
|
+
readonly status: 'comparable' | 'incompatible' | 'unavailable';
|
|
15
|
+
readonly reason: 'observations-unavailable' | 'source-scope-unknown' | 'source-scope-changed' | 'method-unknown' | 'method-changed' | null;
|
|
16
|
+
readonly delta: number | null;
|
|
17
|
+
}
|
|
18
|
+
export type ComparisonSubject = Pick<Report, 'subject' | 'generatedAt' | 'status' | 'scope'>;
|
|
19
|
+
export interface InspectionComparison {
|
|
20
|
+
readonly schema: typeof comparisonSchema;
|
|
21
|
+
readonly baseline: ComparisonSubject;
|
|
22
|
+
readonly current: ComparisonSubject;
|
|
23
|
+
readonly metrics: Readonly<Record<'physicalLines' | 'functions' | 'maxCyclomaticComplexity' | 'lineCoverage', MetricComparison>>;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const comparisonSchema = 'urn:repometry:schema:comparison:1';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface FileCoverage {
|
|
2
|
+
readonly path: string;
|
|
3
|
+
readonly addedLines: number;
|
|
4
|
+
readonly covered: number | null;
|
|
5
|
+
readonly total: number | null;
|
|
6
|
+
}
|
|
7
|
+
export interface DiffCoverage {
|
|
8
|
+
readonly status: 'complete' | 'partial' | 'not-applicable';
|
|
9
|
+
readonly covered: number;
|
|
10
|
+
readonly total: number;
|
|
11
|
+
readonly percent: number | null;
|
|
12
|
+
readonly files: readonly FileCoverage[];
|
|
13
|
+
readonly gaps: readonly {
|
|
14
|
+
readonly path: string;
|
|
15
|
+
readonly reason: string;
|
|
16
|
+
}[];
|
|
17
|
+
}
|
|
18
|
+
export interface DiffCoverageResult extends DiffCoverage {
|
|
19
|
+
readonly uncovered: readonly {
|
|
20
|
+
readonly path: string;
|
|
21
|
+
readonly lines: readonly number[];
|
|
22
|
+
}[];
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Finding } from './finding.js';
|
|
2
|
+
import type { FindingIgnoreRule, IgnoredFinding } from './ignore-rule.js';
|
|
3
|
+
export type { FindingIgnoreRule, IgnoredFinding } from './ignore-rule.js';
|
|
4
|
+
export declare function normalizeFindingIgnore(value: unknown): readonly FindingIgnoreRule[];
|
|
5
|
+
export declare function partitionFindings(items: readonly Finding[], ignore: readonly FindingIgnoreRule[]): {
|
|
6
|
+
findings: readonly Finding[];
|
|
7
|
+
ignoredFindings: readonly IgnoredFinding[];
|
|
8
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isRecord } from '../engine/plugin.js';
|
|
2
|
+
import { exclusionMatcher, normalizeExclusions } from '../profile/exclusions.js';
|
|
3
|
+
const fields = new Set(['tool', 'rule', 'path', 'reason']);
|
|
4
|
+
export function normalizeFindingIgnore(value) {
|
|
5
|
+
if (!Array.isArray(value))
|
|
6
|
+
throw new Error('Profile ignore must be an array of finding rules');
|
|
7
|
+
return value.map((item) => {
|
|
8
|
+
if (!isRecord(item) || Object.entries(item).some(([key, value]) => !fields.has(key) || typeof value !== 'string' || value.trim() === '' || /[\0\r\n]/.test(value))) {
|
|
9
|
+
throw new Error('Finding ignore rules accept tool, rule, path and reason strings');
|
|
10
|
+
}
|
|
11
|
+
const { tool, rule, path, reason } = item;
|
|
12
|
+
if (tool === undefined && rule === undefined && path === undefined) {
|
|
13
|
+
throw new Error('Choose at least one of tool, rule or path for a finding ignore rule');
|
|
14
|
+
}
|
|
15
|
+
return { ...(tool !== undefined && { tool }), ...(rule !== undefined && { rule }),
|
|
16
|
+
...(path !== undefined && { path: normalizeExclusions([path])[0] }), ...(reason !== undefined && { reason }) };
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function partitionFindings(items, ignore) {
|
|
20
|
+
const findings = [];
|
|
21
|
+
const ignoredFindings = [];
|
|
22
|
+
const matches = ignore.map(({ tool, rule, path }) => {
|
|
23
|
+
const matchesPath = path === undefined ? undefined : exclusionMatcher([path]);
|
|
24
|
+
return (item) => (tool === undefined || tool === item.tool) && (rule === undefined || rule === item.rule)
|
|
25
|
+
&& (matchesPath === undefined || (item.path !== undefined && matchesPath(item.path)));
|
|
26
|
+
});
|
|
27
|
+
for (const finding of items) {
|
|
28
|
+
const matchedRule = matches.findIndex(match => match(finding));
|
|
29
|
+
if (matchedRule < 0)
|
|
30
|
+
findings.push(finding);
|
|
31
|
+
else
|
|
32
|
+
ignoredFindings.push({ finding, matchedRule });
|
|
33
|
+
}
|
|
34
|
+
return { findings, ignoredFindings };
|
|
35
|
+
}
|