repometry 0.7.0 → 0.8.1
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 +23 -20
- package/package.json +1 -1
- package/target/main/resources/config/process-plugins-v1.schema.json +4 -0
- package/target/main/resources/languages/go/parser.go +602 -0
- package/target/main/resources/languages/python/parser.py +312 -0
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +2 -1
- package/target/main/resources/viewer/files.css +1 -0
- package/target/main/ts/api/git/git-reader.d.ts +10 -2
- package/target/main/ts/api/git/git-reader.js +74 -35
- package/target/main/ts/api/git/git.d.ts +19 -1
- package/target/main/ts/api/git/git.js +97 -7
- package/target/main/ts/api/import/go-cover.d.ts +13 -0
- package/target/main/ts/api/import/go-cover.js +150 -0
- package/target/main/ts/api/import/lcov-files.d.ts +6 -1
- package/target/main/ts/api/import/lcov-files.js +27 -7
- package/target/main/ts/api/process/docker-tool-runner.js +5 -21
- package/target/main/ts/api/process/host-language-runner.d.ts +13 -0
- package/target/main/ts/api/process/host-language-runner.js +176 -0
- package/target/main/ts/api/process/plugin.d.ts +4 -1
- package/target/main/ts/api/process/plugin.js +7 -3
- package/target/main/ts/api/process/tool-snapshot.d.ts +3 -0
- package/target/main/ts/api/process/tool-snapshot.js +26 -0
- package/target/main/ts/cli/imports.d.ts +1 -0
- package/target/main/ts/cli/imports.js +5 -2
- package/target/main/ts/cli/main.js +46 -15
- package/target/main/ts/compose/analysis-files.d.ts +2 -1
- package/target/main/ts/compose/analysis-files.js +19 -5
- package/target/main/ts/compose/analysis-imports.js +2 -1
- package/target/main/ts/compose/analysis-report.d.ts +1 -0
- package/target/main/ts/compose/analysis-report.js +13 -12
- package/target/main/ts/compose/analysis-repository.d.ts +2 -1
- package/target/main/ts/compose/analysis-repository.js +42 -4
- package/target/main/ts/compose/analysis-sources.d.ts +5 -0
- package/target/main/ts/compose/analysis-sources.js +10 -3
- package/target/main/ts/compose/analyze-snapshot.d.ts +2 -1
- package/target/main/ts/compose/analyze-snapshot.js +5 -3
- package/target/main/ts/compose/diff-coverage.d.ts +2 -1
- package/target/main/ts/compose/diff-coverage.js +8 -6
- package/target/main/ts/compose/history-cache.d.ts +29 -0
- package/target/main/ts/compose/history-cache.js +57 -0
- package/target/main/ts/compose/inspect.d.ts +6 -1
- package/target/main/ts/compose/inspect.js +10 -10
- package/target/main/ts/compose/inspection-coverage.d.ts +9 -0
- package/target/main/ts/compose/inspection-coverage.js +9 -0
- package/target/main/ts/compose/languages.d.ts +6 -1
- package/target/main/ts/compose/languages.js +19 -6
- package/target/main/ts/compose/native-language-plugins.d.ts +6 -0
- package/target/main/ts/compose/native-language-plugins.js +40 -0
- package/target/main/ts/compose/plugin-list.d.ts +3 -8
- package/target/main/ts/compose/plugin-list.js +12 -5
- package/target/main/ts/compose/prepare-metabranch.js +1 -1
- package/target/main/ts/compose/process-plugins.js +6 -5
- package/target/main/ts/compose/review.d.ts +1 -2
- package/target/main/ts/compose/review.js +2 -2
- package/target/main/ts/core/engine/plan.js +5 -6
- package/target/main/ts/core/engine/plugin.d.ts +2 -0
- package/target/main/ts/core/model/file-types.d.ts +1 -0
- package/target/main/ts/core/model/file-types.js +14 -3
- package/target/main/ts/core/model/quality-summary.js +2 -0
- package/target/main/ts/core/model/source.d.ts +2 -0
- package/target/main/ts/core/usecases/inspect.d.ts +1 -1
- package/target/main/ts/core/usecases/inspect.js +1 -1
- package/target/main/ts/plugins/security/dockerfile.js +6 -15
- package/target/main/ts/report/html/app/viewer-language-bar.d.ts +2 -0
- package/target/main/ts/report/html/app/viewer-language-bar.js +5 -1
- package/target/main/ts/report/html/app/viewer-profile.js +9 -2
- package/target/main/ts/report/json/projections/commit-summary.d.ts +1 -0
- package/target/main/ts/report/json/projections/commit-summary.js +5 -0
- package/target/main/ts/report/json/projections/file-metrics.js +39 -44
- package/target/main/ts/report/json/projections/inspection-details.js +3 -2
- package/target/main/ts/report/json/store/directory.d.ts +3 -0
- package/target/main/ts/report/json/store/directory.js +19 -0
- package/target/main/ts/report/json/store/local-store.d.ts +14 -2
- package/target/main/ts/report/json/store/local-store.js +74 -60
- package/target/main/ts/report/json/store/object-store.d.ts +14 -0
- package/target/main/ts/report/json/store/object-store.js +73 -0
- package/target/main/ts/report/json/store/report-tree.d.ts +46 -0
- package/target/main/ts/report/json/store/report-tree.js +290 -0
- package/target/main/ts/report/json/store/store-check.d.ts +32 -0
- package/target/main/ts/report/json/store/store-check.js +144 -0
- package/target/main/ts/report/json/validation/report.d.ts +6 -1
- package/target/main/ts/report/json/validation/report.js +10 -4
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +1 -0
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { lstat, readFile } from 'node:fs/promises';
|
|
2
|
+
import { lstat, readFile, realpath } from 'node:fs/promises';
|
|
3
3
|
import { join, resolve } from 'node:path';
|
|
4
4
|
import { firstParentRange, gitRoot, resolveGitCommit } from '../api/git/git.js';
|
|
5
|
+
import { gitReportObjects } from '../api/git/git-reader.js';
|
|
5
6
|
import { resolveGitBranch } from '../api/git/commit-metadata.js';
|
|
6
7
|
import { clearSourceCache, sourceCacheRoot } from '../api/git/source-cache.js';
|
|
7
8
|
import { writeGitHubDiffCoverage, writeGitHubResult, writeGitHubReview } from '../api/gh/github.js';
|
|
8
9
|
import { remoteExecutor } from '../api/worker/remote-executor.js';
|
|
9
10
|
import { serveWorker } from '../api/worker/worker.js';
|
|
10
11
|
import { workerToken } from '../api/worker/worker-protocol.js';
|
|
11
|
-
import {
|
|
12
|
+
import { HistoryCache } from '../compose/history-cache.js';
|
|
13
|
+
import { defaultLanguages, languageRegistry } from '../compose/languages.js';
|
|
12
14
|
import { analyzeSnapshot, attachFindings, inspect } from '../compose/inspect.js';
|
|
13
15
|
import { measureDiffCoverage } from '../compose/diff-coverage.js';
|
|
14
16
|
import { prepareMetabranch } from '../compose/prepare-metabranch.js';
|
|
15
17
|
import { reviewExitCode, reviewPull } from '../compose/review.js';
|
|
16
|
-
import {
|
|
18
|
+
import { effectivePlugins } from '../compose/plugin-list.js';
|
|
17
19
|
import { isRecord } from '../core/engine/plugin.js';
|
|
18
20
|
import { validSubjectId } from '../core/model/report.js';
|
|
19
21
|
import { sourceExclusionMatcher } from '../core/profile/exclusions.js';
|
|
20
22
|
import { compareInspections } from '../core/usecases/compare.js';
|
|
21
23
|
import { exportProjects } from '../report/html/site/projects.js';
|
|
22
24
|
import { fileMetrics } from '../report/json/projections/file-metrics.js';
|
|
25
|
+
import { LocalReportStore } from '../report/json/store/local-store.js';
|
|
23
26
|
import { savePullReview } from '../report/json/store/pull-review-store.js';
|
|
27
|
+
import { LocalObjectStore } from '../report/json/store/object-store.js';
|
|
28
|
+
import { checkStore } from '../report/json/store/store-check.js';
|
|
24
29
|
import { dispatch, flag, option } from './arguments.js';
|
|
25
30
|
import { readConfig } from './config.js';
|
|
26
31
|
import { importerIds, readInputs } from './imports.js';
|
|
@@ -119,7 +124,7 @@ const commands = {
|
|
|
119
124
|
async run(input) {
|
|
120
125
|
const { root } = await context(input);
|
|
121
126
|
const config = await readConfig(root, input);
|
|
122
|
-
print({ schema: 'urn:repometry:schema:plugin-list:1', plugins:
|
|
127
|
+
print({ schema: 'urn:repometry:schema:plugin-list:1', plugins: effectivePlugins(config.plugins),
|
|
123
128
|
importers: importerIds, reporters: reporterIds, ci: ['github'], stores: ['local', 'git'] });
|
|
124
129
|
},
|
|
125
130
|
},
|
|
@@ -138,13 +143,34 @@ const commands = {
|
|
|
138
143
|
print({ schema: 'urn:repometry:schema:cache-result:1', path, ...(action === 'clear' ? { cleared: ['sources'] } : {}) });
|
|
139
144
|
},
|
|
140
145
|
},
|
|
146
|
+
store: {
|
|
147
|
+
description: 'Check saved inspections and repair what can be restored.', parameters: 'check', min: 1, max: 1,
|
|
148
|
+
options: {
|
|
149
|
+
repair: flag('Restore missing data from a copy.'),
|
|
150
|
+
from: option('PATH|git:REF', 'The copy: another store or a storage branch.'),
|
|
151
|
+
},
|
|
152
|
+
async run(input) {
|
|
153
|
+
if (input.args[0] !== 'check')
|
|
154
|
+
throw new Error('Use store check');
|
|
155
|
+
const from = input.text('from');
|
|
156
|
+
if (from !== undefined && !input.flag('repair'))
|
|
157
|
+
throw new Error('--from requires --repair');
|
|
158
|
+
const { directory, root, store } = await context(input);
|
|
159
|
+
const path = writableStore(store);
|
|
160
|
+
const source = from === undefined ? undefined
|
|
161
|
+
: from.startsWith('git:') ? await gitReportObjects(root, from.slice(4)) : new LocalObjectStore(resolve(directory, from)).source();
|
|
162
|
+
const result = await checkStore(path, input.flag('repair') ? { from: source } : undefined);
|
|
163
|
+
print({ ...result, store: path });
|
|
164
|
+
return result.problems.length ? 1 : 0;
|
|
165
|
+
},
|
|
166
|
+
},
|
|
141
167
|
worker: { description: 'Run the remote analysis worker.',
|
|
142
168
|
options: { port: option('PORT', 'Listen on this port.'), listen: option('ADDRESS', 'Listen on 127.0.0.1 or 0.0.0.0.') },
|
|
143
169
|
async run(input) {
|
|
144
170
|
const host = input.text('listen') ?? '127.0.0.1';
|
|
145
171
|
if (host !== '127.0.0.1' && host !== '0.0.0.0')
|
|
146
172
|
throw new Error('--listen must be 127.0.0.1 or 0.0.0.0');
|
|
147
|
-
announce(await serveWorker(host, port(input.text('port') ?? '7331'), workerToken(), analyzeSnapshot,
|
|
173
|
+
announce(await serveWorker(host, port(input.text('port') ?? '7331'), workerToken(), analyzeSnapshot, languageRegistry([]).isSource));
|
|
148
174
|
} },
|
|
149
175
|
};
|
|
150
176
|
async function context(input) {
|
|
@@ -167,7 +193,7 @@ async function analyze(input) {
|
|
|
167
193
|
const branch = input.text('branch') ?? config.branch;
|
|
168
194
|
const revision = input.args[0] ?? (!input.flag('working-tree') && branch !== undefined ? await resolveGitBranch(root, branch) : 'HEAD');
|
|
169
195
|
const imports = input.many('import');
|
|
170
|
-
const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
196
|
+
const { lcov, goCover, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
171
197
|
const importRoot = input.text('import-root');
|
|
172
198
|
if (importRoot && findings.length === 0)
|
|
173
199
|
throw new Error('--import-root requires a scanner report');
|
|
@@ -176,7 +202,7 @@ async function analyze(input) {
|
|
|
176
202
|
const skipped = savedId !== undefined && await isSaved(output, savedId);
|
|
177
203
|
const report = skipped ? await store.reader.read({ kind: 'commit', id: savedId })
|
|
178
204
|
: await inspect({ directory, output, source: input.flag('working-tree') ? { workingTree: true } : { revision },
|
|
179
|
-
lcov, exclude: [...config.exclude, ...input.many('exclude')], ignore: config.ignore, plugins: config.plugins,
|
|
205
|
+
lcov, goCover, exclude: [...config.exclude, ...input.many('exclude')], ignore: config.ignore, plugins: config.plugins,
|
|
180
206
|
findingInputs: findings, findingRoot: importRoot ? resolve(directory, importRoot) : undefined }, executor);
|
|
181
207
|
if (github)
|
|
182
208
|
await writeGitHubResult(report);
|
|
@@ -205,10 +231,15 @@ async function analyzeRange(input, range) {
|
|
|
205
231
|
process.stderr.write(`No commits in ${range.base}..${range.head}.\n`);
|
|
206
232
|
const executor = analysisExecutor(input, config.plugins);
|
|
207
233
|
const exclude = [...config.exclude, ...input.many('exclude')];
|
|
234
|
+
const { plugins, ...profile } = config;
|
|
235
|
+
const history = executor === undefined ? new HistoryCache(profile) : undefined;
|
|
208
236
|
const inspectCommit = (id) => inspect({ directory, output, source: { revision: id }, exclude,
|
|
209
|
-
ignore: config.ignore, plugins
|
|
237
|
+
ignore: config.ignore, plugins }, executor, { history, deferSummary: true });
|
|
210
238
|
const skip = input.flag('skip-saved') ? (id) => isSaved(output, id) : undefined;
|
|
211
239
|
const { interrupted, ...results } = await analyzeCommits(commits, inspectCommit, skip);
|
|
240
|
+
if (results.analyzed.length || results.skipped.length) {
|
|
241
|
+
await new LocalReportStore(await realpath(output)).refreshSummary();
|
|
242
|
+
}
|
|
212
243
|
const requested = input.many('report');
|
|
213
244
|
const reports = interrupted ? [] : await outputReports(root, store, requested.length ? requested : config.reports, input, config);
|
|
214
245
|
print({ schema: 'urn:repometry:schema:analyze-range:1', range: `${base}..${head}`,
|
|
@@ -259,7 +290,7 @@ function analysisExecutor(input, plugins) {
|
|
|
259
290
|
return undefined;
|
|
260
291
|
if (plugins.length)
|
|
261
292
|
throw new Error('Configured process plugins require local analysis. Use --no-config with --worker.');
|
|
262
|
-
return remoteExecutor(worker, workerToken(),
|
|
293
|
+
return remoteExecutor(worker, workerToken(), languageRegistry([]).isSource);
|
|
263
294
|
}
|
|
264
295
|
async function isSaved(store, id) {
|
|
265
296
|
try {
|
|
@@ -300,10 +331,10 @@ async function diffCoverage(input) {
|
|
|
300
331
|
const { directory, root } = await context(input);
|
|
301
332
|
const config = await readConfig(root, input);
|
|
302
333
|
const imports = input.many('import');
|
|
303
|
-
const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
304
|
-
if (!lcov || (imports.length && findings.length))
|
|
305
|
-
throw new Error('diff-coverage requires --import lcov=PATH');
|
|
306
|
-
const report = await measureDiffCoverage({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, plugins: config.plugins,
|
|
334
|
+
const { lcov, goCover, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
335
|
+
if ((!lcov && !goCover) || (imports.length && findings.length))
|
|
336
|
+
throw new Error('diff-coverage requires --import lcov=PATH or go-cover=PATH');
|
|
337
|
+
const report = await measureDiffCoverage({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, goCover, plugins: config.plugins,
|
|
307
338
|
exclude: [...config.exclude, ...input.many('exclude')], minimumPercent: percent(input.text('min-coverage') ?? config.minCoverage, '--min-coverage') });
|
|
308
339
|
if (useGitHub(input))
|
|
309
340
|
await writeGitHubDiffCoverage(report);
|
|
@@ -317,7 +348,7 @@ async function review(input) {
|
|
|
317
348
|
throw new Error('--annotations requires --ci github');
|
|
318
349
|
const config = await readConfig(root, input);
|
|
319
350
|
const imports = input.many('import');
|
|
320
|
-
const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
351
|
+
const { lcov, goCover, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
321
352
|
const baselinePath = input.text('baseline-store');
|
|
322
353
|
const baseline = baselinePath === undefined ? store : selectStore(root, baselinePath, directory);
|
|
323
354
|
const exclude = [...config.exclude, ...input.many('exclude')];
|
|
@@ -332,7 +363,7 @@ async function review(input) {
|
|
|
332
363
|
},
|
|
333
364
|
} : store.reader;
|
|
334
365
|
const number = count(input.text('pull'), '--pull', 1);
|
|
335
|
-
const report = await reviewPull({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, exclude, number, plugins: config.plugins,
|
|
366
|
+
const report = await reviewPull({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, goCover, exclude, number, plugins: config.plugins,
|
|
336
367
|
minimumPercent: percent(input.text('min-coverage') ?? config.minCoverage, '--min-coverage'),
|
|
337
368
|
minimumLines: count(input.text('min-lines') ?? config.minLines, '--min-lines'),
|
|
338
369
|
maxCoverageDrop: percent(input.text('max-coverage-drop') ?? config.maxCoverageDrop, '--max-coverage-drop'),
|
|
@@ -5,10 +5,11 @@ import type { CodeStructure } from '../core/model/code-structure.js';
|
|
|
5
5
|
import type { SourceLineRange } from '../core/model/source.js';
|
|
6
6
|
import type { AnalysisResults } from './analysis-results.js';
|
|
7
7
|
import type { AnalysisSources } from './analysis-sources.js';
|
|
8
|
+
import type { HistoryFiles } from './history-cache.js';
|
|
8
9
|
export declare const defaultFilePlan: readonly PlannedOperation[];
|
|
9
10
|
export interface FileAnalysis {
|
|
10
11
|
readonly cloneSources: readonly CloneSource[];
|
|
11
12
|
readonly codeLines: ReadonlyMap<string, ReadonlySet<number>>;
|
|
12
13
|
readonly functionBodies: ReadonlyMap<string, readonly SourceLineRange[]>;
|
|
13
14
|
}
|
|
14
|
-
export declare function inspectFiles(sources: AnalysisSources, batchFacts: ReadonlyMap<string, CodeStructure>, results: AnalysisResults, withCoverage: boolean, cache?: OperationCacheOptions): Promise<FileAnalysis>;
|
|
15
|
+
export declare function inspectFiles(sources: AnalysisSources, batchFacts: ReadonlyMap<string, CodeStructure>, results: AnalysisResults, withCoverage: boolean, cache?: OperationCacheOptions, history?: HistoryFiles): Promise<FileAnalysis>;
|
|
@@ -6,12 +6,13 @@ import { isClaimedText, maxClaimedFileBytes } from '../core/model/source.js';
|
|
|
6
6
|
import { fileQuality } from '../plugins/maintainability/maintainability.js';
|
|
7
7
|
import { oversizedClaim } from './analysis-results.js';
|
|
8
8
|
import { defaultProvider, inspectionKeys, pluginForScope, structuralInspections } from './analysis-sources.js';
|
|
9
|
+
import { canReuseBatch } from './history-cache.js';
|
|
9
10
|
import { unmeasuredStructure } from './structure-measures.js';
|
|
10
11
|
const standardInspections = ['structure/size', 'structure/complexity', 'maintainability/file'];
|
|
11
12
|
const fileInput = new Map([['file', sourceFile.id]]);
|
|
12
13
|
const batchFileInput = new Map([...fileInput, ['syntax', codeStructure.id]]);
|
|
13
14
|
export const defaultFilePlan = filePlan(defaultProvider, []);
|
|
14
|
-
export async function inspectFiles(sources, batchFacts, results, withCoverage, cache) {
|
|
15
|
+
export async function inspectFiles(sources, batchFacts, results, withCoverage, cache, history) {
|
|
15
16
|
const plans = new Map([[filePlanKey(defaultProvider, []), defaultFilePlan]]);
|
|
16
17
|
const cloneSources = [];
|
|
17
18
|
const codeLines = new Map();
|
|
@@ -23,10 +24,8 @@ export async function inspectFiles(sources, batchFacts, results, withCoverage, c
|
|
|
23
24
|
continue;
|
|
24
25
|
const tasks = findFilePlan(provider, plugins, plans, results);
|
|
25
26
|
const facts = batchFacts.get(file.path);
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
products.set('syntax', { contract: codeStructure.id, value: facts });
|
|
29
|
-
const outcomes = await execute(tasks, products, cache);
|
|
27
|
+
const reusable = provider?.batch && (!facts || !canReuseBatch(provider)) ? undefined : history;
|
|
28
|
+
const outcomes = await fileOutcomes(source, tasks, facts, cache, reusable);
|
|
30
29
|
const syntax = provider && outcomes.get(provider.key);
|
|
31
30
|
const parsed = recordFileSyntax(source, syntax, facts, results, withCoverage);
|
|
32
31
|
if (withCoverage && parsed) {
|
|
@@ -40,6 +39,21 @@ export async function inspectFiles(sources, batchFacts, results, withCoverage, c
|
|
|
40
39
|
}
|
|
41
40
|
return { cloneSources, codeLines, functionBodies };
|
|
42
41
|
}
|
|
42
|
+
async function fileOutcomes({ file }, tasks, facts, cache, history) {
|
|
43
|
+
const saved = history?.read(file.path)?.outcomes;
|
|
44
|
+
if (saved) {
|
|
45
|
+
history?.retain(file.path, { outcomes: saved });
|
|
46
|
+
return saved;
|
|
47
|
+
}
|
|
48
|
+
const products = new Map([['file', { contract: sourceFile.id, value: file }]]);
|
|
49
|
+
if (facts)
|
|
50
|
+
products.set('syntax', { contract: codeStructure.id, value: facts });
|
|
51
|
+
const outcomes = await execute(tasks, products, cache);
|
|
52
|
+
if (history && [...outcomes.values()].every(outcome => outcome.state === 'completed' && !outcome.diagnostics?.length)) {
|
|
53
|
+
history.retain(file.path, { outcomes });
|
|
54
|
+
}
|
|
55
|
+
return outcomes;
|
|
56
|
+
}
|
|
43
57
|
function matchedInspections({ file }, sources, results) {
|
|
44
58
|
const claimed = sources.perFile.filter(({ matches }) => matches(file.path));
|
|
45
59
|
if (claimed.length && file.bytes.byteLength > maxClaimedFileBytes)
|
|
@@ -17,9 +17,10 @@ export async function importAnalysisCoverage({ coverage: input, excludedPaths =
|
|
|
17
17
|
if (input === undefined)
|
|
18
18
|
return;
|
|
19
19
|
const unclassified = new Set([...results.unmeasured].filter(([, missing]) => missing.includes('codeLines')).map(([path]) => path));
|
|
20
|
+
const excludes = sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded);
|
|
20
21
|
const value = { text: input.text, root: input.sourceRoot, sourceLines: sourceLineCounts(sources.sourceFiles),
|
|
21
22
|
codeLines: files.codeLines, unclassified, functionBodies: files.functionBodies,
|
|
22
|
-
excludes:
|
|
23
|
+
excludes: (path) => excludes(path) || sources.unavailableFiles.has(path) };
|
|
23
24
|
const outcomes = await execute(coveragePlan, new Map([['lcov', { contract: lcovInput.id, value }]]), cache);
|
|
24
25
|
for (const task of coveragePlan) {
|
|
25
26
|
results.remember(task);
|
|
@@ -2,4 +2,5 @@ import type { Report } from '../core/model/report.js';
|
|
|
2
2
|
import type { AnalysisInput } from '../core/usecases/inspect.js';
|
|
3
3
|
import type { AnalysisResults } from './analysis-results.js';
|
|
4
4
|
import type { AnalysisSources } from './analysis-sources.js';
|
|
5
|
+
export declare const analysisProfile = "repository/v3";
|
|
5
6
|
export declare function assembleAnalysisReport(input: AnalysisInput, sources: AnalysisSources, results: AnalysisResults): Report;
|
|
@@ -6,14 +6,15 @@ import { defaultSourceExclusions, generatedSourcePolicy } from '../core/profile/
|
|
|
6
6
|
import { duplicationSettings, structuralRules } from '../core/profile/maintainability.js';
|
|
7
7
|
import { defaultProvider } from './analysis-sources.js';
|
|
8
8
|
import { fileTypeId } from '../core/model/file-types.js';
|
|
9
|
+
export const analysisProfile = 'repository/v3';
|
|
9
10
|
const measurementDefinitions = {
|
|
10
11
|
[definitions.lines]: 'Physical lines including blank lines and comments. A final line terminator does not add a line.',
|
|
11
|
-
[definitions.functions]: '
|
|
12
|
-
[definitions.complexity]: 'One plus
|
|
12
|
+
[definitions.functions]: 'Functions, methods and function literals recognized by the language provider, including nested functions.',
|
|
13
|
+
[definitions.complexity]: 'One plus decision points in the function body. The language provider defines its decision rules and column units. Nested functions are measured separately.',
|
|
13
14
|
[definitions.coverage]: 'Distinct covered lines divided by the distinct lines listed in LCOV DA records, filtered to code where classifications are available. Hit counts are summed across records. A zero denominator has no ratio.',
|
|
14
|
-
[definitions.codeLines]: 'Nonblank physical lines after removing
|
|
15
|
-
[definitions.comments]: 'Physical lines containing only a
|
|
16
|
-
[definitions.classes]: '
|
|
15
|
+
[definitions.codeLines]: 'Nonblank physical lines after removing comment spans and the interpreter directive. A line containing both code and a comment counts as code.',
|
|
16
|
+
[definitions.comments]: 'Physical lines containing only a comment or interpreter directive.',
|
|
17
|
+
[definitions.classes]: 'Class declarations and expressions recognized by the language provider.',
|
|
17
18
|
[definitions.cognitiveComplexity]: 'Flow breaks plus nesting weight and logical operator sequences. Nested functions are measured separately. File complexity sums functions and module-level flow breaks.',
|
|
18
19
|
[definitions.duplicatedLines]: 'Distinct code lines inside repeated Babel syntax subtrees, including original and repeated occurrences. Identifier and literal spellings are ignored for similar-code matches.',
|
|
19
20
|
};
|
|
@@ -29,7 +30,7 @@ export function assembleAnalysisReport(input, sources, results) {
|
|
|
29
30
|
definitions: { ...Object.fromEntries((pluginData?.metrics ?? []).map(metric => [metric.id, metric.description ?? metric.label])),
|
|
30
31
|
...measurementDefinitions },
|
|
31
32
|
scope: { files: fileCount, parsed: results.parsed.size },
|
|
32
|
-
status: inspectionStatus(fileCount, results),
|
|
33
|
+
status: inspectionStatus(fileCount > 0 || sources.unavailableFiles.size > 0, results),
|
|
33
34
|
measurements: results.measurements,
|
|
34
35
|
diagnostics: results.diagnostics,
|
|
35
36
|
findings: results.findings,
|
|
@@ -41,7 +42,7 @@ export function assembleAnalysisReport(input, sources, results) {
|
|
|
41
42
|
function appliedConfiguration({ snapshot, excludedOutput, excludedPaths = [], coverage }, { languages, claimedPlugins, plugins }, results) {
|
|
42
43
|
const securityScanners = results.securityScanners(claimedPlugins);
|
|
43
44
|
return {
|
|
44
|
-
profile:
|
|
45
|
+
profile: analysisProfile, mode: snapshot.subject.kind,
|
|
45
46
|
source: { extensions: languages.extensions, ...(languages.globs.length ? { globs: languages.globs } : {}),
|
|
46
47
|
excludedDirectories: sourceDirectoriesExcluded, excludedOutput, excludedPaths,
|
|
47
48
|
defaultExclusions: defaultSourceExclusions, generatedSourcePolicy, generatedExcluded: snapshot.generatedExcluded ?? [] },
|
|
@@ -51,19 +52,19 @@ function appliedConfiguration({ snapshot, excludedOutput, excludedPaths = [], co
|
|
|
51
52
|
merge: 'any-hit', hitCounts: 'sum',
|
|
52
53
|
lines: [...results.unmeasured.values()].some(measures => measures.includes('codeLines')) ? 'code-when-classified' : 'code-only' },
|
|
53
54
|
...(securityScanners.length ? { securityScanners } : {}),
|
|
54
|
-
plugins: plugins.map(pluginProvenance),
|
|
55
|
+
plugins: [...plugins, ...languages.native.filter(plugin => plugin.unavailableReason !== undefined)].map(pluginProvenance),
|
|
55
56
|
operations: results.operationRecords(),
|
|
56
57
|
};
|
|
57
58
|
}
|
|
58
|
-
function pluginProvenance({ id, version, api, tools, kinds, claims, settings, providesLanguages }) {
|
|
59
|
+
function pluginProvenance({ id, version, api, tools, kinds, claims, settings, providesLanguages, unavailableReason }) {
|
|
59
60
|
return { id, version, api, tools: tools ?? {}, kinds,
|
|
60
61
|
...(claims === undefined ? {} : { claims }), ...(settings === undefined ? {} : { settings }),
|
|
61
|
-
...(providesLanguages === undefined ? {} : { providesLanguages }) };
|
|
62
|
+
...(providesLanguages === undefined ? {} : { providesLanguages }), ...(unavailableReason === undefined ? {} : { unavailableReason }) };
|
|
62
63
|
}
|
|
63
|
-
function inspectionStatus(
|
|
64
|
+
function inspectionStatus(hasSources, results) {
|
|
64
65
|
if (results.diagnostics.length > 0)
|
|
65
66
|
return 'partial';
|
|
66
|
-
return
|
|
67
|
+
return !hasSources && !results.completedInspection ? 'not-applicable' : 'complete';
|
|
67
68
|
}
|
|
68
69
|
function reportInventory(snapshot, sources, results) {
|
|
69
70
|
const inventory = new Map((snapshot.inventory ?? []).map(({ path, lines, bytes }) => [path, { lines, bytes }]));
|
|
@@ -2,5 +2,6 @@ import type { OperationCacheOptions } from '../core/engine/operation-cache.js';
|
|
|
2
2
|
import type { CodeStructure } from '../core/model/code-structure.js';
|
|
3
3
|
import type { AnalysisResults } from './analysis-results.js';
|
|
4
4
|
import type { AnalysisSources } from './analysis-sources.js';
|
|
5
|
-
|
|
5
|
+
import type { HistoryFiles } from './history-cache.js';
|
|
6
|
+
export declare function collectRepositorySyntax(sources: AnalysisSources, results: AnalysisResults, cache?: OperationCacheOptions, history?: HistoryFiles): Promise<Map<string, CodeStructure>>;
|
|
6
7
|
export declare function inspectRepositories(sources: AnalysisSources, results: AnalysisResults, cache?: OperationCacheOptions): Promise<void>;
|
|
@@ -4,8 +4,9 @@ import { codeStructures } from '../core/model/code-structure.js';
|
|
|
4
4
|
import { sourceFiles } from '../core/model/snapshot.js';
|
|
5
5
|
import { isClaimedText } from '../core/model/source.js';
|
|
6
6
|
import { inspectionKeys } from './analysis-sources.js';
|
|
7
|
+
import { canReuseBatch } from './history-cache.js';
|
|
7
8
|
const repositoryInput = new Map([['files', sourceFiles.id]]);
|
|
8
|
-
export async function collectRepositorySyntax(sources, results, cache) {
|
|
9
|
+
export async function collectRepositorySyntax(sources, results, cache, history) {
|
|
9
10
|
const providers = new Map(sources.languages.providers.filter(provider => provider.batch).map(provider => [provider.plugin.id, provider]));
|
|
10
11
|
const facts = new Map();
|
|
11
12
|
for (const { plugin } of sources.repository) {
|
|
@@ -15,7 +16,8 @@ export async function collectRepositorySyntax(sources, results, cache) {
|
|
|
15
16
|
const files = sources.sources.filter(source => source.provider === provider).map(({ file }) => file);
|
|
16
17
|
if (!files.length)
|
|
17
18
|
continue;
|
|
18
|
-
const
|
|
19
|
+
const reusable = canReuseBatch(provider) ? history : undefined;
|
|
20
|
+
const outcomes = await runRepository(plugin, files, [provider.key, ...inspectionKeys(plugin)], results, cache, reusable);
|
|
19
21
|
const syntax = outcomes.get(provider.key);
|
|
20
22
|
if (syntax?.state === 'completed' && codeStructures.accepts(syntax.product.value)) {
|
|
21
23
|
collectFacts(facts, syntax.product.value, files, provider.key, results);
|
|
@@ -35,9 +37,10 @@ export async function inspectRepositories(sources, results, cache) {
|
|
|
35
37
|
await runRepository(plugin, files, select, results, cache);
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
|
-
async function runRepository(plugin, files, select, results, cache) {
|
|
40
|
+
async function runRepository(plugin, files, select, results, cache, history) {
|
|
39
41
|
const tasks = plan({ plugins: [plugin], select, inputs: repositoryInput });
|
|
40
|
-
const outcomes =
|
|
42
|
+
const outcomes = history && tasks.length === 1
|
|
43
|
+
? await runIndependentProvider(tasks[0], files, history, cache) : await executeRepository(tasks, files, cache);
|
|
41
44
|
const paths = files.map(({ path }) => path);
|
|
42
45
|
for (const task of tasks) {
|
|
43
46
|
results.remember(task);
|
|
@@ -45,6 +48,41 @@ async function runRepository(plugin, files, select, results, cache) {
|
|
|
45
48
|
}
|
|
46
49
|
return outcomes;
|
|
47
50
|
}
|
|
51
|
+
function executeRepository(tasks, files, cache) {
|
|
52
|
+
return execute(tasks, new Map([['files', { contract: sourceFiles.id, value: files }]]), cache);
|
|
53
|
+
}
|
|
54
|
+
async function runIndependentProvider(task, files, history, cache) {
|
|
55
|
+
const saved = new Map(files.flatMap(({ path }) => {
|
|
56
|
+
const syntax = history.read(path)?.syntax;
|
|
57
|
+
return syntax === undefined ? [] : [[path, syntax]];
|
|
58
|
+
}));
|
|
59
|
+
const missing = files.filter(({ path }) => !saved.has(path));
|
|
60
|
+
const outcomes = missing.length === 0 ? undefined : await executeRepository([task], missing, cache);
|
|
61
|
+
const fresh = outcomes === undefined ? [] : successfulBatch(outcomes.get(task.key), missing);
|
|
62
|
+
// Preserve complete-batch diagnostics if an incremental run produces incomplete facts or a warning.
|
|
63
|
+
if (!fresh)
|
|
64
|
+
return saved.size ? executeRepository([task], files, cache) : outcomes;
|
|
65
|
+
for (const syntax of fresh)
|
|
66
|
+
saved.set(syntax.path, syntax);
|
|
67
|
+
const values = files.map(({ path }) => saved.get(path));
|
|
68
|
+
const { output } = task.operation;
|
|
69
|
+
if (missing.length !== files.length && (!output.accepts(values) || (task.validateOutput && !task.validateOutput(values)))) {
|
|
70
|
+
return executeRepository([task], files, cache);
|
|
71
|
+
}
|
|
72
|
+
for (const syntax of values)
|
|
73
|
+
history.retain(syntax.path, { syntax });
|
|
74
|
+
return missing.length === files.length ? outcomes : new Map([[task.key, {
|
|
75
|
+
state: 'completed', product: { contract: output.id, value: values },
|
|
76
|
+
}]]);
|
|
77
|
+
}
|
|
78
|
+
function successfulBatch(outcome, files) {
|
|
79
|
+
if (outcome?.state !== 'completed' || outcome.diagnostics?.length || !codeStructures.accepts(outcome.product.value))
|
|
80
|
+
return;
|
|
81
|
+
const values = outcome.product.value;
|
|
82
|
+
const paths = new Set(files.map(({ path }) => path));
|
|
83
|
+
if (values.length === paths.size && values.every(({ path }) => paths.has(path)))
|
|
84
|
+
return values;
|
|
85
|
+
}
|
|
48
86
|
function collectFacts(target, values, files, operation, results) {
|
|
49
87
|
const planned = new Set(files.map(({ path }) => path));
|
|
50
88
|
if (values.some(({ path }) => !planned.has(path))) {
|
|
@@ -19,6 +19,8 @@ export declare function inspectionFileMatcher(additional: readonly Plugin[], lan
|
|
|
19
19
|
readonly globs: readonly string[];
|
|
20
20
|
readonly catalog: readonly import("../plugin.js").LanguageDisplay[];
|
|
21
21
|
readonly providers: readonly LanguageProvider[];
|
|
22
|
+
readonly native: readonly import("./native-language-plugins.js").NativeLanguagePlugin[];
|
|
23
|
+
skipped(path: string): boolean;
|
|
22
24
|
}): (path: string) => boolean;
|
|
23
25
|
export declare function selectAnalysisSources(snapshot: SourceSnapshot, additional: readonly Plugin[], withCoverage: boolean): {
|
|
24
26
|
languages: {
|
|
@@ -29,9 +31,12 @@ export declare function selectAnalysisSources(snapshot: SourceSnapshot, addition
|
|
|
29
31
|
readonly globs: readonly string[];
|
|
30
32
|
readonly catalog: readonly import("../plugin.js").LanguageDisplay[];
|
|
31
33
|
readonly providers: readonly LanguageProvider[];
|
|
34
|
+
readonly native: readonly import("./native-language-plugins.js").NativeLanguagePlugin[];
|
|
35
|
+
skipped(path: string): boolean;
|
|
32
36
|
};
|
|
33
37
|
sources: SelectedSource[];
|
|
34
38
|
sourceFiles: SourceFile[];
|
|
39
|
+
unavailableFiles: Set<string>;
|
|
35
40
|
providersByPath: Map<string, LanguageProvider>;
|
|
36
41
|
plugins: Plugin[];
|
|
37
42
|
claimedPlugins: Plugin[];
|
|
@@ -13,17 +13,24 @@ export function inspectionFileMatcher(additional, languages = defaultLanguages)
|
|
|
13
13
|
return path => matches.some(match => match(path));
|
|
14
14
|
}
|
|
15
15
|
export function selectAnalysisSources(snapshot, additional, withCoverage) {
|
|
16
|
-
const languages =
|
|
16
|
+
const languages = languageRegistry(additional);
|
|
17
17
|
const sources = snapshot.files.map(file => ({ file, provider: languages.select(file.path) }));
|
|
18
18
|
const providersByPath = new Map(sources.flatMap(({ file, provider }) => provider ? [[file.path, provider]] : []));
|
|
19
|
+
const unavailableFiles = new Set(sources.filter(({ file, provider }) => !provider && languages.skipped(file.path))
|
|
20
|
+
.map(({ file }) => file.path));
|
|
19
21
|
const sourceFiles = sources.flatMap(({ file, provider }) => provider ? [file] : []);
|
|
20
22
|
const bound = new Map(languages.providers.map(({ plugin }) => [plugin.id, plugin]));
|
|
21
|
-
const
|
|
23
|
+
const native = languages.native.flatMap(({ id }) => {
|
|
24
|
+
const plugin = bound.get(id);
|
|
25
|
+
return plugin ? [plugin] : [];
|
|
26
|
+
});
|
|
27
|
+
const claimedPlugins = [...securityPlugins.filter(plugin => !additional.includes(plugin)), ...native,
|
|
28
|
+
...additional.map(plugin => bound.get(plugin.id) ?? plugin)];
|
|
22
29
|
const plugins = [defaultProvider.plugin, ...structuralInspections, duplication, ...(withCoverage ? [coverage] : []), ...claimedPlugins];
|
|
23
30
|
validateRegistration(plugins, additional, withCoverage);
|
|
24
31
|
const claims = claimedPlugins.map(plugin => ({ plugin, matches: plugin.kinds.includes('language')
|
|
25
32
|
? path => providersByPath.get(path)?.plugin.id === plugin.id : claimMatcher(plugin.claims, languages.id) }));
|
|
26
|
-
return { languages, sources, sourceFiles, providersByPath, plugins, claimedPlugins,
|
|
33
|
+
return { languages, sources, sourceFiles, unavailableFiles, providersByPath, plugins, claimedPlugins,
|
|
27
34
|
perFile: claimsForScope(claims, 'file'), repository: claimsForScope(claims, 'repository') };
|
|
28
35
|
}
|
|
29
36
|
function validateRegistration(plugins, additional, withCoverage) {
|
|
@@ -2,5 +2,6 @@ import type { OperationCacheOptions } from '../core/engine/operation-cache.js';
|
|
|
2
2
|
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
|
+
import type { HistoryCache } from './history-cache.js';
|
|
5
6
|
export { inspectionFileMatcher } from './analysis-sources.js';
|
|
6
|
-
export declare function analyzeSnapshot(input: AnalysisInput, additional?: readonly Plugin[], cache?: OperationCacheOptions): Promise<Report>;
|
|
7
|
+
export declare function analyzeSnapshot(input: AnalysisInput, additional?: readonly Plugin[], cache?: OperationCacheOptions, history?: HistoryCache): Promise<Report>;
|
|
@@ -4,15 +4,17 @@ import { collectRepositorySyntax, inspectRepositories } from './analysis-reposit
|
|
|
4
4
|
import { assembleAnalysisReport } from './analysis-report.js';
|
|
5
5
|
import { AnalysisResults } from './analysis-results.js';
|
|
6
6
|
import { selectAnalysisSources } from './analysis-sources.js';
|
|
7
|
+
import { historyProfile } from './history-cache.js';
|
|
7
8
|
export { inspectionFileMatcher } from './analysis-sources.js';
|
|
8
|
-
export async function analyzeSnapshot(input, additional = [], cache) {
|
|
9
|
+
export async function analyzeSnapshot(input, additional = [], cache, history) {
|
|
9
10
|
const withCoverage = input.coverage !== undefined;
|
|
10
11
|
const sources = selectAnalysisSources(input.snapshot, additional, withCoverage);
|
|
12
|
+
const reusable = history?.begin(input.snapshot, historyProfile(input, sources, cache?.configurationDigest));
|
|
11
13
|
const results = new AnalysisResults(sources.plugins, sources.claimedPlugins, input.snapshot.oversizedClaims ?? []);
|
|
12
14
|
for (const task of defaultFilePlan)
|
|
13
15
|
results.remember(task);
|
|
14
|
-
const batchFacts = await collectRepositorySyntax(sources, results, cache);
|
|
15
|
-
const files = await inspectFiles(sources, batchFacts, results, withCoverage, cache);
|
|
16
|
+
const batchFacts = await collectRepositorySyntax(sources, results, cache, reusable);
|
|
17
|
+
const files = await inspectFiles(sources, batchFacts, results, withCoverage, cache, reusable);
|
|
16
18
|
await inspectRepositories(sources, results, cache);
|
|
17
19
|
await inspectDuplication(files, results, cache);
|
|
18
20
|
await importAnalysisCoverage(input, sources, files, results, cache);
|
|
@@ -7,7 +7,8 @@ export interface DiffCoverageRequest {
|
|
|
7
7
|
readonly directory: string;
|
|
8
8
|
readonly revision: string;
|
|
9
9
|
readonly base: string;
|
|
10
|
-
readonly lcov
|
|
10
|
+
readonly lcov?: LcovFiles;
|
|
11
|
+
readonly goCover?: LcovFiles;
|
|
11
12
|
readonly exclude?: readonly string[];
|
|
12
13
|
readonly minimumPercent?: number;
|
|
13
14
|
readonly plugins?: readonly Plugin[];
|
|
@@ -7,8 +7,8 @@ import { coverage, lcovInput } from '../plugins/coverage/coverage.js';
|
|
|
7
7
|
import { changesInput, diffCoverage, diffCoverageResult } from '../plugins/coverage/diff-coverage.js';
|
|
8
8
|
import { diffMethod, findMergeBase, readChanges } from '../api/git/changes.js';
|
|
9
9
|
import { gitText, physicalGitRoot, readGitCommit, resolveGitCommit } from '../api/git/git.js';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { readInspectionCoverage } from './inspection-coverage.js';
|
|
11
|
+
import { languageRegistry } from './languages.js';
|
|
12
12
|
export { diffCoverageSchema } from '../core/usecases/diff-coverage.js';
|
|
13
13
|
const operation = 'diff-coverage/measure';
|
|
14
14
|
const steps = plan({ plugins: [diffCoverage], select: [operation],
|
|
@@ -37,16 +37,18 @@ export async function measureChangedLines(request, overrides) {
|
|
|
37
37
|
}
|
|
38
38
|
async function readInputs(request, excludedPaths, excludes) {
|
|
39
39
|
const root = await physicalGitRoot(request.directory);
|
|
40
|
-
const [requestedBase, head,
|
|
40
|
+
const [requestedBase, head, gitVersion] = await Promise.all([
|
|
41
41
|
resolveGitCommit(root, request.base),
|
|
42
42
|
resolveGitCommit(root, request.revision),
|
|
43
|
-
readLcovFiles(request.lcov),
|
|
44
43
|
gitText(root, ['--version']).then(text => text.trim()),
|
|
45
44
|
]);
|
|
46
45
|
const base = await findMergeBase(root, requestedBase, head);
|
|
47
|
-
const { isSource, extensions, globs } =
|
|
46
|
+
const { isSource, extensions, globs } = languageRegistry(request.plugins ?? []);
|
|
48
47
|
const snapshot = await readGitCommit(root, head, excludes, isSource);
|
|
49
|
-
const changes = await
|
|
48
|
+
const [lcov, changes] = await Promise.all([
|
|
49
|
+
readInspectionCoverage(request, { root, snapshot }),
|
|
50
|
+
readChanges(root, base, snapshot, sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded), isSource),
|
|
51
|
+
]);
|
|
50
52
|
return { requestedBase, base, head, snapshot, changes, root, lcovText: lcov.text, appliedConfig: {
|
|
51
53
|
source: { extensions, ...(globs.length ? { globs } : {}), excludedDirectories: sourceDirectoriesExcluded, excludedPaths,
|
|
52
54
|
defaultExclusions: defaultSourceExclusions, generatedSourcePolicy, generatedExcluded: snapshot.generatedExcluded ?? [] },
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Outcome } from '../core/engine/execute.js';
|
|
2
|
+
import type { CodeStructure } from '../core/model/code-structure.js';
|
|
3
|
+
import type { SourceSnapshot } from '../core/model/source.js';
|
|
4
|
+
import type { AnalysisInput } from '../core/usecases/inspect.js';
|
|
5
|
+
import type { AnalysisSources } from './analysis-sources.js';
|
|
6
|
+
import type { LanguageProvider } from './languages.js';
|
|
7
|
+
interface FileResult {
|
|
8
|
+
readonly blob: string;
|
|
9
|
+
syntax?: CodeStructure;
|
|
10
|
+
outcomes?: ReadonlyMap<string, Outcome>;
|
|
11
|
+
}
|
|
12
|
+
export declare class HistoryFiles {
|
|
13
|
+
private readonly ids;
|
|
14
|
+
private readonly previous?;
|
|
15
|
+
readonly current: Map<string, FileResult>;
|
|
16
|
+
constructor(ids: ReadonlyMap<string, string>, previous?: ReadonlyMap<string, FileResult> | undefined);
|
|
17
|
+
read(path: string): FileResult | undefined;
|
|
18
|
+
retain(path: string, result: Omit<FileResult, 'blob'>): void;
|
|
19
|
+
}
|
|
20
|
+
/** One range keeps at most two adjacent snapshots' results during inspection. */
|
|
21
|
+
export declare class HistoryCache {
|
|
22
|
+
private readonly configuration?;
|
|
23
|
+
private previous?;
|
|
24
|
+
constructor(configuration?: unknown);
|
|
25
|
+
begin(snapshot: SourceSnapshot, profile: string): HistoryFiles | undefined;
|
|
26
|
+
}
|
|
27
|
+
export declare function historyProfile(input: AnalysisInput, sources: AnalysisSources, operationConfiguration?: string): string;
|
|
28
|
+
export declare function canReuseBatch(provider: LanguageProvider): boolean;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { debtModel } from '../core/model/quality-summary.js';
|
|
2
|
+
import { digest, sourceDirectoriesExcluded } from '../core/model/snapshot.js';
|
|
3
|
+
import { defaultSourceExclusions, generatedSourcePolicy } from '../core/profile/exclusions.js';
|
|
4
|
+
import { duplicationSettings, structuralRules } from '../core/profile/maintainability.js';
|
|
5
|
+
import { analysisProfile } from './analysis-report.js';
|
|
6
|
+
export class HistoryFiles {
|
|
7
|
+
ids;
|
|
8
|
+
previous;
|
|
9
|
+
current = new Map();
|
|
10
|
+
constructor(ids, previous) {
|
|
11
|
+
this.ids = ids;
|
|
12
|
+
this.previous = previous;
|
|
13
|
+
}
|
|
14
|
+
read(path) {
|
|
15
|
+
const result = this.previous?.get(path);
|
|
16
|
+
return result?.blob === this.ids.get(path) ? result : undefined;
|
|
17
|
+
}
|
|
18
|
+
retain(path, result) {
|
|
19
|
+
const blob = this.ids.get(path);
|
|
20
|
+
if (blob !== undefined)
|
|
21
|
+
this.current.set(path, { ...this.current.get(path), ...result, blob });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** One range keeps at most two adjacent snapshots' results during inspection. */
|
|
25
|
+
export class HistoryCache {
|
|
26
|
+
configuration;
|
|
27
|
+
previous;
|
|
28
|
+
constructor(configuration) {
|
|
29
|
+
this.configuration = configuration;
|
|
30
|
+
}
|
|
31
|
+
begin(snapshot, profile) {
|
|
32
|
+
if (snapshot.subject.kind !== 'commit' || snapshot.blobIds === undefined)
|
|
33
|
+
return undefined;
|
|
34
|
+
const key = digest(JSON.stringify([this.configuration, profile]));
|
|
35
|
+
const files = new HistoryFiles(snapshot.blobIds, this.previous?.profile === key ? this.previous.files.current : undefined);
|
|
36
|
+
this.previous = { profile: key, files };
|
|
37
|
+
return files;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function historyProfile(input, sources, operationConfiguration) {
|
|
41
|
+
return JSON.stringify([process.version, analysisProfile, input.excludedPaths, input.excludedOutput,
|
|
42
|
+
sourceDirectoriesExcluded, defaultSourceExclusions, generatedSourcePolicy, structuralRules, duplicationSettings, debtModel,
|
|
43
|
+
operationConfiguration, sources.plugins.map(pluginIdentity),
|
|
44
|
+
sources.languages.native.filter(plugin => plugin.unavailableReason !== undefined).map(pluginIdentity)]);
|
|
45
|
+
}
|
|
46
|
+
function pluginIdentity({ operations, ...manifest }) {
|
|
47
|
+
return { ...manifest, operations: operations.map(({ execute, inputs, output, ...operation }) => ({ ...operation,
|
|
48
|
+
inputs: Object.entries(inputs).map(([port, contract]) => [port, contract.id]), output: output.id,
|
|
49
|
+
implementation: operation.implementation ?? execute.toString(),
|
|
50
|
+
})) };
|
|
51
|
+
}
|
|
52
|
+
export function canReuseBatch(provider) {
|
|
53
|
+
return provider.operation.fileIndependent === true
|
|
54
|
+
&& !provider.plugin.operations.some(operation => operation.scope === 'repository' && operation.role === 'inspection')
|
|
55
|
+
&& provider.plugin.produces.some(product => product.contract === provider.operation.output.id && product.persistence === 'transient');
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=history-cache.js.map
|