repometry 0.10.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- 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 +41 -0
- 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 +1 -1
- package/target/main/ts/api/cache/root.js +2 -2
- 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/commit-metadata.d.ts +0 -1
- package/target/main/ts/api/git/commit-metadata.js +1 -10
- 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/cli/arguments.js +2 -4
- package/target/main/ts/cli/config.d.ts +10 -6
- package/target/main/ts/cli/config.js +36 -6
- 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 +47 -139
- package/target/main/ts/cli/range-inspection.d.ts +0 -3
- package/target/main/ts/cli/range-inspection.js +5 -17
- package/target/main/ts/cli/range-jobs.js +1 -3
- 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 +4 -5
- 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 +15 -12
- package/target/main/ts/compose/history-cache.d.ts +1 -1
- package/target/main/ts/compose/inspect.d.ts +6 -9
- package/target/main/ts/compose/inspect.js +8 -9
- 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 +4 -11
- 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/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/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,23 @@
|
|
|
1
|
+
import type { OperationCacheOptions } from '../core/engine/operation-cache.js';
|
|
2
|
+
import type { PlannedOperation } from '../core/engine/plan.js';
|
|
3
|
+
import type { CodeStructure } from '../core/model/code-structure.js';
|
|
4
|
+
import type { AnalysisInput } from '../core/usecases/inspect.js';
|
|
5
|
+
import type { AnalysisResults } from './analysis-results.js';
|
|
6
|
+
import type { HistoryFiles } from './history-cache.js';
|
|
7
|
+
import type { AnalysisSources } from './phases.js';
|
|
8
|
+
/** A parsed file's structure, kept for the inspections after the files, and the plugin that parsed it. */
|
|
9
|
+
export type ParsedFile = Readonly<{
|
|
10
|
+
path: string;
|
|
11
|
+
structure: CodeStructure;
|
|
12
|
+
parser: string;
|
|
13
|
+
}>;
|
|
14
|
+
/** The plan of a file the first provider parses and nothing claims, recorded before any file so the records keep their order. */
|
|
15
|
+
export declare function defaultFilePlan(sources: AnalysisSources): readonly PlannedOperation[];
|
|
16
|
+
/** Runs each language parsed over the repository on its files, with the plugin's other repository operations. */
|
|
17
|
+
export declare function collectRepositorySyntax(sources: AnalysisSources, results: AnalysisResults, cache?: OperationCacheOptions, history?: HistoryFiles): Promise<Map<string, CodeStructure>>;
|
|
18
|
+
/** Runs each file's inspections, with its provider's parse unless the repository syntax already read the file. */
|
|
19
|
+
export declare function inspectFiles(sources: AnalysisSources, batchFacts: ReadonlyMap<string, CodeStructure>, results: AnalysisResults, cache?: OperationCacheOptions, history?: HistoryFiles): Promise<ParsedFile[]>;
|
|
20
|
+
/** Runs every other repository inspection on the files its plugin claims. */
|
|
21
|
+
export declare function inspectRepositories(sources: AnalysisSources, results: AnalysisResults, cache?: OperationCacheOptions): Promise<void>;
|
|
22
|
+
/** Runs the inspections that read what the files phase gathered: clone sources and, when given, the coverage input. */
|
|
23
|
+
export declare function inspectAfterFiles({ coverage: input, excludedPaths, snapshot }: AnalysisInput, sources: AnalysisSources, parsed: readonly ParsedFile[], results: AnalysisResults, cache?: OperationCacheOptions): Promise<void>;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { execute } from '../core/engine/execute.js';
|
|
2
|
+
import { plan } from '../core/engine/plan.js';
|
|
3
|
+
import { cloneSources as cloneSourcesContract } from '../core/model/clone-source.js';
|
|
4
|
+
import { codeStructure, codeStructures, ruleCategoryMeasures, structureCodeLines } from '../core/model/code-structure.js';
|
|
5
|
+
import { lcovInput } from '../core/model/coverage-input.js';
|
|
6
|
+
import { sourceFile, sourceFiles, sourceLineCounts } from '../core/model/snapshot.js';
|
|
7
|
+
import { isClaimedText, maxClaimedFileBytes } from '../core/model/source.js';
|
|
8
|
+
import { sourceExclusionMatcher } from '../core/profile/exclusions.js';
|
|
9
|
+
import { oversizedClaim } from './analysis-results.js';
|
|
10
|
+
import { canReuseBatch } from './history-cache.js';
|
|
11
|
+
import { analysisPhases, phaseInputs } from './phases.js';
|
|
12
|
+
import { unmeasuredStructure } from './structure-measures.js';
|
|
13
|
+
// The steps of an analysis in run order. Each runs what the phases chose for it; none decides what runs where.
|
|
14
|
+
const { files: filesPhase, repository: repositoryPhase } = analysisPhases(false);
|
|
15
|
+
/** The plan of a file the first provider parses and nothing claims, recorded before any file so the records keep their order. */
|
|
16
|
+
export function defaultFilePlan(sources) {
|
|
17
|
+
const [provider] = sources.languages.providers;
|
|
18
|
+
// Language plugins claim the files they parse, so only the first provider's plugin and those without claims are left.
|
|
19
|
+
const unclaimed = ({ claims, providesLanguages, id }) => (!claims && !providesLanguages) || id === provider?.plugin.id;
|
|
20
|
+
return filePlan(provider, sources.steps.files.inspections.filter(({ parsed, plugin }) => parsed && unclaimed(plugin)), sources.steps.files.candidates.filter(unclaimed));
|
|
21
|
+
}
|
|
22
|
+
/** Runs each language parsed over the repository on its files, with the plugin's other repository operations. */
|
|
23
|
+
export async function collectRepositorySyntax(sources, results, cache, history) {
|
|
24
|
+
const facts = new Map();
|
|
25
|
+
for (const { provider, ...step } of sources.steps.repositorySyntax) {
|
|
26
|
+
const files = sources.sources.filter(source => source.provider === provider).map(({ file }) => file);
|
|
27
|
+
if (!files.length)
|
|
28
|
+
continue;
|
|
29
|
+
const reusable = canReuseBatch(provider) ? history : undefined;
|
|
30
|
+
const outcomes = await runRepository(step, files, [provider.key, ...step.inspections.map(({ key }) => key)], results, cache, reusable);
|
|
31
|
+
const syntax = outcomes.get(provider.key); // execute() checked its value against the contract
|
|
32
|
+
if (syntax?.state === 'completed')
|
|
33
|
+
collectFacts(facts, syntax.product.value, files, provider.key, results);
|
|
34
|
+
}
|
|
35
|
+
return facts;
|
|
36
|
+
}
|
|
37
|
+
/** Runs each file's inspections, with its provider's parse unless the repository syntax already read the file. */
|
|
38
|
+
export async function inspectFiles(sources, batchFacts, results, cache, history) {
|
|
39
|
+
const plans = new Map();
|
|
40
|
+
const parsed = [];
|
|
41
|
+
for (const source of sources.sources) {
|
|
42
|
+
const { file, provider } = source;
|
|
43
|
+
const inspections = fileInspections(source, sources.steps.files, results);
|
|
44
|
+
if (!provider && !inspections.length)
|
|
45
|
+
continue;
|
|
46
|
+
const tasks = findFilePlan(sources, source, inspections, plans, results);
|
|
47
|
+
const facts = batchFacts.get(file.path);
|
|
48
|
+
const reusable = provider?.batch && (!facts || !canReuseBatch(provider)) ? undefined : history;
|
|
49
|
+
const outcomes = await fileOutcomes(source, tasks, facts, cache, reusable);
|
|
50
|
+
const structure = facts ?? parsedStructure(provider && outcomes.get(provider.key));
|
|
51
|
+
if (structure)
|
|
52
|
+
parsed.push(recordParsed({ path: file.path, structure, parser: provider.plugin.id }, results, sources.plugins));
|
|
53
|
+
for (const task of tasks)
|
|
54
|
+
results.record(task, outcomes.get(task.key), file.path);
|
|
55
|
+
}
|
|
56
|
+
return parsed;
|
|
57
|
+
}
|
|
58
|
+
/** Runs every other repository inspection on the files its plugin claims. */
|
|
59
|
+
export async function inspectRepositories(sources, results, cache) {
|
|
60
|
+
const step = sources.steps.repository;
|
|
61
|
+
for (const plugin of new Set(step.inspections.map(({ plugin }) => plugin))) {
|
|
62
|
+
const inspections = step.inspections.filter(inspection => inspection.plugin === plugin);
|
|
63
|
+
const files = sources.sources.map(({ file }) => file).filter(file => inspections[0].matches(file.path, false) && isClaimedText(file.bytes));
|
|
64
|
+
if (files.length)
|
|
65
|
+
await runRepository(step, files, inspections.map(({ key }) => key), results, cache);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Runs the inspections that read what the files phase gathered: clone sources and, when given, the coverage input. */
|
|
69
|
+
export async function inspectAfterFiles({ coverage: input, excludedPaths = [], snapshot }, sources, parsed, results, cache) {
|
|
70
|
+
const clones = parsed.flatMap(({ structure: { clones }, parser }) => clones ? [{ ...clones, scheme: clones.scheme ?? parser }] : []);
|
|
71
|
+
const products = new Map([['sources', { contract: cloneSourcesContract.id, value: clones }]]);
|
|
72
|
+
if (input !== undefined) {
|
|
73
|
+
const unclassified = new Set([...results.unmeasured].filter(([, missing]) => missing.includes('codeLines')).map(([path]) => path));
|
|
74
|
+
const excludes = sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded);
|
|
75
|
+
const codeLines = parsed.flatMap(({ path, structure }) => {
|
|
76
|
+
const lines = structureCodeLines(structure);
|
|
77
|
+
return lines === undefined ? [] : [[path, new Set(lines)]];
|
|
78
|
+
});
|
|
79
|
+
const functionBodies = parsed.flatMap(({ path, structure: { functionBodies } }) => functionBodies ? [[path, functionBodies]] : []);
|
|
80
|
+
products.set('lcov', { contract: lcovInput.id, value: { text: input.text, root: input.sourceRoot,
|
|
81
|
+
sourceLines: sourceLineCounts(sources.sourceFiles), codeLines: new Map(codeLines), unclassified,
|
|
82
|
+
functionBodies: new Map(functionBodies), excludes: (path) => excludes(path) || sources.unavailableFiles.has(path) } });
|
|
83
|
+
}
|
|
84
|
+
const { candidates, inspections } = sources.steps.afterFiles;
|
|
85
|
+
const tasks = plan({ plugins: candidates, select: inspections.map(({ key }) => key),
|
|
86
|
+
inputs: new Map([...products].map(([port, { contract }]) => [port, contract])) });
|
|
87
|
+
const outcomes = await execute(tasks, products, cache);
|
|
88
|
+
for (const task of tasks) {
|
|
89
|
+
results.remember(task);
|
|
90
|
+
results.record(task, outcomes.get(task.key));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function parsedStructure(outcome) {
|
|
94
|
+
return outcome?.state === 'completed' ? outcome.product.value : undefined; // execute() checked the contract
|
|
95
|
+
}
|
|
96
|
+
async function fileOutcomes({ file }, tasks, facts, cache, history) {
|
|
97
|
+
const saved = history?.read(file.path)?.outcomes;
|
|
98
|
+
if (saved) {
|
|
99
|
+
history?.retain(file.path, { outcomes: saved });
|
|
100
|
+
return saved;
|
|
101
|
+
}
|
|
102
|
+
const products = new Map([['file', { contract: sourceFile.id, value: file }]]);
|
|
103
|
+
if (facts)
|
|
104
|
+
products.set('syntax', { contract: codeStructure.id, value: facts });
|
|
105
|
+
const outcomes = await execute(tasks, products, cache);
|
|
106
|
+
if (history && [...outcomes.values()].every(outcome => outcome.state === 'completed' && !outcome.diagnostics?.length)) {
|
|
107
|
+
history.retain(file.path, { outcomes });
|
|
108
|
+
}
|
|
109
|
+
return outcomes;
|
|
110
|
+
}
|
|
111
|
+
/** The inspections that run on a file. Those that run because their plugin claims it need a text file under the size limit. */
|
|
112
|
+
function fileInspections({ file, provider }, { inspections }, results) {
|
|
113
|
+
const matched = inspections.filter(({ matches }) => matches(file.path, provider !== undefined));
|
|
114
|
+
const claimed = matched.some(({ parsed }) => !parsed);
|
|
115
|
+
if (claimed && file.bytes.byteLength > maxClaimedFileBytes)
|
|
116
|
+
results.diagnostics.push(oversizedClaim(file.path));
|
|
117
|
+
return isClaimedText(file.bytes) ? matched : matched.filter(({ parsed }) => parsed);
|
|
118
|
+
}
|
|
119
|
+
/** A file's plan, shared by the files with the same provider, inspections and claiming plugins. */
|
|
120
|
+
function findFilePlan(sources, { file, provider }, inspections, plans, results) {
|
|
121
|
+
// A consumer runs only where its producer may: the planner chooses from the plugins that claim the file.
|
|
122
|
+
const claiming = sources.steps.files.candidates.filter(plugin => sources.steps.claims(plugin, file.path));
|
|
123
|
+
const key = JSON.stringify([provider?.key ?? null, inspections.map(({ key }) => key), claiming.map(({ id }) => id)]);
|
|
124
|
+
const cached = plans.get(key);
|
|
125
|
+
if (cached)
|
|
126
|
+
return cached;
|
|
127
|
+
const tasks = filePlan(provider, inspections, claiming);
|
|
128
|
+
plans.set(key, tasks);
|
|
129
|
+
for (const task of tasks) {
|
|
130
|
+
const consumesBatch = provider?.batch && [...task.inputs.values()].some(input => 'external' in input && input.external === 'syntax');
|
|
131
|
+
results.remember(task, consumesBatch ? provider.key : undefined);
|
|
132
|
+
}
|
|
133
|
+
return tasks;
|
|
134
|
+
}
|
|
135
|
+
/** A file's plan: its provider's parse unless the repository syntax already read it, then the file's inspections. */
|
|
136
|
+
function filePlan(provider, inspections, plugins) {
|
|
137
|
+
const parse = provider && !provider.batch ? [provider.key] : [];
|
|
138
|
+
return plan({ plugins, select: [...parse, ...inspections.map(({ key }) => key)],
|
|
139
|
+
inputs: phaseInputs(filesPhase, provider?.batch ? undefined : codeStructure) });
|
|
140
|
+
}
|
|
141
|
+
/** Records a parsed file and, for each measure it lacks, a skip of the rules that need the measure. */
|
|
142
|
+
function recordParsed(file, results, plugins) {
|
|
143
|
+
const { path } = file;
|
|
144
|
+
results.parsed.add(path);
|
|
145
|
+
const unmeasured = unmeasuredStructure(file.structure);
|
|
146
|
+
if (unmeasured.length)
|
|
147
|
+
results.unmeasured.set(path, unmeasured);
|
|
148
|
+
for (const plugin of plugins) {
|
|
149
|
+
const rules = plugin.rules?.filter(({ category }) => unmeasured.some(measure => ruleCategoryMeasures[category] === measure))
|
|
150
|
+
.map(({ id }) => id) ?? [];
|
|
151
|
+
if (rules.length)
|
|
152
|
+
results.ruleSkips.push({ path, plugin: plugin.id, rules, reason: 'unmeasured' });
|
|
153
|
+
}
|
|
154
|
+
return file;
|
|
155
|
+
}
|
|
156
|
+
async function runRepository({ candidates }, files, select, results, cache, history) {
|
|
157
|
+
const tasks = plan({ plugins: candidates, select, inputs: phaseInputs(repositoryPhase) });
|
|
158
|
+
const outcomes = history && tasks.length === 1
|
|
159
|
+
? await runIndependentProvider(tasks[0], files, history, cache) : await executeRepository(tasks, files, cache);
|
|
160
|
+
const paths = files.map(({ path }) => path);
|
|
161
|
+
for (const task of tasks) {
|
|
162
|
+
results.remember(task);
|
|
163
|
+
results.record(task, outcomes.get(task.key), undefined, paths);
|
|
164
|
+
}
|
|
165
|
+
return outcomes;
|
|
166
|
+
}
|
|
167
|
+
function executeRepository(tasks, files, cache) {
|
|
168
|
+
return execute(tasks, new Map([['files', { contract: sourceFiles.id, value: files }]]), cache);
|
|
169
|
+
}
|
|
170
|
+
async function runIndependentProvider(task, files, history, cache) {
|
|
171
|
+
const saved = new Map(files.flatMap(({ path }) => {
|
|
172
|
+
const syntax = history.read(path)?.syntax;
|
|
173
|
+
return syntax === undefined ? [] : [[path, syntax]];
|
|
174
|
+
}));
|
|
175
|
+
const missing = files.filter(({ path }) => !saved.has(path));
|
|
176
|
+
const outcomes = missing.length === 0 ? undefined : await executeRepository([task], missing, cache);
|
|
177
|
+
const fresh = outcomes === undefined ? [] : successfulBatch(outcomes.get(task.key), missing);
|
|
178
|
+
// Preserve complete-batch diagnostics if an incremental run produces incomplete facts or a warning.
|
|
179
|
+
if (!fresh)
|
|
180
|
+
return saved.size ? executeRepository([task], files, cache) : outcomes;
|
|
181
|
+
for (const syntax of fresh)
|
|
182
|
+
saved.set(syntax.path, syntax);
|
|
183
|
+
const values = files.map(({ path }) => saved.get(path));
|
|
184
|
+
const { output } = task.operation;
|
|
185
|
+
if (missing.length !== files.length && (!output.accepts(values) || (task.validateOutput && !task.validateOutput(values)))) {
|
|
186
|
+
return executeRepository([task], files, cache);
|
|
187
|
+
}
|
|
188
|
+
for (const syntax of values)
|
|
189
|
+
history.retain(syntax.path, { syntax });
|
|
190
|
+
return missing.length === files.length ? outcomes : new Map([[task.key, {
|
|
191
|
+
state: 'completed', product: { contract: output.id, value: values },
|
|
192
|
+
}]]);
|
|
193
|
+
}
|
|
194
|
+
function successfulBatch(outcome, files) {
|
|
195
|
+
if (outcome?.state !== 'completed' || outcome.diagnostics?.length || !codeStructures.accepts(outcome.product.value))
|
|
196
|
+
return;
|
|
197
|
+
const values = outcome.product.value;
|
|
198
|
+
const paths = new Set(files.map(({ path }) => path));
|
|
199
|
+
if (values.length === paths.size && values.every(({ path }) => paths.has(path)))
|
|
200
|
+
return values;
|
|
201
|
+
}
|
|
202
|
+
function collectFacts(target, values, files, operation, results) {
|
|
203
|
+
const planned = new Set(files.map(({ path }) => path));
|
|
204
|
+
if (values.some(({ path }) => !planned.has(path))) {
|
|
205
|
+
results.diagnostics.push({ operation, state: 'failed', message: 'Language provider returned a path outside its inputs' });
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
for (const facts of values)
|
|
209
|
+
target.set(facts.path, facts);
|
|
210
|
+
for (const path of planned) {
|
|
211
|
+
if (!target.has(path))
|
|
212
|
+
results.diagnostics.push({ operation, state: 'failed', path, message: 'Language provider returned no structure for this file' });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=analysis-steps.js.map
|
|
@@ -3,5 +3,5 @@ import type { Plugin } from '../core/engine/plugin.js';
|
|
|
3
3
|
import type { Report } from '../core/model/report.js';
|
|
4
4
|
import type { AnalysisInput } from '../core/usecases/inspect.js';
|
|
5
5
|
import type { HistoryCache } from './history-cache.js';
|
|
6
|
-
export { inspectionFileMatcher } from './
|
|
6
|
+
export { inspectionFileMatcher } from './phases.js';
|
|
7
7
|
export declare function analyzeSnapshot(input: AnalysisInput, additional?: readonly Plugin[], cache?: OperationCacheOptions, history?: HistoryCache): Promise<Report>;
|
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
import { defaultFilePlan, inspectFiles } from './analysis-
|
|
2
|
-
import { importAnalysisCoverage, inspectDuplication } from './analysis-imports.js';
|
|
3
|
-
import { collectRepositorySyntax, inspectRepositories } from './analysis-repository.js';
|
|
1
|
+
import { collectRepositorySyntax, defaultFilePlan, inspectAfterFiles, inspectFiles, inspectRepositories } from './analysis-steps.js';
|
|
4
2
|
import { assembleAnalysisReport } from './analysis-report.js';
|
|
5
3
|
import { AnalysisResults } from './analysis-results.js';
|
|
6
|
-
import { selectAnalysisSources } from './
|
|
4
|
+
import { selectAnalysisSources } from './phases.js';
|
|
7
5
|
import { historyProfile } from './history-cache.js';
|
|
8
|
-
export { inspectionFileMatcher } from './
|
|
6
|
+
export { inspectionFileMatcher } from './phases.js';
|
|
9
7
|
export async function analyzeSnapshot(input, additional = [], cache, history) {
|
|
10
|
-
const
|
|
11
|
-
const sources = selectAnalysisSources(input.snapshot, additional, withCoverage);
|
|
8
|
+
const sources = selectAnalysisSources(input.snapshot, additional, input.coverage !== undefined);
|
|
12
9
|
const reusable = history?.begin(input.snapshot, historyProfile(input, sources, cache?.configurationDigest));
|
|
13
|
-
const results = new AnalysisResults(sources.plugins,
|
|
14
|
-
for (const task of defaultFilePlan)
|
|
10
|
+
const results = new AnalysisResults(sources.plugins, input.snapshot.oversizedClaims ?? []);
|
|
11
|
+
for (const task of defaultFilePlan(sources))
|
|
15
12
|
results.remember(task);
|
|
16
13
|
const batchFacts = await collectRepositorySyntax(sources, results, cache, reusable);
|
|
17
|
-
const
|
|
14
|
+
const parsed = await inspectFiles(sources, batchFacts, results, cache, reusable);
|
|
18
15
|
await inspectRepositories(sources, results, cache);
|
|
19
|
-
await
|
|
20
|
-
await importAnalysisCoverage(input, sources, files, results, cache);
|
|
16
|
+
await inspectAfterFiles(input, sources, parsed, results, cache);
|
|
21
17
|
return assembleAnalysisReport(input, sources, results);
|
|
22
18
|
}
|
|
23
19
|
//# sourceMappingURL=analyze-snapshot.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { builtInPlugins, hostLanguages } from '../plugins/built-in.js';
|
|
2
|
+
// The one edge from compose to plugins: everything else in compose reads the built-ins from here.
|
|
3
|
+
export { builtInPlugins, hostLanguages };
|
|
4
|
+
export const builtInPluginIds = new Set([...builtInPlugins, ...hostLanguages].map(({ id }) => id));
|
|
5
|
+
//# sourceMappingURL=built-ins.js.map
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type { Plugin } from '../core/engine/plugin.js';
|
|
2
2
|
import type { DiffCoveragePorts, DiffCoverageReport } from '../core/usecases/diff-coverage.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { CoverageInputs } from '../api/import/lcov-files.js';
|
|
4
4
|
export { diffCoverageSchema } from '../core/usecases/diff-coverage.js';
|
|
5
5
|
export type { DiffCoverageReport } from '../core/usecases/diff-coverage.js';
|
|
6
|
-
export interface DiffCoverageRequest {
|
|
6
|
+
export interface DiffCoverageRequest extends CoverageInputs {
|
|
7
7
|
readonly directory: string;
|
|
8
8
|
readonly revision: string;
|
|
9
9
|
readonly base: string;
|
|
10
|
-
readonly lcov?: LcovFiles;
|
|
11
|
-
readonly goCover?: LcovFiles;
|
|
12
10
|
readonly exclude?: readonly string[];
|
|
13
11
|
readonly minimumPercent?: number;
|
|
14
12
|
readonly plugins?: readonly Plugin[];
|
|
@@ -3,16 +3,22 @@ import { plan } from '../core/engine/plan.js';
|
|
|
3
3
|
import { digest, sourceDirectoriesExcluded, sourceLineCounts } from '../core/model/snapshot.js';
|
|
4
4
|
import { executeDiffCoverage } from '../core/usecases/diff-coverage.js';
|
|
5
5
|
import { defaultSourceExclusions, generatedSourcePolicy, sourceExclusionMatcher } from '../core/profile/exclusions.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { changesInput } from '../core/model/changes.js';
|
|
7
|
+
import { lcovInput } from '../core/model/coverage-input.js';
|
|
8
|
+
import { diffCoverageResult } from '../core/model/diff-coverage.js';
|
|
9
|
+
import { builtInPlugins } from './built-ins.js';
|
|
10
|
+
import { candidatesOf, diffCoveragePhases, phaseInputs, selectOperations } from './phases.js';
|
|
8
11
|
import { diffMethod, findMergeBase, readChanges } from '../api/git/changes.js';
|
|
9
12
|
import { gitText, physicalGitRoot, readGitCommit, resolveGitCommit } from '../api/git/git.js';
|
|
10
13
|
import { readInspectionCoverage } from './inspection-coverage.js';
|
|
11
|
-
import { languageRegistry } from './languages.js';
|
|
14
|
+
import { defaultLanguages, languageRegistry } from './languages.js';
|
|
12
15
|
export { diffCoverageSchema } from '../core/usecases/diff-coverage.js';
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
+
const { changedLines } = selectOperations(builtInPlugins, diffCoveragePhases, new Set(defaultLanguages.providers.map(({ key }) => key)));
|
|
17
|
+
const { plugin: measurer, key: operation } = changedLines.find(({ operation }) => operation.output === diffCoverageResult);
|
|
18
|
+
// The result records the version of the import-kind plugin that reads the coverage input.
|
|
19
|
+
const { plugin: importer } = changedLines.find(({ plugin, operation }) => plugin.kinds.includes('import')
|
|
20
|
+
&& Object.values(operation.inputs).includes(lcovInput));
|
|
21
|
+
const steps = plan({ plugins: candidatesOf(changedLines), select: [operation], inputs: phaseInputs(diffCoveragePhases.changedLines) });
|
|
16
22
|
export async function measureDiffCoverage(request, overrides) {
|
|
17
23
|
return (await measureChangedLines(request, overrides)).report;
|
|
18
24
|
}
|
|
@@ -27,10 +33,7 @@ export async function measureChangedLines(request, overrides) {
|
|
|
27
33
|
const result = (await execute(steps, inputs)).get(operation);
|
|
28
34
|
if (!result || result.state !== 'completed')
|
|
29
35
|
throw new Error(result?.reason ?? 'Diff coverage did not run');
|
|
30
|
-
|
|
31
|
-
if (!diffCoverageResult.accepts(value))
|
|
32
|
-
throw new Error('Invalid diff coverage result');
|
|
33
|
-
return value;
|
|
36
|
+
return result.product.value; // execute() checked it against the contract
|
|
34
37
|
},
|
|
35
38
|
...overrides,
|
|
36
39
|
});
|
|
@@ -53,9 +56,9 @@ async function readInputs(request, excludedPaths, excludes) {
|
|
|
53
56
|
source: { extensions, ...(globs.length ? { globs } : {}), excludedDirectories: sourceDirectoriesExcluded, excludedPaths,
|
|
54
57
|
defaultExclusions: defaultSourceExclusions, generatedSourcePolicy, generatedExcluded: snapshot.generatedExcluded ?? [] },
|
|
55
58
|
gitDiff: { ...diffMethod, version: gitVersion },
|
|
56
|
-
lcov: { inputDigest: digest(lcov.text), pathBase: root, merge: 'any-hit', importerVersion:
|
|
59
|
+
lcov: { inputDigest: digest(lcov.text), pathBase: root, merge: 'any-hit', importerVersion: importer.version,
|
|
57
60
|
...(lcov.inputDigests.length > 1 ? { inputDigests: lcov.inputDigests } : {}) },
|
|
58
|
-
plugin: { id:
|
|
61
|
+
plugin: { id: measurer.id, version: measurer.version, api: measurer.api },
|
|
59
62
|
} };
|
|
60
63
|
}
|
|
61
64
|
//# sourceMappingURL=diff-coverage.js.map
|
|
@@ -3,7 +3,7 @@ import type { Outcome } from '../core/engine/execute.js';
|
|
|
3
3
|
import type { CodeStructure } from '../core/model/code-structure.js';
|
|
4
4
|
import type { SourceSnapshot } from '../core/model/source.js';
|
|
5
5
|
import type { AnalysisInput } from '../core/usecases/inspect.js';
|
|
6
|
-
import type { AnalysisSources } from './
|
|
6
|
+
import type { AnalysisSources } from './phases.js';
|
|
7
7
|
import type { LanguageProvider } from './languages.js';
|
|
8
8
|
interface FileResult {
|
|
9
9
|
readonly blob: string;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CoverageInputs } from '../api/import/lcov-files.js';
|
|
2
2
|
import type { OperationCacheOptions } from '../core/engine/operation-cache.js';
|
|
3
3
|
import type { Plugin } from '../core/engine/plugin.js';
|
|
4
4
|
import type { FindingIgnoreRule } from '../core/model/finding-ignore.js';
|
|
5
5
|
import type { Report } from '../core/model/report.js';
|
|
6
6
|
import type { FindingInput } from '../core/model/scanner-import.js';
|
|
7
|
-
import type { AnalysisExecutor, InspectionPorts } from '../core/usecases/inspect.js';
|
|
8
7
|
import type { HistoryCache } from './history-cache.js';
|
|
9
|
-
export
|
|
10
|
-
export type { AnalysisExecutor, AnalysisInput, InspectionPorts } from '../core/usecases/inspect.js';
|
|
11
|
-
export interface InspectRequest {
|
|
8
|
+
export interface InspectRequest extends CoverageInputs {
|
|
12
9
|
readonly directory: string;
|
|
13
10
|
readonly output: string;
|
|
14
11
|
readonly source: {
|
|
@@ -16,18 +13,18 @@ export interface InspectRequest {
|
|
|
16
13
|
} | {
|
|
17
14
|
readonly revision: string;
|
|
18
15
|
};
|
|
19
|
-
readonly lcov?: LcovFiles;
|
|
20
|
-
readonly goCover?: LcovFiles;
|
|
21
16
|
readonly exclude?: readonly string[];
|
|
22
17
|
readonly findingInputs?: readonly FindingInput[];
|
|
23
18
|
readonly findingRoot?: string;
|
|
24
19
|
readonly ignore?: readonly FindingIgnoreRule[];
|
|
25
|
-
/** Trusted in-process plugins
|
|
20
|
+
/** Trusted in-process plugins. */
|
|
26
21
|
readonly plugins?: readonly Plugin[];
|
|
27
22
|
readonly operationCache?: OperationCacheOptions;
|
|
28
23
|
}
|
|
29
|
-
export declare function inspect(request: InspectRequest
|
|
24
|
+
export declare function inspect(request: InspectRequest): Promise<Report>;
|
|
25
|
+
export declare function inspectWithOptions(request: InspectRequest, { history, deferSummary, recordChurn }?: {
|
|
30
26
|
history?: HistoryCache;
|
|
31
27
|
deferSummary?: boolean;
|
|
28
|
+
recordChurn?: boolean;
|
|
32
29
|
}): Promise<Report>;
|
|
33
30
|
export declare function attachFindings(report: Report, inputs: readonly FindingInput[], root: string, findingRoot: string, excludes: (path: string) => boolean): Promise<Report>;
|
|
@@ -2,6 +2,7 @@ import { resolve } from 'node:path';
|
|
|
2
2
|
import { gitTreeFiles } from '../api/git/git.js';
|
|
3
3
|
import { readInspectionSource } from '../api/git/inspection-source.js';
|
|
4
4
|
import { importFindings } from '../api/import/finding-import.js';
|
|
5
|
+
import { hasCoverageInputs } from '../api/import/lcov-files.js';
|
|
5
6
|
import { readInspectionCoverage } from './inspection-coverage.js';
|
|
6
7
|
import { reportSchema } from '../core/model/report.js';
|
|
7
8
|
import { isExcludedDirectory } from '../core/model/snapshot.js';
|
|
@@ -10,22 +11,20 @@ import { LocalReportStore } from '../report/json/store/local-store.js';
|
|
|
10
11
|
import { analyzeSnapshot, inspectionFileMatcher } from './analyze-snapshot.js';
|
|
11
12
|
import { attachChurn } from './attach-churn.js';
|
|
12
13
|
import { languageRegistry } from './languages.js';
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
14
|
+
export function inspect(request) {
|
|
15
|
+
return inspectWithOptions(request);
|
|
16
|
+
}
|
|
17
|
+
export async function inspectWithOptions(request, { history, deferSummary = false, recordChurn = true } = {}) {
|
|
18
|
+
const { findingInputs = [], plugins = [], operationCache } = request;
|
|
19
19
|
const languages = languageRegistry(plugins);
|
|
20
20
|
const claims = inspectionFileMatcher(plugins, languages);
|
|
21
21
|
const { isSource } = languages;
|
|
22
22
|
const ports = {
|
|
23
23
|
readSource: excludes => readSource(request, { excludes, isSource, claims, history: history?.blobs }, deferSummary),
|
|
24
24
|
analyze: input => analyzeSnapshot(input, plugins, operationCache, history),
|
|
25
|
-
...(
|
|
25
|
+
...(hasCoverageInputs(request) ? { readCoverage: source => readInspectionCoverage(request, source) } : {}),
|
|
26
26
|
...(findingInputs.length === 0 ? {} : { importFindings: (report, root, excludes) => attachFindings(report, findingInputs, root, request.findingRoot === undefined ? root : resolve(request.findingRoot), excludes) }),
|
|
27
|
-
recordChurn: (report, root, paths) => attachChurn(report, root, paths.filter(isSource)),
|
|
28
|
-
...(typeof overrides === 'function' ? { analyze: overrides } : overrides),
|
|
27
|
+
recordChurn: recordChurn ? (report, root, paths) => attachChurn(report, root, paths.filter(isSource)) : undefined,
|
|
29
28
|
};
|
|
30
29
|
return executeInspection(request, ports);
|
|
31
30
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FileClaims, Operation, Plugin } from '../core/engine/plugin.js';
|
|
2
2
|
import { fileTypeId } from '../core/model/file-types.js';
|
|
3
|
-
import type { LanguageDisplay } from '../core/model/language.js';
|
|
3
|
+
import type { LanguageDisplay, LanguageSyntax } from '../core/model/language.js';
|
|
4
4
|
import type { NativeLanguagePlugin } from './native-language-plugins.js';
|
|
5
5
|
export interface LanguageProvider {
|
|
6
6
|
readonly plugin: Plugin;
|
|
@@ -13,6 +13,7 @@ export declare const defaultLanguages: {
|
|
|
13
13
|
select(path: string): LanguageProvider | undefined;
|
|
14
14
|
isSource(path: string): boolean;
|
|
15
15
|
id(path: string): string;
|
|
16
|
+
syntax(id: string): LanguageSyntax | undefined;
|
|
16
17
|
readonly extensions: readonly string[];
|
|
17
18
|
readonly globs: readonly string[];
|
|
18
19
|
readonly catalog: readonly LanguageDisplay[];
|
|
@@ -20,10 +21,12 @@ export declare const defaultLanguages: {
|
|
|
20
21
|
readonly native: readonly NativeLanguagePlugin[];
|
|
21
22
|
skipped(path: string): boolean;
|
|
22
23
|
};
|
|
24
|
+
export type LanguageRegistry = ReturnType<typeof languageRegistry>;
|
|
23
25
|
export declare function languageRegistry(plugins: readonly Plugin[], includeNative?: boolean): {
|
|
24
26
|
select(path: string): LanguageProvider | undefined;
|
|
25
27
|
isSource(path: string): boolean;
|
|
26
28
|
id(path: string): string;
|
|
29
|
+
syntax(id: string): LanguageSyntax | undefined;
|
|
27
30
|
readonly extensions: readonly string[];
|
|
28
31
|
readonly globs: readonly string[];
|
|
29
32
|
readonly catalog: readonly LanguageDisplay[];
|
|
@@ -5,7 +5,7 @@ import { isExcludedDirectory } from '../core/model/snapshot.js';
|
|
|
5
5
|
import { exclusionMatcher } from '../core/profile/exclusions.js';
|
|
6
6
|
import { nativeLanguagePlugins } from './native-language-plugins.js';
|
|
7
7
|
import { restrictStructureMeasures } from './structure-measures.js';
|
|
8
|
-
import {
|
|
8
|
+
import { builtInPlugins, hostLanguages } from './built-ins.js';
|
|
9
9
|
export const defaultLanguages = languageRegistry([], false);
|
|
10
10
|
export function languageRegistry(plugins, includeNative = true) {
|
|
11
11
|
const languagePlugins = plugins.filter(plugin => plugin.kinds?.includes('language'));
|
|
@@ -15,7 +15,7 @@ export function languageRegistry(plugins, includeNative = true) {
|
|
|
15
15
|
const unavailable = native.filter(plugin => plugin.unavailableReason !== undefined).flatMap(plugin => plugin.providesLanguages ?? []);
|
|
16
16
|
const skippedClaims = unavailable.map(claim => claimMatcher(claim));
|
|
17
17
|
const enabled = native.filter(plugin => plugin.unavailableReason === undefined);
|
|
18
|
-
const entries = [
|
|
18
|
+
const entries = [...builtInPlugins.filter(plugin => plugin.kinds.includes('language')), ...languagePlugins, ...enabled].map(plugin => {
|
|
19
19
|
const operations = plugin.operations.filter(operation => operation.role === 'provider'
|
|
20
20
|
&& operation.output.id === (operation.scope === 'repository' ? codeStructures.id : codeStructure.id));
|
|
21
21
|
const [operation] = operations;
|
|
@@ -45,13 +45,16 @@ export function languageRegistry(plugins, includeNative = true) {
|
|
|
45
45
|
const extensions = [...new Set(claims.flatMap(entry => entry.extensions ?? []))];
|
|
46
46
|
const globs = [...new Set(claims.flatMap(entry => entry.globs ?? []))];
|
|
47
47
|
const providers = entries.map(({ provider }) => provider);
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
})));
|
|
48
|
+
const declared = providers.flatMap(({ plugin }) => plugin.providesLanguages ?? []);
|
|
49
|
+
const catalog = declared.map(({ id, label, color }) => ({ id, label, ...(color === undefined ? {} : { color }) }));
|
|
50
|
+
const syntaxById = new Map(hostLanguages.map(({ language, syntax }) => [language, syntax]));
|
|
51
|
+
for (const { id, syntax } of declared)
|
|
52
|
+
if (syntax !== undefined)
|
|
53
|
+
syntaxById.set(id, syntax);
|
|
51
54
|
if (new Set(catalog.map(({ id }) => id)).size !== catalog.length)
|
|
52
55
|
throw new Error('Duplicate provided language ID');
|
|
53
56
|
return { select, isSource: path => select(path) !== undefined || skipped(path), id: path => select(path)?.language(path) ?? fileTypeId(path), extensions, globs,
|
|
54
|
-
catalog, providers, native, skipped };
|
|
57
|
+
catalog, providers, native, skipped, syntax: id => syntaxById.get(id) };
|
|
55
58
|
function skipped(path) {
|
|
56
59
|
return skippedClaims.some(matches => matches(path)) && !path.split('/').slice(0, -1).some(isExcludedDirectory);
|
|
57
60
|
}
|
|
@@ -2,5 +2,4 @@ import type { Plugin } from '../core/engine/plugin.js';
|
|
|
2
2
|
export interface NativeLanguagePlugin extends Plugin {
|
|
3
3
|
readonly unavailableReason?: string;
|
|
4
4
|
}
|
|
5
|
-
export declare const nativeLanguageIds: ("go-ast" | "python-ast")[];
|
|
6
5
|
export declare function nativeLanguagePlugins(): readonly NativeLanguagePlugin[];
|
|
@@ -6,25 +6,18 @@ import { bindProcessPlugin } from '../api/process/plugin.js';
|
|
|
6
6
|
import { pluginApi } from '../core/engine/plugin.js';
|
|
7
7
|
import { codeStructures } from '../core/model/code-structure.js';
|
|
8
8
|
import { fileTypes } from '../core/model/file-types.js';
|
|
9
|
+
import { hostLanguages } from './built-ins.js';
|
|
9
10
|
import { duplicationSettings } from '../core/profile/maintainability.js';
|
|
10
11
|
import { digest, sourceFiles } from '../core/model/snapshot.js';
|
|
11
|
-
const measures = ['functions', 'cyclomaticComplexity', 'cognitiveComplexity', 'commentLines', 'codeLines',
|
|
12
|
-
'structuralRules', 'duplication'];
|
|
13
|
-
const descriptors = [
|
|
14
|
-
{ id: 'go-ast', language: 'go', binary: 'go', args: ['run'], versionArgs: ['version'], script: 'go/parser.go', measures },
|
|
15
|
-
{ id: 'python-ast', language: 'python', binary: 'python3', args: ['-I', '-S'], versionArgs: ['--version'],
|
|
16
|
-
script: 'python/parser.py', measures: [...measures, 'classes'] },
|
|
17
|
-
];
|
|
18
|
-
export const nativeLanguageIds = descriptors.map(({ id }) => id);
|
|
19
12
|
let cached;
|
|
20
13
|
export function nativeLanguagePlugins() {
|
|
21
14
|
const path = hostToolPath();
|
|
22
15
|
if (cached?.path !== path)
|
|
23
|
-
cached = { path, plugins:
|
|
16
|
+
cached = { path, plugins: hostLanguages.map(descriptor => createPlugin(descriptor, path)) };
|
|
24
17
|
return cached.plugins;
|
|
25
18
|
}
|
|
26
|
-
function createPlugin({ id, language, binary, args, versionArgs, script, measures }, path) {
|
|
27
|
-
const declaration = { ...fileTypes.find(type => type.id === language), measures };
|
|
19
|
+
function createPlugin({ id, language, binary, args, versionArgs, script, measures, syntax }, path) {
|
|
20
|
+
const declaration = { ...fileTypes.find(type => type.id === language), measures, syntax };
|
|
28
21
|
const manifest = { id, version: '1.1.0', api: pluginApi, kinds: ['language'],
|
|
29
22
|
settings: { duplication: duplicationSettings },
|
|
30
23
|
providesLanguages: [declaration], produces: [{ contract: codeStructures.id, persistence: 'transient' }] };
|