repometry 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/package.json +1 -1
- package/target/main/resources/config/process-plugins-v1.schema.json +22 -0
- package/target/main/resources/report/json/config-v1.schema.json +125 -2
- package/target/main/resources/report/json/file-metrics-v1.schema.json +23 -1
- package/target/main/resources/report/json/pull-review-v2.schema.json +100 -0
- package/target/main/ts/api/cache/root.d.ts +3 -0
- package/target/main/ts/api/cache/root.js +21 -0
- package/target/main/ts/api/gh/github.d.ts +0 -4
- package/target/main/ts/api/gh/github.js +3 -33
- package/target/main/ts/api/git/blob-batch.js +2 -1
- package/target/main/ts/api/git/blob-history.d.ts +20 -0
- package/target/main/ts/api/git/blob-history.js +54 -0
- package/target/main/ts/api/git/commit-metadata.d.ts +0 -1
- package/target/main/ts/api/git/commit-metadata.js +1 -10
- package/target/main/ts/api/git/git-executable.d.ts +1 -0
- package/target/main/ts/api/git/git-executable.js +31 -0
- package/target/main/ts/api/git/git.d.ts +8 -1
- package/target/main/ts/api/git/git.js +58 -61
- package/target/main/ts/api/git/inspection-source.d.ts +2 -1
- package/target/main/ts/api/git/inspection-source.js +3 -2
- package/target/main/ts/api/git/local-sources.js +3 -2
- package/target/main/ts/api/git/source-cache.d.ts +0 -2
- package/target/main/ts/api/git/source-cache.js +1 -16
- package/target/main/ts/api/import/cobertura.d.ts +2 -0
- package/target/main/ts/api/import/cobertura.js +160 -0
- package/target/main/ts/api/import/coverage-xml.d.ts +7 -0
- package/target/main/ts/api/import/coverage-xml.js +135 -0
- package/target/main/ts/api/import/lcov-files.d.ts +3 -1
- package/target/main/ts/api/import/lcov-files.js +23 -4
- package/target/main/ts/api/process/go-parser-cache.d.ts +1 -0
- package/target/main/ts/api/process/go-parser-cache.js +71 -0
- package/target/main/ts/api/process/go-parser-files.d.ts +5 -0
- package/target/main/ts/api/process/go-parser-files.js +65 -0
- package/target/main/ts/api/process/host-language-runner.d.ts +3 -5
- package/target/main/ts/api/process/host-language-runner.js +21 -66
- package/target/main/ts/api/process/host-tool.d.ts +22 -0
- package/target/main/ts/api/process/host-tool.js +87 -0
- package/target/main/ts/cli/arguments.js +2 -4
- package/target/main/ts/cli/config.d.ts +20 -3
- package/target/main/ts/cli/config.js +43 -10
- package/target/main/ts/cli/imports.d.ts +1 -0
- package/target/main/ts/cli/imports.js +6 -2
- package/target/main/ts/cli/main.js +66 -215
- package/target/main/ts/cli/range-inspection.d.ts +25 -0
- package/target/main/ts/cli/range-inspection.js +29 -0
- package/target/main/ts/cli/range-jobs.d.ts +22 -0
- package/target/main/ts/cli/range-jobs.js +150 -0
- package/target/main/ts/cli/range-worker.d.ts +1 -0
- package/target/main/ts/cli/range-worker.js +36 -0
- package/target/main/ts/cli/reporting.d.ts +2 -7
- package/target/main/ts/cli/reporting.js +23 -37
- package/target/main/ts/compose/analysis-report.d.ts +1 -1
- package/target/main/ts/compose/analysis-report.js +8 -8
- package/target/main/ts/compose/analysis-results.d.ts +1 -1
- package/target/main/ts/compose/analysis-results.js +4 -6
- package/target/main/ts/compose/analysis-steps.d.ts +23 -0
- package/target/main/ts/compose/analysis-steps.js +215 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +1 -1
- package/target/main/ts/compose/analyze-snapshot.js +8 -12
- package/target/main/ts/compose/built-ins.d.ts +3 -0
- package/target/main/ts/compose/built-ins.js +5 -0
- package/target/main/ts/compose/diff-coverage.d.ts +2 -4
- package/target/main/ts/compose/diff-coverage.js +16 -13
- package/target/main/ts/compose/history-cache.d.ts +3 -1
- package/target/main/ts/compose/history-cache.js +2 -0
- package/target/main/ts/compose/inspect.d.ts +6 -9
- package/target/main/ts/compose/inspect.js +11 -12
- package/target/main/ts/compose/languages.d.ts +4 -1
- package/target/main/ts/compose/languages.js +9 -6
- package/target/main/ts/compose/native-language-plugins.d.ts +0 -1
- package/target/main/ts/compose/native-language-plugins.js +11 -17
- package/target/main/ts/compose/phases.d.ts +126 -0
- package/target/main/ts/compose/phases.js +154 -0
- package/target/main/ts/compose/plugin-list.d.ts +8 -2
- package/target/main/ts/compose/plugin-list.js +4 -13
- package/target/main/ts/compose/process-plugins.js +1 -1
- package/target/main/ts/compose/review.d.ts +2 -4
- package/target/main/ts/compose/review.js +10 -9
- package/target/main/ts/compose/sources.d.ts +1 -2
- package/target/main/ts/compose/sources.js +7 -7
- package/target/main/ts/core/engine/execute.d.ts +4 -1
- package/target/main/ts/core/engine/execute.js +1 -1
- package/target/main/ts/core/engine/manifest.d.ts +0 -1
- package/target/main/ts/core/engine/manifest.js +9 -13
- package/target/main/ts/core/engine/plugin.d.ts +1 -1
- package/target/main/ts/core/engine/report-products.js +3 -2
- package/target/main/ts/core/model/changes.d.ts +2 -0
- package/target/main/ts/core/model/changes.js +5 -1
- package/target/main/ts/core/model/clone-source.d.ts +2 -0
- package/target/main/ts/core/model/clone-source.js +4 -0
- package/target/main/ts/core/model/code-structure.d.ts +4 -1
- package/target/main/ts/core/model/code-structure.js +3 -1
- package/target/main/ts/core/model/coverage-input.d.ts +12 -0
- package/target/main/ts/core/model/coverage-input.js +11 -0
- package/target/main/ts/core/model/diff-coverage.d.ts +2 -0
- package/target/main/ts/core/model/diff-coverage.js +9 -1
- package/target/main/ts/core/model/language.d.ts +28 -0
- package/target/main/ts/core/model/language.js +25 -1
- package/target/main/ts/core/model/quality-summary.js +1 -1
- package/target/main/ts/core/model/report.d.ts +0 -2
- package/target/main/ts/core/model/report.js +0 -20
- package/target/main/ts/core/ports/tool-runner.d.ts +13 -0
- package/target/main/ts/core/usecases/inspect.d.ts +1 -2
- package/target/main/ts/core/usecases/review.js +11 -3
- package/target/main/ts/index.d.ts +6 -33
- package/target/main/ts/index.js +3 -18
- package/target/main/ts/plugin.d.ts +7 -3
- package/target/main/ts/plugin.js +3 -0
- package/target/main/ts/plugins/built-in.d.ts +6 -0
- package/target/main/ts/plugins/built-in.js +39 -0
- package/target/main/ts/plugins/coverage/coverage.d.ts +3 -24
- package/target/main/ts/plugins/coverage/coverage.js +8 -11
- package/target/main/ts/plugins/coverage/diff-coverage.d.ts +1 -5
- package/target/main/ts/plugins/coverage/diff-coverage.js +5 -14
- package/target/main/ts/plugins/duplication/duplication.d.ts +1 -3
- package/target/main/ts/plugins/duplication/duplication.js +2 -6
- package/target/main/ts/plugins/language-js/babel-provider.js +3 -2
- package/target/main/ts/plugins/language-js/structural-observations.js +1 -1
- package/target/main/ts/plugins/language-js/syntax.d.ts +2 -0
- package/target/main/ts/plugins/language-js/syntax.js +11 -0
- package/target/main/ts/plugins/maintainability/maintainability.d.ts +1 -8
- package/target/main/ts/plugins/maintainability/maintainability.js +4 -10
- package/target/main/ts/plugins/source/forges.js +1 -1
- package/target/main/ts/report/html/app/viewer-languages.d.ts +3 -1
- package/target/main/ts/report/html/app/viewer-languages.js +11 -1
- package/target/main/ts/report/html/app/viewer-metrics-view.js +1 -1
- package/target/main/ts/report/html/app/viewer-source-view.js +2 -2
- package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +7 -6
- package/target/main/ts/report/html/app/viewer-tokenizer.js +72 -71
- package/target/main/ts/report/html/site/export-site.d.ts +1 -5
- package/target/main/ts/report/html/site/export-site.js +2 -6
- package/target/main/ts/report/html/site/projects.d.ts +1 -3
- package/target/main/ts/report/html/site/projects.js +2 -4
- package/target/main/ts/report/json/projections/commit-summary.js +5 -7
- package/target/main/ts/report/json/projections/file-metrics.js +1 -1
- package/target/main/ts/report/json/projections/inspection-context.d.ts +1 -0
- package/target/main/ts/report/json/projections/inspection-context.js +19 -1
- package/target/main/ts/report/json/projections/inspection-details.js +7 -2
- package/target/main/ts/report/json/projections/metric-values.d.ts +5 -0
- package/target/main/ts/report/json/projections/metric-values.js +9 -6
- package/target/main/ts/report/json/store/local-store.js +2 -0
- package/target/main/ts/report/json/store/replace-file.d.ts +1 -1
- package/target/main/ts/report/json/store/replace-file.js +24 -3
- package/target/main/ts/report/json/store/store-check.js +10 -1
- package/target/main/ts/report/json/validation/metabranch.d.ts +1 -1
- package/target/main/ts/report/json/validation/metabranch.js +6 -3
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +3 -1
- package/target/main/ts/report.d.ts +13 -1
- package/target/main/ts/report.js +7 -1
- package/target/main/ts/api/git/metabranch-worktree.d.ts +0 -1
- package/target/main/ts/api/git/metabranch-worktree.js +0 -35
- package/target/main/ts/api/worker/remote-executor.d.ts +0 -2
- package/target/main/ts/api/worker/remote-executor.js +0 -46
- package/target/main/ts/api/worker/worker-protocol.d.ts +0 -7
- package/target/main/ts/api/worker/worker-protocol.js +0 -127
- package/target/main/ts/api/worker/worker.d.ts +0 -5
- package/target/main/ts/api/worker/worker.js +0 -86
- package/target/main/ts/compose/analysis-files.d.ts +0 -15
- package/target/main/ts/compose/analysis-files.js +0 -129
- package/target/main/ts/compose/analysis-imports.d.ts +0 -7
- package/target/main/ts/compose/analysis-imports.js +0 -36
- package/target/main/ts/compose/analysis-repository.d.ts +0 -7
- package/target/main/ts/compose/analysis-repository.js +0 -99
- package/target/main/ts/compose/analysis-sources.d.ts +0 -48
- package/target/main/ts/compose/analysis-sources.js +0 -54
- package/target/main/ts/compose/prepare-metabranch.d.ts +0 -9
- package/target/main/ts/compose/prepare-metabranch.js +0 -17
- package/target/main/ts/compose/security-plugins.d.ts +0 -1
- package/target/main/ts/compose/security-plugins.js +0 -7
- package/target/main/ts/core/usecases/compare.d.ts +0 -6
- package/target/main/ts/core/usecases/compare.js +0 -189
- package/target/main/ts/report/json/store/components.d.ts +0 -2
- package/target/main/ts/report/json/store/components.js +0 -32
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { DataContract, Operation, Plugin } from '../core/engine/plugin.js';
|
|
2
|
+
import type { SourceFile, SourceSnapshot } from '../core/model/source.js';
|
|
3
|
+
import type { LanguageProvider, LanguageRegistry } from './languages.js';
|
|
4
|
+
/**
|
|
5
|
+
* A phase of a run: the host inputs it offers by external port name, and what one of its tasks covers: one file, the files
|
|
6
|
+
* one plugin claims, or the whole run once. An operation runs only where the task matches its scope; a run task takes any.
|
|
7
|
+
*/
|
|
8
|
+
export type Phase = Readonly<{
|
|
9
|
+
offers: Readonly<Record<string, DataContract>>;
|
|
10
|
+
task: 'file' | 'repository' | 'run';
|
|
11
|
+
}>;
|
|
12
|
+
/** The phases of an analysis in run order. The coverage input is offered only when coverage is given. */
|
|
13
|
+
export declare function analysisPhases(withCoverage: boolean): {
|
|
14
|
+
readonly files: {
|
|
15
|
+
readonly task: 'file';
|
|
16
|
+
readonly offers: {
|
|
17
|
+
readonly file: DataContract<SourceFile>;
|
|
18
|
+
readonly syntax: DataContract<import("../core/model/code-structure.js").CodeStructure>;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
readonly repository: {
|
|
22
|
+
readonly task: 'repository';
|
|
23
|
+
readonly offers: {
|
|
24
|
+
readonly files: DataContract<readonly SourceFile[]>;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
readonly afterFiles: {
|
|
28
|
+
readonly task: 'run';
|
|
29
|
+
readonly offers: {
|
|
30
|
+
readonly sources: DataContract<readonly import("../core/model/clone-source.js").CloneSource[]>;
|
|
31
|
+
readonly lcov?: DataContract<import("../core/model/coverage-input.js").CoverageInput> | undefined;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
/** The one phase of a diff coverage run. */
|
|
36
|
+
export declare const diffCoveragePhases: {
|
|
37
|
+
readonly changedLines: {
|
|
38
|
+
readonly task: 'run';
|
|
39
|
+
readonly offers: {
|
|
40
|
+
readonly changes: DataContract<import("../core/model/changes.js").GitChanges>;
|
|
41
|
+
readonly lcov: DataContract<import("../core/model/coverage-input.js").CoverageInput>;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export type ActiveOperation = Readonly<{
|
|
46
|
+
plugin: Plugin;
|
|
47
|
+
operation: Operation;
|
|
48
|
+
key: string;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* The one rule for every plugin. An input is satisfied in a phase by a host input the phase offers, or by the output of
|
|
52
|
+
* any operation satisfied in that phase; more than one candidate is the planner's ambiguity. An operation runs in the
|
|
53
|
+
* first phase of this run that satisfies all its inputs. One that no phase of any run satisfies is an error; one that
|
|
54
|
+
* only another run, or this run with coverage, satisfies is inactive here. Host contracts come from the host only: no
|
|
55
|
+
* operation outputs one, except the parse of a language provider (`parsers`, by key), which is how the host gets it.
|
|
56
|
+
*/
|
|
57
|
+
export declare function selectOperations<Name extends string>(plugins: readonly Plugin[], phases: Readonly<Record<Name, Phase>>, parsers: ReadonlySet<string>): Record<Name, Readonly<{
|
|
58
|
+
plugin: Plugin;
|
|
59
|
+
operation: Operation;
|
|
60
|
+
key: string;
|
|
61
|
+
}>[]>;
|
|
62
|
+
/** An active inspection and the files it runs on: those its plugin claims, and only parsed ones when it reads code structure. */
|
|
63
|
+
export type Inspection = ActiveOperation & {
|
|
64
|
+
readonly parsed: boolean;
|
|
65
|
+
readonly matches: (path: string, parsed: boolean) => boolean;
|
|
66
|
+
};
|
|
67
|
+
/** One step of the pipeline: the plugins the planner may choose from, and the inspections to plan. */
|
|
68
|
+
export type Step = Readonly<{
|
|
69
|
+
candidates: readonly Plugin[];
|
|
70
|
+
inspections: readonly Inspection[];
|
|
71
|
+
}>;
|
|
72
|
+
/** The plugins restricted to the given operations, in their order, for the planner to choose from. */
|
|
73
|
+
export declare function candidatesOf(operations: readonly ActiveOperation[]): Plugin[];
|
|
74
|
+
/** The external inputs of a phase as the planner reads them, by port name. */
|
|
75
|
+
export declare function phaseInputs({ offers }: Phase, omit?: DataContract): ReadonlyMap<string, string>;
|
|
76
|
+
export type SelectedSource = Readonly<{
|
|
77
|
+
file: SourceFile;
|
|
78
|
+
provider: LanguageProvider | undefined;
|
|
79
|
+
}>;
|
|
80
|
+
/** Whether a file is claimed by an inspection that runs on claimed files rather than on every parsed one. */
|
|
81
|
+
export declare function inspectionFileMatcher(additional: readonly Plugin[], languages: LanguageRegistry): (path: string) => boolean;
|
|
82
|
+
/** The files of a snapshot with their language providers, and the steps that analyse them. */
|
|
83
|
+
export declare function selectAnalysisSources(snapshot: SourceSnapshot, additional: readonly Plugin[], withCoverage: boolean): {
|
|
84
|
+
languages: {
|
|
85
|
+
select(path: string): LanguageProvider | undefined;
|
|
86
|
+
isSource(path: string): boolean;
|
|
87
|
+
id(path: string): string;
|
|
88
|
+
syntax(id: string): import("../plugin.js").LanguageSyntax | undefined;
|
|
89
|
+
readonly extensions: readonly string[];
|
|
90
|
+
readonly globs: readonly string[];
|
|
91
|
+
readonly catalog: readonly import("../plugin.js").LanguageDisplay[];
|
|
92
|
+
readonly providers: readonly LanguageProvider[];
|
|
93
|
+
readonly native: readonly import("./native-language-plugins.js").NativeLanguagePlugin[];
|
|
94
|
+
skipped(path: string): boolean;
|
|
95
|
+
};
|
|
96
|
+
sources: Readonly<{
|
|
97
|
+
file: SourceFile;
|
|
98
|
+
provider: LanguageProvider | undefined;
|
|
99
|
+
}>[];
|
|
100
|
+
sourceFiles: SourceFile[];
|
|
101
|
+
unavailableFiles: Set<string>;
|
|
102
|
+
providersByPath: Map<string, LanguageProvider>;
|
|
103
|
+
steps: {
|
|
104
|
+
plugins: Plugin[];
|
|
105
|
+
repositorySyntax: {
|
|
106
|
+
candidates: readonly Plugin[];
|
|
107
|
+
inspections: readonly Inspection[];
|
|
108
|
+
provider: LanguageProvider;
|
|
109
|
+
}[];
|
|
110
|
+
files: Readonly<{
|
|
111
|
+
candidates: readonly Plugin[];
|
|
112
|
+
inspections: readonly Inspection[];
|
|
113
|
+
}>;
|
|
114
|
+
repository: Readonly<{
|
|
115
|
+
candidates: readonly Plugin[];
|
|
116
|
+
inspections: readonly Inspection[];
|
|
117
|
+
}>;
|
|
118
|
+
afterFiles: Readonly<{
|
|
119
|
+
candidates: readonly Plugin[];
|
|
120
|
+
inspections: readonly Inspection[];
|
|
121
|
+
}>;
|
|
122
|
+
claims: (plugin: Plugin, path: string) => boolean;
|
|
123
|
+
};
|
|
124
|
+
plugins: Plugin[];
|
|
125
|
+
};
|
|
126
|
+
export type AnalysisSources = ReturnType<typeof selectAnalysisSources>;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { plan } from '../core/engine/plan.js';
|
|
2
|
+
import { changesInput } from '../core/model/changes.js';
|
|
3
|
+
import { cloneSources } from '../core/model/clone-source.js';
|
|
4
|
+
import { codeStructure, codeStructures } from '../core/model/code-structure.js';
|
|
5
|
+
import { lcovInput } from '../core/model/coverage-input.js';
|
|
6
|
+
import { sourceFile, sourceFiles } from '../core/model/snapshot.js';
|
|
7
|
+
import { builtInPluginIds, builtInPlugins } from './built-ins.js';
|
|
8
|
+
import { claimMatcher, languageRegistry } from './languages.js';
|
|
9
|
+
/** The phases of an analysis in run order. The coverage input is offered only when coverage is given. */
|
|
10
|
+
export function analysisPhases(withCoverage) {
|
|
11
|
+
return {
|
|
12
|
+
files: { task: 'file', offers: { file: sourceFile, syntax: codeStructure } },
|
|
13
|
+
repository: { task: 'repository', offers: { files: sourceFiles } },
|
|
14
|
+
afterFiles: { task: 'run', offers: { sources: cloneSources, ...(withCoverage ? { lcov: lcovInput } : {}) } },
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** The one phase of a diff coverage run. */
|
|
18
|
+
export const diffCoveragePhases = { changedLines: { task: 'run', offers: { changes: changesInput, lcov: lcovInput } } };
|
|
19
|
+
/** The phases of each kind of run, with all their optional host inputs. Every plugin takes part in an analysis; only built-ins in diff coverage. */
|
|
20
|
+
const analysisRun = Object.values(analysisPhases(true));
|
|
21
|
+
const diffCoverageRun = Object.values(diffCoveragePhases);
|
|
22
|
+
/** The closed list of host contracts: every contract some host run offers. */
|
|
23
|
+
const hostContracts = new Set([...analysisRun, ...diffCoverageRun].flatMap(({ offers }) => Object.values(offers).map(({ id }) => id)));
|
|
24
|
+
// Reserve both parse outputs. The host supplies per-file structure directly to phases.
|
|
25
|
+
const languageOutputs = new Set([codeStructure.id, codeStructures.id]);
|
|
26
|
+
/**
|
|
27
|
+
* The one rule for every plugin. An input is satisfied in a phase by a host input the phase offers, or by the output of
|
|
28
|
+
* any operation satisfied in that phase; more than one candidate is the planner's ambiguity. An operation runs in the
|
|
29
|
+
* first phase of this run that satisfies all its inputs. One that no phase of any run satisfies is an error; one that
|
|
30
|
+
* only another run, or this run with coverage, satisfies is inactive here. Host contracts come from the host only: no
|
|
31
|
+
* operation outputs one, except the parse of a language provider (`parsers`, by key), which is how the host gets it.
|
|
32
|
+
*/
|
|
33
|
+
export function selectOperations(plugins, phases, parsers) {
|
|
34
|
+
const all = plugins.flatMap(plugin => plugin.operations.map(operation => ({ plugin, operation, key: `${plugin.id}/${operation.id}` })));
|
|
35
|
+
const supplier = all.find(({ key, operation: { output } }) => (hostContracts.has(output.id) || languageOutputs.has(output.id)) && !parsers.has(key));
|
|
36
|
+
if (supplier) {
|
|
37
|
+
const { id } = supplier.operation.output;
|
|
38
|
+
const only = languageOutputs.has(id) ? 'a language provider' : 'the host';
|
|
39
|
+
throw new Error(`${supplier.key} outputs ${id}, which only ${only} supplies`);
|
|
40
|
+
}
|
|
41
|
+
rejectUnsatisfiable(all);
|
|
42
|
+
const selected = {};
|
|
43
|
+
let waiting = all;
|
|
44
|
+
for (const [name, phase] of Object.entries(phases)) {
|
|
45
|
+
selected[name] = satisfiedIn(phase, waiting);
|
|
46
|
+
waiting = waiting.filter(candidate => !selected[name].includes(candidate));
|
|
47
|
+
}
|
|
48
|
+
return selected;
|
|
49
|
+
}
|
|
50
|
+
/** The operations a phase satisfies: those of its task's scope whose inputs it offers or satisfied operations output. */
|
|
51
|
+
function satisfiedIn(phase, candidates) {
|
|
52
|
+
const inScope = candidates.filter(({ operation }) => [operation.scope ?? 'file', 'run'].includes(phase.task));
|
|
53
|
+
return reached(inScope, Object.values(phase.offers).map(({ id }) => id), 'every');
|
|
54
|
+
}
|
|
55
|
+
/** The operations reached from some contracts: each reads every (or some) of its inputs from them or from earlier ones' outputs. */
|
|
56
|
+
function reached(operations, contracts, reads, found = []) {
|
|
57
|
+
const next = operations.filter(item => !found.includes(item) && Object.values(item.operation.inputs)[reads](({ id }) => contracts.includes(id)));
|
|
58
|
+
if (!next.length)
|
|
59
|
+
return operations.filter(item => found.includes(item));
|
|
60
|
+
return reached(operations, [...contracts, ...next.map(({ operation }) => operation.output.id)], reads, [...found, ...next]);
|
|
61
|
+
}
|
|
62
|
+
/** Rejects an operation that no phase satisfies in any run its plugin takes part in, naming the root cause first. */
|
|
63
|
+
function rejectUnsatisfiable(all) {
|
|
64
|
+
const satisfiable = new Set([...analysisRun.flatMap(phase => satisfiedIn(phase, all)),
|
|
65
|
+
...diffCoverageRun.flatMap(phase => satisfiedIn(phase, all.filter(({ plugin }) => builtInPluginIds.has(plugin.id))))]);
|
|
66
|
+
const unsatisfiable = all.filter(candidate => !satisfiable.has(candidate));
|
|
67
|
+
const ids = (contracts) => [...contracts].map(({ id }) => id);
|
|
68
|
+
const known = [...hostContracts, ...ids(all.map(({ operation }) => operation.output))];
|
|
69
|
+
const reachable = [...hostContracts, ...ids([...satisfiable].map(({ operation }) => operation.output))];
|
|
70
|
+
const unread = ({ operation }, offered) => ids(Object.values(operation.inputs)).filter(id => !offered.includes(id));
|
|
71
|
+
const unknown = unsatisfiable.find(candidate => unread(candidate, known).length);
|
|
72
|
+
if (unknown)
|
|
73
|
+
throw new Error(`${unknown.key} reads ${unread(unknown, known).join(', ')}, which no plugin outputs`);
|
|
74
|
+
// The root cause before what depends on it: an operation whose inputs are all on offer, but in no single phase.
|
|
75
|
+
const root = unsatisfiable.find(candidate => !unread(candidate, reachable).length);
|
|
76
|
+
if (root)
|
|
77
|
+
throw new Error(`${root.key} reads ${ids(Object.values(root.operation.inputs)).join(', ')}, which no phase of its runs offers together`);
|
|
78
|
+
// What is left reads only the products of unsatisfiable operations, as in a dependency cycle.
|
|
79
|
+
const [dependent] = unsatisfiable;
|
|
80
|
+
if (dependent)
|
|
81
|
+
throw new Error(`${dependent.key} reads ${unread(dependent, reachable).join(', ')}, which only operations that never run output`);
|
|
82
|
+
}
|
|
83
|
+
/** What runs where in an analysis: the active plugins and the four steps. */
|
|
84
|
+
function analysisSteps(plugins, languages, withCoverage) {
|
|
85
|
+
const { files, repository, afterFiles } = selectOperations(plugins, analysisPhases(withCoverage), new Set(languages.providers.map(({ key }) => key)));
|
|
86
|
+
// Those that read the code structure, directly or through the products of others, run on the parsed files their plugin claims.
|
|
87
|
+
const readers = new Set(reached(files, [codeStructure.id], 'some'));
|
|
88
|
+
const claims = new Map(plugins.map(plugin => [plugin.id, claimsOf(plugin, languages)]));
|
|
89
|
+
const step = (operations, candidates = operations) => ({ candidates: candidatesOf(candidates),
|
|
90
|
+
inspections: operations.filter(({ operation }) => operation.role === 'inspection').map(active => ({ ...active, parsed: readers.has(active),
|
|
91
|
+
matches: (path, isParsed) => (!readers.has(active) || isParsed) && claims.get(active.plugin.id)(path) })) });
|
|
92
|
+
const parsers = repositoryParsers(plugins, languages);
|
|
93
|
+
const active = new Set([...files, ...repository, ...afterFiles].map(({ plugin }) => plugin));
|
|
94
|
+
return {
|
|
95
|
+
plugins: plugins.filter(plugin => active.has(plugin)),
|
|
96
|
+
repositorySyntax: [...parsers].map(([plugin, provider]) => ({ provider, ...step(repository.filter(operation => operation.plugin === plugin)) })),
|
|
97
|
+
files: step(files),
|
|
98
|
+
repository: step(repository.filter(({ plugin }) => !parsers.has(plugin)), repository),
|
|
99
|
+
afterFiles: step(afterFiles),
|
|
100
|
+
claims: (plugin, path) => claims.get(plugin.id)(path),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** Plugins that parse a language over the whole repository: their repository operations run first, since the files read the structures. */
|
|
104
|
+
function repositoryParsers(plugins, languages) {
|
|
105
|
+
return new Map(plugins.flatMap(plugin => languages.providers.filter(provider => provider.batch && provider.plugin === plugin)
|
|
106
|
+
.map(provider => [plugin, provider])));
|
|
107
|
+
}
|
|
108
|
+
/** The files a plugin claims: a language plugin those it parses, any other the files its claims match, or every file without claims. */
|
|
109
|
+
function claimsOf(plugin, languages) {
|
|
110
|
+
return languages.providers.some(provider => provider.plugin === plugin)
|
|
111
|
+
? path => languages.select(path)?.plugin === plugin : claimMatcher(plugin.claims, languages.id);
|
|
112
|
+
}
|
|
113
|
+
/** The plugins restricted to the given operations, in their order, for the planner to choose from. */
|
|
114
|
+
export function candidatesOf(operations) {
|
|
115
|
+
const byPlugin = new Map();
|
|
116
|
+
for (const { plugin, operation } of operations)
|
|
117
|
+
byPlugin.set(plugin, [...byPlugin.get(plugin) ?? [], operation]);
|
|
118
|
+
return [...byPlugin].map(([plugin, chosen]) => chosen.length === plugin.operations.length ? plugin : { ...plugin, operations: chosen });
|
|
119
|
+
}
|
|
120
|
+
/** The external inputs of a phase as the planner reads them, by port name. */
|
|
121
|
+
export function phaseInputs({ offers }, omit) {
|
|
122
|
+
return new Map(Object.entries(offers).filter(([, contract]) => contract !== omit).map(([port, { id }]) => [port, id]));
|
|
123
|
+
}
|
|
124
|
+
/** Whether a file is claimed by an inspection that runs on claimed files rather than on every parsed one. */
|
|
125
|
+
export function inspectionFileMatcher(additional, languages) {
|
|
126
|
+
const { files, repository } = analysisSteps(runPlugins(additional, languages), languages, false);
|
|
127
|
+
const claimed = [...files.inspections, ...repository.inspections].filter(({ parsed }) => !parsed);
|
|
128
|
+
return path => claimed.some(({ matches }) => matches(path, false));
|
|
129
|
+
}
|
|
130
|
+
/** The files of a snapshot with their language providers, and the steps that analyse them. */
|
|
131
|
+
export function selectAnalysisSources(snapshot, additional, withCoverage) {
|
|
132
|
+
const languages = languageRegistry(additional);
|
|
133
|
+
const sources = snapshot.files.map(file => ({ file, provider: languages.select(file.path) }));
|
|
134
|
+
const providersByPath = new Map(sources.flatMap(({ file, provider }) => provider ? [[file.path, provider]] : []));
|
|
135
|
+
const unavailableFiles = new Set(sources.filter(({ file, provider }) => !provider && languages.skipped(file.path))
|
|
136
|
+
.map(({ file }) => file.path));
|
|
137
|
+
const sourceFiles = sources.flatMap(({ file, provider }) => provider ? [file] : []);
|
|
138
|
+
const steps = analysisSteps(runPlugins(additional, languages), languages, withCoverage);
|
|
139
|
+
return { languages, sources, sourceFiles, unavailableFiles, providersByPath, steps, plugins: steps.plugins };
|
|
140
|
+
}
|
|
141
|
+
/** The built-ins in root order, then the enabled host languages, then the additional plugins, each bound to its language. */
|
|
142
|
+
function runPlugins(additional, languages) {
|
|
143
|
+
if (additional.some(plugin => builtInPluginIds.has(plugin.id) && !builtInPlugins.includes(plugin))) {
|
|
144
|
+
throw new Error('An additional plugin uses a built-in plugin ID');
|
|
145
|
+
}
|
|
146
|
+
const bound = new Map(languages.providers.map(({ plugin }) => [plugin.id, plugin]));
|
|
147
|
+
const native = languages.native.flatMap(({ id }) => bound.get(id) ?? []);
|
|
148
|
+
const plugins = [...builtInPlugins.filter(plugin => !additional.includes(plugin)), ...native, ...additional]
|
|
149
|
+
.map(plugin => bound.get(plugin.id) ?? plugin);
|
|
150
|
+
if (additional.length)
|
|
151
|
+
plan({ plugins, select: [], inputs: new Map() });
|
|
152
|
+
return plugins;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=phases.js.map
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import type { Plugin } from '../core/engine/plugin.js';
|
|
2
|
-
export declare const builtInPluginIds: Set<string>;
|
|
3
2
|
export declare function effectivePlugins(additional: readonly Plugin[]): {
|
|
4
3
|
id: string;
|
|
5
4
|
version: string;
|
|
6
5
|
kinds: readonly import("../core/engine/plugin.js").PluginKind[];
|
|
7
6
|
claims?: import("../core/engine/plugin.js").FileClaims | undefined;
|
|
8
|
-
providesLanguages?:
|
|
7
|
+
providesLanguages?: {
|
|
8
|
+
id: string;
|
|
9
|
+
label: string;
|
|
10
|
+
color?: string;
|
|
11
|
+
extensions?: readonly string[];
|
|
12
|
+
globs?: readonly string[];
|
|
13
|
+
measures?: readonly import("../plugin.js").StructureMeasure[];
|
|
14
|
+
}[] | undefined;
|
|
9
15
|
unavailableReason?: string | undefined;
|
|
10
16
|
}[];
|
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { duplication } from '../plugins/duplication/duplication.js';
|
|
4
|
-
import { maintainability } from '../plugins/maintainability/maintainability.js';
|
|
5
|
-
import { structure } from '../plugins/structure/structure.js';
|
|
6
|
-
import { nativeLanguageIds } from './native-language-plugins.js';
|
|
7
|
-
import { defaultLanguages, languageRegistry } from './languages.js';
|
|
8
|
-
import { sourceProviders } from './sources.js';
|
|
9
|
-
import { securityPlugins } from './security-plugins.js';
|
|
10
|
-
const builtInPlugins = [...defaultLanguages.providers.map(({ plugin }) => plugin), structure, maintainability, duplication, coverage,
|
|
11
|
-
diffCoverage, ...securityPlugins, ...sourceProviders];
|
|
12
|
-
export const builtInPluginIds = new Set([...builtInPlugins.map(({ id }) => id), ...nativeLanguageIds]);
|
|
1
|
+
import { languageRegistry } from './languages.js';
|
|
2
|
+
import { builtInPlugins } from './built-ins.js';
|
|
13
3
|
export function effectivePlugins(additional) {
|
|
14
4
|
const native = languageRegistry(additional).native.map(plugin => ({ ...describePlugin(plugin), ...(plugin.tools ? { tools: plugin.tools } : {}) }));
|
|
15
5
|
return [...builtInPlugins.map(describePlugin), ...native, ...additional.map(describePlugin)];
|
|
16
6
|
}
|
|
17
7
|
function describePlugin({ id, version, kinds, claims, providesLanguages, unavailableReason }) {
|
|
18
|
-
return { id, version, kinds, ...(claims ? { claims } : {}),
|
|
8
|
+
return { id, version, kinds, ...(claims ? { claims } : {}),
|
|
9
|
+
...(providesLanguages ? { providesLanguages: providesLanguages.map(({ syntax, ...language }) => language) } : {}),
|
|
19
10
|
...(unavailableReason ? { unavailableReason } : {}) };
|
|
20
11
|
}
|
|
21
12
|
//# sourceMappingURL=plugin-list.js.map
|
|
@@ -6,7 +6,7 @@ import { pluginApi } from '../core/engine/plugin.js';
|
|
|
6
6
|
import { codeStructure, codeStructures } from '../core/model/code-structure.js';
|
|
7
7
|
import { sourceFile, sourceFiles } from '../core/model/snapshot.js';
|
|
8
8
|
import { languageRegistry } from './languages.js';
|
|
9
|
-
import { builtInPluginIds } from './
|
|
9
|
+
import { builtInPluginIds } from './built-ins.js';
|
|
10
10
|
let check;
|
|
11
11
|
export function readProcessPlugins(value) {
|
|
12
12
|
if (value === undefined)
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CoverageInputs } from '../api/import/lcov-files.js';
|
|
2
2
|
import type { Plugin } from '../core/engine/plugin.js';
|
|
3
3
|
import type { FindingIgnoreRule } from '../core/model/ignore-rule.js';
|
|
4
4
|
import type { PullReview } from '../core/model/pull-review.js';
|
|
5
5
|
import type { ReviewOptions } from '../core/usecases/review.js';
|
|
6
6
|
export { projectReview, reviewExitCode, reviewReason } from '../core/usecases/review.js';
|
|
7
|
-
export interface ReviewRequest extends ReviewOptions {
|
|
7
|
+
export interface ReviewRequest extends ReviewOptions, CoverageInputs {
|
|
8
8
|
/** The repository root. */
|
|
9
9
|
readonly directory: string;
|
|
10
10
|
readonly base: string;
|
|
11
11
|
readonly revision?: string;
|
|
12
|
-
readonly lcov?: LcovFiles;
|
|
13
|
-
readonly goCover?: LcovFiles;
|
|
14
12
|
readonly exclude?: readonly string[];
|
|
15
13
|
readonly ignore?: readonly FindingIgnoreRule[];
|
|
16
14
|
readonly plugins?: readonly Plugin[];
|
|
@@ -4,18 +4,21 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { findMergeBase } from '../api/git/changes.js';
|
|
5
5
|
import { GitBlobReader, resolveGitCommit } from '../api/git/git.js';
|
|
6
6
|
import { readLineChanges } from '../api/git/line-changes.js';
|
|
7
|
+
import { hasCoverageInputs } from '../api/import/lcov-files.js';
|
|
7
8
|
import { checkOptions, projectReview } from '../core/usecases/review.js';
|
|
8
9
|
import { measureChangedLines } from './diff-coverage.js';
|
|
9
10
|
import { HistoryCache } from './history-cache.js';
|
|
10
|
-
import {
|
|
11
|
+
import { inspectWithOptions } from './inspect.js';
|
|
11
12
|
export { projectReview, reviewExitCode, reviewReason } from '../core/usecases/review.js';
|
|
12
13
|
/**
|
|
13
14
|
* Analyses the merge base and the head with the same settings, in a temporary store, and reports what the change did
|
|
14
15
|
* on the lines it changed. The repository's own store is neither read nor written.
|
|
15
16
|
*/
|
|
16
17
|
export async function review(request) {
|
|
17
|
-
const { directory, lcov, goCover, exclude, ignore, plugins } = request;
|
|
18
|
-
|
|
18
|
+
const { directory, lcov, goCover, cobertura, exclude, ignore, plugins } = request;
|
|
19
|
+
const inputs = { lcov, goCover, cobertura };
|
|
20
|
+
const withCoverage = hasCoverageInputs(inputs);
|
|
21
|
+
checkOptions(request, withCoverage);
|
|
19
22
|
const [head, requested] = await Promise.all([resolveGitCommit(directory, request.revision ?? 'HEAD'),
|
|
20
23
|
resolveGitCommit(directory, request.base).catch((error) => {
|
|
21
24
|
throw new Error(`${error instanceof Error ? error.message : String(error)}. A review needs the base's history: fetch it, `
|
|
@@ -25,13 +28,13 @@ export async function review(request) {
|
|
|
25
28
|
const output = await mkdtemp(join(tmpdir(), 'repometry-review-'));
|
|
26
29
|
try {
|
|
27
30
|
const history = new HistoryCache(request.settings);
|
|
28
|
-
const inspectCommit = (id, coverage) =>
|
|
29
|
-
...coverage ?
|
|
31
|
+
const inspectCommit = (id, coverage) => inspectWithOptions({ directory, output, source: { revision: id }, exclude, ignore, plugins,
|
|
32
|
+
...coverage ? inputs : {} }, { history, deferSummary: true, recordChurn: false });
|
|
30
33
|
const base = await inspectCommit(mergeBase, false);
|
|
31
34
|
const headReport = await inspectCommit(head, true);
|
|
32
35
|
const changes = await readLineChanges(directory, mergeBase, head);
|
|
33
|
-
const coverage =
|
|
34
|
-
|
|
36
|
+
const coverage = withCoverage
|
|
37
|
+
? await measureChangedLines({ directory, base: mergeBase, revision: head, ...inputs, exclude, plugins }) : null;
|
|
35
38
|
const sources = { base: await sourceLines(directory, mergeBase, changes, 'previous'), head: await sourceLines(directory, head, changes, 'path') };
|
|
36
39
|
const settingsChanged = request.settingsPath !== undefined
|
|
37
40
|
&& changes.files.some(file => file.path === request.settingsPath || file.previous === request.settingsPath);
|
|
@@ -41,8 +44,6 @@ export async function review(request) {
|
|
|
41
44
|
await rm(output, { recursive: true, force: true });
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
|
-
/** A review compares findings, not file activity: it skips the walk over Git history that churn needs. */
|
|
45
|
-
const noChurn = { recordChurn: undefined };
|
|
46
47
|
/** The text of one side's changed files, which scope and matching read line by line. */
|
|
47
48
|
async function sourceLines(directory, commit, changes, side) {
|
|
48
49
|
const paths = changes.files.flatMap(file => file[side] === null || file.whole ? [] : [file[side]]);
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import type { SourceContext, SourcePlugin } from '../core/ports/source-provider.js';
|
|
2
|
-
export declare
|
|
3
|
-
export declare function resolveSourceLocator(option: string | undefined, context: Omit<SourceContext, 'option'>, providers?: readonly SourcePlugin[]): import("../plugin.js").SourceLocator | undefined;
|
|
2
|
+
export declare function resolveSourceLocator(option: string | undefined, context: Omit<SourceContext, 'option'>, providers?: SourcePlugin[]): import("../report.js").SourceLocator | undefined;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { plan } from '../core/engine/plan.js';
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
export function resolveSourceLocator(option, context, providers = sourceProviders) {
|
|
2
|
+
import { builtInPlugins } from './built-ins.js';
|
|
3
|
+
export function resolveSourceLocator(option, context, providers = builtInPlugins.filter((plugin) => plugin.kinds.includes('source'))) {
|
|
5
4
|
plan({ plugins: providers, select: [], inputs: new Map() });
|
|
6
5
|
if (option === 'none')
|
|
7
6
|
return undefined;
|
|
8
7
|
if (option && option !== 'auto')
|
|
9
8
|
return namedSourceLocator(option, context, providers);
|
|
10
|
-
|
|
9
|
+
// A provider that locates sources without CI variables or remotes is the fallback, tried last.
|
|
10
|
+
const fallback = providers.find(provider => provider.locate({ env: {}, remotes: [] }) !== undefined);
|
|
11
11
|
for (const candidate of [{ env: context.env, remotes: [] }, { env: {}, remotes: context.remotes }]) {
|
|
12
|
-
for (const provider of
|
|
13
|
-
const locator = provider.locate(candidate);
|
|
12
|
+
for (const provider of providers) {
|
|
13
|
+
const locator = provider === fallback ? undefined : provider.locate(candidate);
|
|
14
14
|
if (locator)
|
|
15
15
|
return locator;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
return
|
|
18
|
+
return fallback?.locate(context);
|
|
19
19
|
}
|
|
20
20
|
function namedSourceLocator(option, context, providers) {
|
|
21
21
|
const colon = option.indexOf(':');
|
|
@@ -4,7 +4,10 @@ import type { PlannedOperation } from './plan.js';
|
|
|
4
4
|
export type Outcome = {
|
|
5
5
|
readonly state: 'completed';
|
|
6
6
|
readonly product: Product;
|
|
7
|
-
readonly diagnostics?: readonly
|
|
7
|
+
readonly diagnostics?: readonly {
|
|
8
|
+
message: string;
|
|
9
|
+
path?: string;
|
|
10
|
+
}[];
|
|
8
11
|
} | {
|
|
9
12
|
readonly state: 'failed' | 'blocked';
|
|
10
13
|
readonly reason: string;
|
|
@@ -36,7 +36,7 @@ async function runTask(task, inputs, cache) {
|
|
|
36
36
|
}
|
|
37
37
|
return readInput(inputs, port, contract);
|
|
38
38
|
},
|
|
39
|
-
emitDiagnostic: message => diagnostics.push(message),
|
|
39
|
+
emitDiagnostic: (message, path) => diagnostics.push(path === undefined ? { message } : { message, path }),
|
|
40
40
|
};
|
|
41
41
|
const value = await operation.execute(context);
|
|
42
42
|
const { output } = operation;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { MetricDescriptor, Plugin, ProductDeclaration } from './plugin.js';
|
|
2
|
-
export declare function isCoreReportProduct(contract: string): boolean;
|
|
3
2
|
export declare function manifestProducts(plugin: Plugin): ReadonlyMap<string, ProductDeclaration>;
|
|
4
3
|
export declare function isMetricDescriptor(value: unknown): value is MetricDescriptor;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isRecord } from './plugin.js';
|
|
2
|
-
import {
|
|
2
|
+
import { findingResult } from '../model/finding.js';
|
|
3
|
+
import { definitions, measurements } from '../model/measurement.js';
|
|
3
4
|
import { structureMeasures } from '../model/code-structure.js';
|
|
4
|
-
import { isLanguageDisplay } from '../model/language.js';
|
|
5
|
+
import { isLanguageDisplay, isLanguageSyntax } from '../model/language.js';
|
|
5
6
|
const kinds = new Set(['language', 'analysis', 'coverage', 'security', 'import', 'source']);
|
|
6
7
|
const persistence = new Set(['report', 'cache', 'transient']);
|
|
7
8
|
const units = new Set(['count', 'ratio', 'minutes']);
|
|
@@ -9,14 +10,6 @@ const scopes = new Set(['repository', 'file', 'function']);
|
|
|
9
10
|
const aggregates = new Set(['sum', 'max', 'none']);
|
|
10
11
|
const directions = new Set(['lower', 'higher', 'none']);
|
|
11
12
|
const coreMetrics = new Set(Object.values(definitions));
|
|
12
|
-
const coreProducts = new Set([
|
|
13
|
-
'repometry.measurements/v1', 'repometry.findings-and-measurements/v1',
|
|
14
|
-
'repometry.maintainability-file/v1', 'repometry.coverage-result/v1',
|
|
15
|
-
'repometry.source-locator/v1',
|
|
16
|
-
]);
|
|
17
|
-
export function isCoreReportProduct(contract) {
|
|
18
|
-
return coreProducts.has(contract);
|
|
19
|
-
}
|
|
20
13
|
export function manifestProducts(plugin) {
|
|
21
14
|
const { id, produces, rules } = manifestDeclarations(plugin);
|
|
22
15
|
const products = new Map();
|
|
@@ -26,8 +19,9 @@ export function manifestProducts(plugin) {
|
|
|
26
19
|
|| products.has(product.contract))
|
|
27
20
|
throw new Error(`Invalid or duplicate product for plugin ${id}`);
|
|
28
21
|
const { contract, schema, metrics } = product;
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
// Only rows need no schema: the core row contracts, or a report product that declares its metrics.
|
|
23
|
+
const rows = [measurements.id, findingResult.id].includes(contract) || (product.persistence === 'report' && metrics !== undefined);
|
|
24
|
+
if (schema === undefined ? product.persistence !== 'transient' && !rows : typeof schema !== 'boolean' && !isRecord(schema)) {
|
|
31
25
|
throw new Error(`Missing or invalid product schema for ${contract} in plugin ${id}`);
|
|
32
26
|
}
|
|
33
27
|
if (metrics !== undefined && (!Array.isArray(metrics) || !metrics.every(isMetricDescriptor))) {
|
|
@@ -87,7 +81,9 @@ function validLanguages(values) {
|
|
|
87
81
|
for (const value of values) {
|
|
88
82
|
if (!isRecord(value) || !isLanguageDisplay(value) || ids.has(value.id))
|
|
89
83
|
return false;
|
|
90
|
-
const { extensions, globs, measures } = value;
|
|
84
|
+
const { extensions, globs, measures, syntax } = value;
|
|
85
|
+
if (syntax !== undefined && !isLanguageSyntax(syntax))
|
|
86
|
+
return false;
|
|
91
87
|
if (extensions !== undefined && (!strings(extensions) || !extensions.every(isExtension)))
|
|
92
88
|
return false;
|
|
93
89
|
if (globs !== undefined && !strings(globs))
|
|
@@ -14,7 +14,7 @@ export interface Product {
|
|
|
14
14
|
}
|
|
15
15
|
export interface InspectionInputs {
|
|
16
16
|
read<T>(port: string, contract: DataContract<T>): T;
|
|
17
|
-
emitDiagnostic?(message: string): void;
|
|
17
|
+
emitDiagnostic?(message: string, path?: string): void;
|
|
18
18
|
}
|
|
19
19
|
export interface Operation {
|
|
20
20
|
readonly id: string;
|
|
@@ -3,7 +3,6 @@ import { findingResult } from '../model/finding.js';
|
|
|
3
3
|
import { measurements } from '../model/measurement.js';
|
|
4
4
|
import { isJsonValue } from '../model/plugin-data.js';
|
|
5
5
|
import { isRecord } from './plugin.js';
|
|
6
|
-
import { isCoreReportProduct } from './manifest.js';
|
|
7
6
|
export class ReportProducts {
|
|
8
7
|
metrics = new Map();
|
|
9
8
|
measured = new Set();
|
|
@@ -49,7 +48,9 @@ export class ReportProducts {
|
|
|
49
48
|
if (unknown)
|
|
50
49
|
throw new Error(`Undeclared metric from ${task.key}: ${unknown.definition}`);
|
|
51
50
|
}
|
|
52
|
-
if (!
|
|
51
|
+
if (task.declaration.schema === undefined && !rows)
|
|
52
|
+
throw new Error(`Report product ${contract} from ${task.key} has no schema and no rows`);
|
|
53
|
+
if (task.declaration.schema !== undefined) {
|
|
53
54
|
if (!isJsonValue(value))
|
|
54
55
|
throw new Error(`Report product ${contract} is not JSON data`);
|
|
55
56
|
const record = { operation: task.key, ...(path === undefined ? {} : { path }), value };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DataContract } from '../engine/plugin.js';
|
|
1
2
|
export interface LineRange {
|
|
2
3
|
readonly first: number;
|
|
3
4
|
readonly last: number;
|
|
@@ -35,3 +36,4 @@ export interface GitChanges {
|
|
|
35
36
|
readonly files: ReadonlyMap<string, readonly LineRange[]>;
|
|
36
37
|
readonly gaps: ReadonlyMap<string, string>;
|
|
37
38
|
}
|
|
39
|
+
export declare const changesInput: DataContract<GitChanges>;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { isRecord } from './plugin-data.js';
|
|
2
|
+
export const changesInput = {
|
|
3
|
+
id: 'repometry.git-line-changes/v1',
|
|
4
|
+
accepts: (value) => isRecord(value) && value.files instanceof Map && value.gaps instanceof Map,
|
|
5
|
+
};
|
|
2
6
|
//# sourceMappingURL=changes.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DataContract } from '../engine/plugin.js';
|
|
1
2
|
export interface Candidate {
|
|
2
3
|
readonly start: number;
|
|
3
4
|
readonly end: number;
|
|
@@ -15,3 +16,4 @@ export interface CloneSource {
|
|
|
15
16
|
readonly candidates: readonly Candidate[];
|
|
16
17
|
}
|
|
17
18
|
export declare function isCloneSource(value: unknown): value is CloneSource;
|
|
19
|
+
export declare const cloneSources: DataContract<readonly CloneSource[]>;
|
|
@@ -13,3 +13,7 @@ export function isCloneSource(value) {
|
|
|
13
13
|
&& value.codeLines.every((line, index, lines) => isCount(line) && line > (lines[index - 1] ?? 0))
|
|
14
14
|
&& Array.isArray(value.candidates) && value.candidates.every(isCandidate);
|
|
15
15
|
}
|
|
16
|
+
export const cloneSources = {
|
|
17
|
+
id: 'repometry.clone-sources/v1',
|
|
18
|
+
accepts: (value) => Array.isArray(value) && value.every(isCloneSource),
|
|
19
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DataContract } from '../engine/plugin.js';
|
|
2
2
|
import type { CloneSource } from './clone-source.js';
|
|
3
3
|
import type { SourceLineRange } from './source.js';
|
|
4
|
-
|
|
4
|
+
declare const structuralCheckIds: readonly ['function-parameters', 'return-statements', 'boolean-logic', 'nested-control-flow', 'function-complexity', 'file-complexity'];
|
|
5
5
|
export type StructuralCheck = typeof structuralCheckIds[number];
|
|
6
6
|
export declare const structureMeasures: readonly ['functions', 'cyclomaticComplexity', 'cognitiveComplexity', 'classes', 'commentLines', 'codeLines', 'duplication', 'structuralRules'];
|
|
7
7
|
export type StructureMeasure = typeof structureMeasures[number];
|
|
@@ -40,3 +40,6 @@ export declare const codeStructure: DataContract<CodeStructure>;
|
|
|
40
40
|
export declare function structureCodeLines(value: CodeStructure): readonly number[] | undefined;
|
|
41
41
|
/** A repository provider returns at most one structure per input path. */
|
|
42
42
|
export declare const codeStructures: DataContract<readonly CodeStructure[]>;
|
|
43
|
+
/** The structure measure that rules of a finding category need. Without it, a file skips those rules. */
|
|
44
|
+
export declare const ruleCategoryMeasures: Readonly<Partial<Record<string, StructureMeasure>>>;
|
|
45
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isRecord } from './plugin-data.js';
|
|
2
2
|
import { isCloneSource } from './clone-source.js';
|
|
3
3
|
import { isMergedLineRanges } from './source.js';
|
|
4
|
-
|
|
4
|
+
const structuralCheckIds = [
|
|
5
5
|
'function-parameters', 'return-statements', 'boolean-logic', 'nested-control-flow',
|
|
6
6
|
'function-complexity', 'file-complexity',
|
|
7
7
|
];
|
|
@@ -58,3 +58,5 @@ export const codeStructures = {
|
|
|
58
58
|
accepts: (value) => Array.isArray(value) && value.every(codeStructure.accepts)
|
|
59
59
|
&& new Set(value.map(({ path }) => path)).size === value.length,
|
|
60
60
|
};
|
|
61
|
+
/** The structure measure that rules of a finding category need. Without it, a file skips those rules. */
|
|
62
|
+
export const ruleCategoryMeasures = { structure: 'structuralRules', duplication: 'duplication' };
|