repometry 0.6.1 → 0.6.2
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/package.json +1 -1
- package/target/main/ts/compose/analysis-files.js +1 -1
- package/target/main/ts/compose/analysis-report.js +2 -2
- package/target/main/ts/compose/analysis-sources.d.ts +2 -32
- package/target/main/ts/compose/analysis-sources.js +2 -3
- package/target/main/ts/compose/plugin-list.js +2 -2
- package/target/main/ts/core/engine/execute.js +40 -39
- package/target/main/ts/core/engine/manifest.js +40 -37
- package/target/main/ts/core/model/report.d.ts +2 -0
- package/target/main/ts/core/model/report.js +20 -0
- package/target/main/ts/core/usecases/compare.js +3 -4
- package/target/main/ts/index.d.ts +3 -2
- package/target/main/ts/index.js +2 -1
- package/target/main/ts/plugins/coverage/coverage.js +69 -81
- package/target/main/ts/plugins/duplication/duplication.js +2 -3
- package/target/main/ts/plugins/language-js/babel-provider.js +1 -1
- package/target/main/ts/report/json/projections/components.d.ts +1 -1
- package/target/main/ts/report/json/projections/file-metrics.d.ts +0 -2
- package/target/main/ts/report/json/projections/file-metrics.js +53 -66
- package/target/main/ts/report/json/projections/inspection-context.d.ts +0 -1
- package/target/main/ts/report/json/projections/inspection-context.js +5 -3
- package/target/main/ts/report/json/projections/inspection-details.d.ts +0 -1
package/package.json
CHANGED
|
@@ -90,6 +90,6 @@ function cloneSource(outcome, provider) {
|
|
|
90
90
|
if (outcome.state !== 'completed' || outcome.product.contract !== fileQuality.id || !fileQuality.accepts(outcome.product.value))
|
|
91
91
|
return;
|
|
92
92
|
const source = outcome.product.value.cloneSource;
|
|
93
|
-
return provider &&
|
|
93
|
+
return provider && source.scheme === undefined ? { ...source, scheme: provider.plugin.id } : source;
|
|
94
94
|
}
|
|
95
95
|
//# sourceMappingURL=analysis-files.js.map
|
|
@@ -4,7 +4,7 @@ import { reportSchema } from '../core/model/report.js';
|
|
|
4
4
|
import { comparePaths, digest, sourceDirectoriesExcluded, textLineCount } from '../core/model/snapshot.js';
|
|
5
5
|
import { defaultSourceExclusions, generatedSourcePolicy } from '../core/profile/exclusions.js';
|
|
6
6
|
import { duplicationSettings, structuralRules } from '../core/profile/maintainability.js';
|
|
7
|
-
import {
|
|
7
|
+
import { defaultProvider } from './analysis-sources.js';
|
|
8
8
|
import { fileTypeId } from '../core/model/file-types.js';
|
|
9
9
|
const measurementDefinitions = {
|
|
10
10
|
[definitions.lines]: 'Physical lines including blank lines and comments. A final line terminator does not add a line.',
|
|
@@ -44,7 +44,7 @@ function appliedConfiguration({ snapshot, excludedOutput, excludedPaths = [], co
|
|
|
44
44
|
source: { extensions: languages.extensions, ...(languages.globs.length ? { globs: languages.globs } : {}),
|
|
45
45
|
excludedDirectories: sourceDirectoriesExcluded, excludedOutput, excludedPaths,
|
|
46
46
|
defaultExclusions: defaultSourceExclusions, generatedSourcePolicy, generatedExcluded: snapshot.generatedExcluded ?? [] },
|
|
47
|
-
parser:
|
|
47
|
+
parser: defaultProvider.plugin.settings,
|
|
48
48
|
maintainability: { structuralRules, duplication: duplicationSettings, debtModel, remediation: 'nonoverlapping-complexity/v1' },
|
|
49
49
|
coverage: coverage === undefined ? null : { inputDigest: digest(coverage.text), pathBase: coverage.sourceRoot,
|
|
50
50
|
merge: 'any-hit', hitCounts: 'sum', lines: 'code-only' },
|
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
import type { Operation, Plugin } from '../core/engine/plugin.js';
|
|
2
2
|
import type { SourceFile, SourceSnapshot } from '../core/model/source.js';
|
|
3
3
|
import type { LanguageProvider } from './languages.js';
|
|
4
|
-
export declare const structuralInspections:
|
|
5
|
-
id: string;
|
|
6
|
-
version: string;
|
|
7
|
-
api: string;
|
|
8
|
-
operations: readonly Operation[];
|
|
9
|
-
rules?: readonly import("../core/engine/plugin.js").RuleDescriptor[];
|
|
10
|
-
config?: import("../core/engine/plugin.js").PluginConfigSchema;
|
|
11
|
-
settings?: import("../core/model/plugin-data.js").JsonValue;
|
|
12
|
-
kinds: readonly import("../core/engine/plugin.js").PluginKind[];
|
|
13
|
-
claims?: import("../core/engine/plugin.js").FileClaims;
|
|
14
|
-
providesLanguages?: readonly import("../plugin.js").ProvidedLanguage[];
|
|
15
|
-
produces: readonly import("../core/engine/plugin.js").ProductDeclaration[];
|
|
16
|
-
tools: {
|
|
17
|
-
'@babel/types': string;
|
|
18
|
-
};
|
|
19
|
-
}[];
|
|
4
|
+
export declare const structuralInspections: Plugin[];
|
|
20
5
|
export declare const defaultProvider: LanguageProvider;
|
|
21
6
|
export interface SelectedSource {
|
|
22
7
|
readonly file: SourceFile;
|
|
@@ -48,22 +33,7 @@ export declare function selectAnalysisSources(snapshot: SourceSnapshot, addition
|
|
|
48
33
|
sources: SelectedSource[];
|
|
49
34
|
sourceFiles: SourceFile[];
|
|
50
35
|
providersByPath: Map<string, LanguageProvider>;
|
|
51
|
-
plugins:
|
|
52
|
-
id: string;
|
|
53
|
-
version: string;
|
|
54
|
-
api: string;
|
|
55
|
-
operations: readonly Operation[];
|
|
56
|
-
rules?: readonly import("../core/engine/plugin.js").RuleDescriptor[];
|
|
57
|
-
config?: import("../core/engine/plugin.js").PluginConfigSchema;
|
|
58
|
-
settings?: import("../core/model/plugin-data.js").JsonValue;
|
|
59
|
-
kinds: readonly import("../core/engine/plugin.js").PluginKind[];
|
|
60
|
-
claims?: import("../core/engine/plugin.js").FileClaims;
|
|
61
|
-
providesLanguages?: readonly import("../plugin.js").ProvidedLanguage[];
|
|
62
|
-
produces: readonly import("../core/engine/plugin.js").ProductDeclaration[];
|
|
63
|
-
tools: {
|
|
64
|
-
'@babel/types': string;
|
|
65
|
-
};
|
|
66
|
-
})[];
|
|
36
|
+
plugins: Plugin[];
|
|
67
37
|
claimedPlugins: Plugin[];
|
|
68
38
|
perFile: ClaimedPlugin[];
|
|
69
39
|
repository: ClaimedPlugin[];
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { plan } from '../core/engine/plan.js';
|
|
2
2
|
import { coverage } from '../plugins/coverage/coverage.js';
|
|
3
3
|
import { duplication } from '../plugins/duplication/duplication.js';
|
|
4
|
-
import { babelProvider, babelTypes } from '../plugins/language-js/babel-provider.js';
|
|
5
4
|
import { maintainability } from '../plugins/maintainability/maintainability.js';
|
|
6
5
|
import { structure } from '../plugins/structure/structure.js';
|
|
7
6
|
import { claimMatcher, defaultLanguages, languageRegistry } from './languages.js';
|
|
8
7
|
import { securityPlugins } from './security-plugins.js';
|
|
9
|
-
export const structuralInspections = [
|
|
8
|
+
export const structuralInspections = [structure, maintainability];
|
|
10
9
|
export const defaultProvider = defaultLanguages.providers[0];
|
|
11
10
|
export function inspectionFileMatcher(additional, languages = defaultLanguages) {
|
|
12
11
|
const matches = [...securityPlugins, ...additional].filter(plugin => !plugin.kinds.includes('language'))
|
|
@@ -19,7 +18,7 @@ export function selectAnalysisSources(snapshot, additional, withCoverage) {
|
|
|
19
18
|
const providersByPath = new Map(sources.flatMap(({ file, provider }) => provider ? [[file.path, provider]] : []));
|
|
20
19
|
const sourceFiles = sources.flatMap(({ file, provider }) => provider ? [file] : []);
|
|
21
20
|
const claimedPlugins = [...securityPlugins.filter(plugin => !additional.includes(plugin)), ...additional];
|
|
22
|
-
const plugins = [
|
|
21
|
+
const plugins = [defaultProvider.plugin, ...structuralInspections, duplication, ...(withCoverage ? [coverage] : []), ...claimedPlugins];
|
|
23
22
|
validateRegistration(plugins, additional, withCoverage);
|
|
24
23
|
const claims = claimedPlugins.map(plugin => ({ plugin, matches: plugin.kinds.includes('language')
|
|
25
24
|
? path => providersByPath.get(path)?.plugin.id === plugin.id : claimMatcher(plugin.claims, languages.id) }));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { coverage } from '../plugins/coverage/coverage.js';
|
|
2
2
|
import { diffCoverage } from '../plugins/coverage/diff-coverage.js';
|
|
3
3
|
import { duplication } from '../plugins/duplication/duplication.js';
|
|
4
|
-
import { babelProvider } from '../plugins/language-js/babel-provider.js';
|
|
5
4
|
import { maintainability } from '../plugins/maintainability/maintainability.js';
|
|
6
5
|
import { structure } from '../plugins/structure/structure.js';
|
|
6
|
+
import { defaultLanguages } from './languages.js';
|
|
7
7
|
import { sourceProviders } from './sources.js';
|
|
8
8
|
import { securityPlugins } from './security-plugins.js';
|
|
9
|
-
export const builtInPlugins = [
|
|
9
|
+
export const builtInPlugins = [...defaultLanguages.providers.map(({ plugin }) => plugin), structure, maintainability, duplication, coverage, diffCoverage, ...securityPlugins, ...sourceProviders]
|
|
10
10
|
.map(({ id, version, kinds, claims }) => ({ id, version, kinds, ...(claims ? { claims } : {}) }));
|
|
11
11
|
//# sourceMappingURL=plugin-list.js.map
|
|
@@ -3,55 +3,56 @@ export async function execute(plan, external, cache) {
|
|
|
3
3
|
const results = new Map();
|
|
4
4
|
for (const task of plan) {
|
|
5
5
|
const inputs = new Map();
|
|
6
|
+
const missing = [];
|
|
6
7
|
for (const [name, binding] of task.inputs) {
|
|
7
8
|
const producer = 'operation' in binding ? results.get(binding.operation) : undefined;
|
|
8
9
|
const product = 'external' in binding ? external.get(binding.external)
|
|
9
10
|
: producer?.state === 'completed' ? producer.product : undefined;
|
|
10
11
|
if (product)
|
|
11
12
|
inputs.set(name, product);
|
|
13
|
+
else
|
|
14
|
+
missing.push(name);
|
|
12
15
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
for (const [name, contract] of Object.entries(task.operation.inputs)) {
|
|
20
|
-
readInput(inputs, name, contract);
|
|
21
|
-
}
|
|
22
|
-
const key = cache && operationCacheKey(task, inputs, cache.configurationDigest);
|
|
23
|
-
const hit = key && cache ? await readCachedOperation(cache.store, key, task) : undefined;
|
|
24
|
-
if (hit) {
|
|
25
|
-
results.set(task.key, { state: 'completed', product: hit });
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
const diagnostics = [];
|
|
29
|
-
const context = {
|
|
30
|
-
read: (port, contract) => {
|
|
31
|
-
if (!Object.hasOwn(task.operation.inputs, port) || task.operation.inputs[port]?.id !== contract.id) {
|
|
32
|
-
throw new Error(`Undeclared input contract: ${port} (${contract.id})`);
|
|
33
|
-
}
|
|
34
|
-
return readInput(inputs, port, contract);
|
|
35
|
-
},
|
|
36
|
-
emitDiagnostic: message => diagnostics.push(message),
|
|
37
|
-
};
|
|
38
|
-
const value = await task.operation.execute(context);
|
|
39
|
-
const { output } = task.operation;
|
|
40
|
-
if (!output.accepts(value))
|
|
41
|
-
throw new Error(`Invalid output for ${output.id}`);
|
|
42
|
-
if (task.validateOutput && !task.validateOutput(value))
|
|
43
|
-
throw new Error(`Output violates the schema for ${output.id}`);
|
|
44
|
-
const product = { contract: output.id, value };
|
|
45
|
-
if (key && cache && diagnostics.length === 0)
|
|
46
|
-
await writeCachedOperation(cache.store, key, product);
|
|
47
|
-
results.set(task.key, { state: 'completed', product, ...(diagnostics.length ? { diagnostics } : {}) });
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
results.set(task.key, { state: 'failed', reason: error instanceof Error ? error.message : String(error) });
|
|
51
|
-
}
|
|
16
|
+
results.set(task.key, missing.length
|
|
17
|
+
? { state: 'blocked', reason: `Unavailable inputs: ${missing.join(', ')}` }
|
|
18
|
+
: await runTask(task, inputs, cache));
|
|
52
19
|
}
|
|
53
20
|
return results;
|
|
54
21
|
}
|
|
22
|
+
async function runTask(task, inputs, cache) {
|
|
23
|
+
try {
|
|
24
|
+
const { operation, validateOutput } = task;
|
|
25
|
+
for (const [name, contract] of Object.entries(operation.inputs))
|
|
26
|
+
readInput(inputs, name, contract);
|
|
27
|
+
const key = cache && operationCacheKey(task, inputs, cache.configurationDigest);
|
|
28
|
+
const hit = key && cache ? await readCachedOperation(cache.store, key, task) : undefined;
|
|
29
|
+
if (hit)
|
|
30
|
+
return { state: 'completed', product: hit };
|
|
31
|
+
const diagnostics = [];
|
|
32
|
+
const context = {
|
|
33
|
+
read: (port, contract) => {
|
|
34
|
+
if (!Object.hasOwn(operation.inputs, port) || operation.inputs[port]?.id !== contract.id) {
|
|
35
|
+
throw new Error(`Undeclared input contract: ${port} (${contract.id})`);
|
|
36
|
+
}
|
|
37
|
+
return readInput(inputs, port, contract);
|
|
38
|
+
},
|
|
39
|
+
emitDiagnostic: message => diagnostics.push(message),
|
|
40
|
+
};
|
|
41
|
+
const value = await operation.execute(context);
|
|
42
|
+
const { output } = operation;
|
|
43
|
+
if (!output.accepts(value))
|
|
44
|
+
throw new Error(`Invalid output for ${output.id}`);
|
|
45
|
+
if (validateOutput && !validateOutput(value))
|
|
46
|
+
throw new Error(`Output violates the schema for ${output.id}`);
|
|
47
|
+
const product = { contract: output.id, value };
|
|
48
|
+
if (key && cache && diagnostics.length === 0)
|
|
49
|
+
await writeCachedOperation(cache.store, key, product);
|
|
50
|
+
return { state: 'completed', product, ...(diagnostics.length ? { diagnostics } : {}) };
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return { state: 'failed', reason: error instanceof Error ? error.message : String(error) };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
55
56
|
function readInput(inputs, port, contract) {
|
|
56
57
|
const product = inputs.get(port);
|
|
57
58
|
if (!product || product.contract !== contract.id || !contract.accepts(product.value)) {
|
|
@@ -17,30 +17,7 @@ export function isCoreReportProduct(contract) {
|
|
|
17
17
|
return coreProducts.has(contract);
|
|
18
18
|
}
|
|
19
19
|
export function manifestProducts(plugin) {
|
|
20
|
-
const { id,
|
|
21
|
-
if (declaredKinds === undefined && claims === undefined && providesLanguages === undefined && produces === undefined) {
|
|
22
|
-
throw new Error(`Missing plugin manifest for ${id}. Declare kinds and produces.`);
|
|
23
|
-
}
|
|
24
|
-
if (Object.hasOwn(plugin, 'languages'))
|
|
25
|
-
throw new Error(`Plugin ${id} must declare languages in claims.languages`);
|
|
26
|
-
if (!strings(declaredKinds) || declaredKinds.length === 0 || declaredKinds.some(kind => !kinds.has(kind))) {
|
|
27
|
-
throw new Error(`Invalid kinds for plugin ${id}`);
|
|
28
|
-
}
|
|
29
|
-
if (claims !== undefined && (!isRecord(claims) || Object.entries(claims).some(([key, values]) => key === 'scanOnly' ? typeof values !== 'boolean'
|
|
30
|
-
: !['extensions', 'globs', 'languages'].includes(key) || !strings(values)
|
|
31
|
-
|| (key === 'extensions' && values.some(extension => !/^\.[\w-]+$/.test(extension)))))) {
|
|
32
|
-
throw new Error(`Invalid file claims for plugin ${id}`);
|
|
33
|
-
}
|
|
34
|
-
if (providesLanguages !== undefined && (!declaredKinds.includes('language') || !validLanguages(providesLanguages))) {
|
|
35
|
-
throw new Error(`Invalid provided languages for plugin ${id}`);
|
|
36
|
-
}
|
|
37
|
-
if (!Array.isArray(produces))
|
|
38
|
-
throw new Error(`Plugin ${id} must declare its products`);
|
|
39
|
-
if (rules !== undefined && (!Array.isArray(rules) || !rules.every(isRuleDescriptor)
|
|
40
|
-
|| new Set(rules.map(rule => rule.id)).size !== rules.length))
|
|
41
|
-
throw new Error(`Invalid or duplicate rules for plugin ${id}`);
|
|
42
|
-
if (config !== undefined && typeof config !== 'boolean' && !isRecord(config))
|
|
43
|
-
throw new Error(`Invalid configuration schema for plugin ${id}`);
|
|
20
|
+
const { id, produces, rules } = manifestDeclarations(plugin);
|
|
44
21
|
const products = new Map();
|
|
45
22
|
const catalog = new Map();
|
|
46
23
|
for (const product of produces) {
|
|
@@ -48,8 +25,8 @@ export function manifestProducts(plugin) {
|
|
|
48
25
|
|| products.has(product.contract))
|
|
49
26
|
throw new Error(`Invalid or duplicate product for plugin ${id}`);
|
|
50
27
|
const { contract, schema, metrics } = product;
|
|
51
|
-
if (
|
|
52
|
-
|
|
28
|
+
if (schema === undefined ? product.persistence !== 'transient' && !isCoreReportProduct(contract)
|
|
29
|
+
: typeof schema !== 'boolean' && !isRecord(schema)) {
|
|
53
30
|
throw new Error(`Missing or invalid product schema for ${contract} in plugin ${id}`);
|
|
54
31
|
}
|
|
55
32
|
if (metrics !== undefined && (!Array.isArray(metrics) || !metrics.every(isMetricDescriptor))) {
|
|
@@ -63,22 +40,45 @@ export function manifestProducts(plugin) {
|
|
|
63
40
|
}
|
|
64
41
|
products.set(contract, declaration);
|
|
65
42
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
}
|
|
43
|
+
const undeclared = rules?.find(rule => rule.measure !== undefined && !catalog.has(rule.measure));
|
|
44
|
+
if (undeclared)
|
|
45
|
+
throw new Error(`Rule ${undeclared.id} in plugin ${id} references undeclared metric ${undeclared.measure}`);
|
|
71
46
|
for (const metric of catalog.values()) {
|
|
72
47
|
if (!metric.ratio)
|
|
73
48
|
continue;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
}
|
|
49
|
+
const invalid = [metric.ratio.of, metric.ratio.over].find(component => component === metric.id || (!catalog.has(component) && !coreMetrics.has(component)));
|
|
50
|
+
if (invalid !== undefined)
|
|
51
|
+
throw new Error(`Ratio ${metric.id} in plugin ${id} references invalid component ${invalid}`);
|
|
79
52
|
}
|
|
80
53
|
return products;
|
|
81
54
|
}
|
|
55
|
+
function manifestDeclarations(plugin) {
|
|
56
|
+
const { id, kinds: declaredKinds, claims, providesLanguages, produces, rules, config } = plugin;
|
|
57
|
+
if (declaredKinds === undefined && claims === undefined && providesLanguages === undefined && produces === undefined) {
|
|
58
|
+
throw new Error(`Missing plugin manifest for ${id}. Declare kinds and produces.`);
|
|
59
|
+
}
|
|
60
|
+
if (Object.hasOwn(plugin, 'languages'))
|
|
61
|
+
throw new Error(`Plugin ${id} must declare languages in claims.languages`);
|
|
62
|
+
if (!strings(declaredKinds) || declaredKinds.length === 0 || declaredKinds.some(kind => !kinds.has(kind))) {
|
|
63
|
+
throw new Error(`Invalid kinds for plugin ${id}`);
|
|
64
|
+
}
|
|
65
|
+
if (claims !== undefined && (!isRecord(claims) || Object.entries(claims).some(([key, values]) => key === 'scanOnly' ? typeof values !== 'boolean'
|
|
66
|
+
: !['extensions', 'globs', 'languages'].includes(key) || !strings(values)
|
|
67
|
+
|| (key === 'extensions' && !values.every(isExtension))))) {
|
|
68
|
+
throw new Error(`Invalid file claims for plugin ${id}`);
|
|
69
|
+
}
|
|
70
|
+
if (providesLanguages !== undefined && (!declaredKinds.includes('language') || !validLanguages(providesLanguages))) {
|
|
71
|
+
throw new Error(`Invalid provided languages for plugin ${id}`);
|
|
72
|
+
}
|
|
73
|
+
if (!Array.isArray(produces))
|
|
74
|
+
throw new Error(`Plugin ${id} must declare its products`);
|
|
75
|
+
if (rules !== undefined && (!Array.isArray(rules) || !rules.every(isRuleDescriptor)
|
|
76
|
+
|| new Set(rules.map(rule => rule.id)).size !== rules.length))
|
|
77
|
+
throw new Error(`Invalid or duplicate rules for plugin ${id}`);
|
|
78
|
+
if (config !== undefined && typeof config !== 'boolean' && !isRecord(config))
|
|
79
|
+
throw new Error(`Invalid configuration schema for plugin ${id}`);
|
|
80
|
+
return { id, produces, rules };
|
|
81
|
+
}
|
|
82
82
|
function validLanguages(values) {
|
|
83
83
|
if (!Array.isArray(values) || values.length === 0)
|
|
84
84
|
return false;
|
|
@@ -87,7 +87,7 @@ function validLanguages(values) {
|
|
|
87
87
|
if (!isRecord(value) || !isLanguageDisplay(value) || ids.has(value.id))
|
|
88
88
|
return false;
|
|
89
89
|
const { extensions, globs } = value;
|
|
90
|
-
if (extensions !== undefined && (!strings(extensions) || extensions.
|
|
90
|
+
if (extensions !== undefined && (!strings(extensions) || !extensions.every(isExtension)))
|
|
91
91
|
return false;
|
|
92
92
|
if (globs !== undefined && !strings(globs))
|
|
93
93
|
return false;
|
|
@@ -114,6 +114,9 @@ export function isMetricDescriptor(value) {
|
|
|
114
114
|
&& value.bands.every((limit, index, array) => typeof limit === 'number' && Number.isFinite(limit)
|
|
115
115
|
&& (index === 0 || limit > array[index - 1]))));
|
|
116
116
|
}
|
|
117
|
+
function isExtension(value) {
|
|
118
|
+
return /^\.[\w-]+$/.test(value);
|
|
119
|
+
}
|
|
117
120
|
function strings(value) {
|
|
118
121
|
return Array.isArray(value) && value.every(text) && new Set(value).size === value.length;
|
|
119
122
|
}
|
|
@@ -37,3 +37,5 @@ export interface Report {
|
|
|
37
37
|
readonly pluginData?: PluginData;
|
|
38
38
|
}
|
|
39
39
|
export declare function validSubjectId(kind: Subject['kind'], id: string): boolean;
|
|
40
|
+
export declare const legacySyntaxPlugin = "babel-syntax";
|
|
41
|
+
export declare function historicalPluginTools(plugins: unknown): unknown;
|
|
@@ -1,4 +1,24 @@
|
|
|
1
|
+
import { isRecord } from './plugin-data.js';
|
|
1
2
|
export const reportSchema = 'urn:repometry:schema:report:2';
|
|
2
3
|
export function validSubjectId(kind, id) {
|
|
3
4
|
return /^[a-f0-9]{64}$/.test(id) || (kind === 'commit' && /^[a-f0-9]{40}$/.test(id));
|
|
4
5
|
}
|
|
6
|
+
export const legacySyntaxPlugin = 'babel-syntax';
|
|
7
|
+
// Keep history comparable when the parser starts recording its own tool versions.
|
|
8
|
+
export function historicalPluginTools(plugins) {
|
|
9
|
+
if (!Array.isArray(plugins))
|
|
10
|
+
return plugins;
|
|
11
|
+
const syntax = plugins.find(entry => isRecord(entry) && entry.id === legacySyntaxPlugin);
|
|
12
|
+
if (!isRecord(syntax?.tools))
|
|
13
|
+
return plugins;
|
|
14
|
+
const { '@babel/types': types, ...native } = syntax.tools;
|
|
15
|
+
if (typeof types !== 'string')
|
|
16
|
+
return plugins;
|
|
17
|
+
return plugins.map(entry => {
|
|
18
|
+
if (entry === syntax)
|
|
19
|
+
return { ...syntax, tools: native };
|
|
20
|
+
if (!isRecord(entry) || (entry.id !== 'structure' && entry.id !== 'maintainability') || !isRecord(entry.tools))
|
|
21
|
+
return entry;
|
|
22
|
+
return { ...entry, tools: { '@babel/types': types, ...entry.tools } };
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from 'node:util';
|
|
2
2
|
import { isRecord } from '../engine/plugin.js';
|
|
3
3
|
import { canonicalMetricId, definitions } from '../model/measurement.js';
|
|
4
|
+
import { historicalPluginTools, legacySyntaxPlugin } from '../model/report.js';
|
|
4
5
|
import { comparePaths } from '../model/snapshot.js';
|
|
5
6
|
import { comparisonSchema } from '../model/comparison.js';
|
|
6
7
|
export { comparisonSchema } from '../model/comparison.js';
|
|
@@ -92,8 +93,6 @@ function hasDiagnostic(report, ...operations) {
|
|
|
92
93
|
}
|
|
93
94
|
function hasParserDiagnostic(report) {
|
|
94
95
|
const references = parserReferences(report);
|
|
95
|
-
if (references.size === 0)
|
|
96
|
-
return hasDiagnostic(report, 'babel-syntax/parse');
|
|
97
96
|
const operations = new Set(references.values());
|
|
98
97
|
return report.diagnostics.some(({ path, operation }) => path === undefined
|
|
99
98
|
? operations.has(operation) : references.get(path) === operation);
|
|
@@ -162,12 +161,12 @@ function structureMethod(report, operation) {
|
|
|
162
161
|
return null;
|
|
163
162
|
const providerBindings = recordedEntries(operations, 'key', [...providerKeys].sort(comparePaths));
|
|
164
163
|
const pluginIds = [...new Set([operation, ...providerKeys].map(key => key.slice(0, key.indexOf('/'))))].sort(comparePaths);
|
|
165
|
-
const toolchain = recordedEntries(plugins, 'id', pluginIds);
|
|
164
|
+
const toolchain = recordedEntries(historicalPluginTools(plugins), 'id', pluginIds);
|
|
166
165
|
if (!providerBindings || !toolchain)
|
|
167
166
|
return null;
|
|
168
167
|
// The original reports carried the Babel configuration at report level.
|
|
169
168
|
const configured = toolchain.map(({ id, version, api, tools, settings }) => ({
|
|
170
|
-
id, version, api, tools, settings: id ===
|
|
169
|
+
id, version, api, tools, settings: id === legacySyntaxPlugin && isRecord(parser) ? parser : settings ?? null,
|
|
171
170
|
}));
|
|
172
171
|
return { toolchain: configured, bindings: [...providerBindings, ...bindings.sort((a, b) => comparePaths(JSON.stringify(a), JSON.stringify(b)))] };
|
|
173
172
|
}
|
|
@@ -17,8 +17,9 @@ export { compareInspections as compare } from './core/usecases/compare.js';
|
|
|
17
17
|
export { measureDiffCoverage as diffCoverage } from './compose/diff-coverage.js';
|
|
18
18
|
export { review } from './compose/review.js';
|
|
19
19
|
export type { InspectionComparison } from './core/usecases/compare.js';
|
|
20
|
-
export { fileMetrics
|
|
21
|
-
export
|
|
20
|
+
export { fileMetrics } from './report/json/projections/file-metrics.js';
|
|
21
|
+
export { fileMetricsSchema } from './report/json/wire/file-metrics-model.js';
|
|
22
|
+
export type { FileMetricsReport } from './report/json/wire/file-metrics-model.js';
|
|
22
23
|
export { LocalReportStore } from './report/json/store/local-store.js';
|
|
23
24
|
export { GitReportReader } from './api/git/git-reader.js';
|
|
24
25
|
export { readReport, reportSchema } from './report/json/validation/report.js';
|
package/target/main/ts/index.js
CHANGED
|
@@ -8,7 +8,8 @@ export { compareInspections, comparisonSchema } from './core/usecases/compare.js
|
|
|
8
8
|
export { compareInspections as compare } from './core/usecases/compare.js';
|
|
9
9
|
export { measureDiffCoverage as diffCoverage } from './compose/diff-coverage.js';
|
|
10
10
|
export { review } from './compose/review.js';
|
|
11
|
-
export { fileMetrics
|
|
11
|
+
export { fileMetrics } from './report/json/projections/file-metrics.js';
|
|
12
|
+
export { fileMetricsSchema } from './report/json/wire/file-metrics-model.js';
|
|
12
13
|
export { LocalReportStore } from './report/json/store/local-store.js';
|
|
13
14
|
export { GitReportReader } from './api/git/git-reader.js';
|
|
14
15
|
export { readReport, reportSchema } from './report/json/validation/report.js';
|
|
@@ -18,25 +18,27 @@ export const coverageResult = {
|
|
|
18
18
|
&& Array.isArray(value.gaps) && value.gaps.every(gap => isRecord(gap) && typeof gap.path === 'string' && typeof gap.reason === 'string')
|
|
19
19
|
&& lcovLines.accepts(value.lineCoverage),
|
|
20
20
|
};
|
|
21
|
+
const kinds = [
|
|
22
|
+
{ ids: [definitions.coverage, definitions.coveredLines, definitions.coverableLines],
|
|
23
|
+
labels: ['Line coverage', 'Covered lines', 'Measured lines'], includeEmpty: true },
|
|
24
|
+
{ ids: [definitions.branchCoverage, definitions.coveredBranches, definitions.coverableBranches],
|
|
25
|
+
labels: ['Branch coverage', 'Covered branches', 'Measured branches'] },
|
|
26
|
+
{ ids: [definitions.functionCoverage, definitions.coveredFunctions, definitions.coverableFunctions],
|
|
27
|
+
labels: ['Function coverage', 'Covered functions', 'Measured functions'] },
|
|
28
|
+
];
|
|
29
|
+
const [lineMetrics, branchMetrics, functionMetrics] = kinds;
|
|
21
30
|
export const coverage = {
|
|
22
31
|
id: 'lcov',
|
|
23
32
|
version: '1.2.0',
|
|
24
33
|
api: pluginApi,
|
|
25
34
|
kinds: ['coverage', 'import'],
|
|
26
|
-
produces: [{ contract: coverageResult.id, persistence: 'report',
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{ id:
|
|
31
|
-
{ id:
|
|
32
|
-
|
|
33
|
-
{ id: definitions.coveredBranches, label: 'Covered branches', unit: 'count', scope: 'file', aggregate: 'sum', better: 'higher', group: 'Coverage' },
|
|
34
|
-
{ id: definitions.coverableBranches, label: 'Measured branches', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Coverage' },
|
|
35
|
-
{ id: definitions.functionCoverage, label: 'Function coverage', unit: 'ratio', scope: 'file', aggregate: 'sum', better: 'higher',
|
|
36
|
-
ratio: { of: definitions.coveredFunctions, over: definitions.coverableFunctions }, bands: [0.6, 0.7, 0.8, 0.9], group: 'Coverage' },
|
|
37
|
-
{ id: definitions.coveredFunctions, label: 'Covered functions', unit: 'count', scope: 'file', aggregate: 'sum', better: 'higher', group: 'Coverage' },
|
|
38
|
-
{ id: definitions.coverableFunctions, label: 'Measured functions', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Coverage' },
|
|
39
|
-
] }, { contract: lcovLines.id, persistence: 'report',
|
|
35
|
+
produces: [{ contract: coverageResult.id, persistence: 'report',
|
|
36
|
+
metrics: kinds.flatMap(({ ids: [id, of, over], labels }) => [
|
|
37
|
+
{ id, label: labels[0], unit: 'ratio', scope: 'file', aggregate: 'sum', better: 'higher',
|
|
38
|
+
ratio: { of, over }, bands: [0.6, 0.7, 0.8, 0.9], group: 'Coverage' },
|
|
39
|
+
{ id: of, label: labels[1], unit: 'count', scope: 'file', aggregate: 'sum', better: 'higher', group: 'Coverage' },
|
|
40
|
+
{ id: over, label: labels[2], unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Coverage' },
|
|
41
|
+
]) }, { contract: lcovLines.id, persistence: 'report',
|
|
40
42
|
schema: { ...reportSchema.$defs.lcovLines,
|
|
41
43
|
$defs: { lcovLineRanges: reportSchema.$defs.lcovLineRanges, lcovHitRuns: reportSchema.$defs.lcovHitRuns,
|
|
42
44
|
lcovFunctionCalls: reportSchema.$defs.lcovFunctionCalls } } }],
|
|
@@ -59,7 +61,7 @@ export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
|
|
|
59
61
|
// Branches by line, block and branch. Functions by name and its occurrence in the record: tools such as c8 repeat a
|
|
60
62
|
// name for different functions and list FNDA in FN order.
|
|
61
63
|
const branches = new Map();
|
|
62
|
-
const
|
|
64
|
+
const functions = new Map();
|
|
63
65
|
const called = new Map();
|
|
64
66
|
const occurrences = { declared: new Map(), called: new Map() };
|
|
65
67
|
const occurrence = (seen, name) => {
|
|
@@ -71,8 +73,7 @@ export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
|
|
|
71
73
|
let active;
|
|
72
74
|
let ignored = false;
|
|
73
75
|
let sawSource = false;
|
|
74
|
-
const
|
|
75
|
-
for (const [index, line] of lines.entries()) {
|
|
76
|
+
for (const [index, line] of text.split(/\r?\n/).entries()) {
|
|
76
77
|
if (line.startsWith('SF:')) {
|
|
77
78
|
if (active !== undefined || line.length === 3)
|
|
78
79
|
throw new Error(`Unexpected LCOV source at line ${index + 1}`);
|
|
@@ -87,8 +88,8 @@ export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
|
|
|
87
88
|
gaps.set(active, 'LCOV source is outside the inspected file set');
|
|
88
89
|
else if (codeLines && !codeLines.has(active))
|
|
89
90
|
gaps.set(active, 'LCOV source has no classified code lines');
|
|
90
|
-
else
|
|
91
|
-
files
|
|
91
|
+
else
|
|
92
|
+
fileRecords(files, active);
|
|
92
93
|
}
|
|
93
94
|
else if (line.startsWith('DA:')) {
|
|
94
95
|
if (active === undefined)
|
|
@@ -112,35 +113,7 @@ export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
|
|
|
112
113
|
throw new Error(`LCOV data outside a source record at line ${index + 1}`);
|
|
113
114
|
if (ignored || !files.has(active))
|
|
114
115
|
continue;
|
|
115
|
-
|
|
116
|
-
const declaration = /^FN:([1-9]\d*)(?:,[1-9]\d*)?,(.+)$/.exec(line);
|
|
117
|
-
const call = /^FNDA:(\d+),(.+)$/.exec(line);
|
|
118
|
-
if (branch) {
|
|
119
|
-
const taken = branch[4] === '-' ? 0 : Number(branch[4]);
|
|
120
|
-
const key = `${branch[1]},${branch[2]},${branch[3]}`;
|
|
121
|
-
const file = branches.get(active) ?? new Map();
|
|
122
|
-
addHits(file, key, taken, index + 1);
|
|
123
|
-
branches.set(active, file);
|
|
124
|
-
}
|
|
125
|
-
else if (declaration) {
|
|
126
|
-
const number = Number(declaration[1]);
|
|
127
|
-
if (!Number.isSafeInteger(number))
|
|
128
|
-
throw new Error(`Invalid LCOV function line at line ${index + 1}`);
|
|
129
|
-
const key = occurrence(occurrences.declared, declaration[2]);
|
|
130
|
-
const file = declared.get(active) ?? new Map();
|
|
131
|
-
if (!file.has(key))
|
|
132
|
-
file.set(key, number);
|
|
133
|
-
declared.set(active, file);
|
|
134
|
-
}
|
|
135
|
-
else if (call) {
|
|
136
|
-
const key = occurrence(occurrences.called, call[2]);
|
|
137
|
-
const file = called.get(active) ?? new Map();
|
|
138
|
-
addHits(file, key, Number(call[1]), index + 1);
|
|
139
|
-
called.set(active, file);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
throw new Error(`Invalid LCOV data at line ${index + 1}`);
|
|
143
|
-
}
|
|
116
|
+
readDetails(active, line, index + 1);
|
|
144
117
|
}
|
|
145
118
|
else if (line === 'end_of_record') {
|
|
146
119
|
if (active === undefined)
|
|
@@ -152,14 +125,14 @@ export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
|
|
|
152
125
|
throw new Error('Unterminated LCOV source record');
|
|
153
126
|
if (!sawSource && text.trim() !== '')
|
|
154
127
|
throw new Error('LCOV contains no source records');
|
|
155
|
-
|
|
128
|
+
// The declaration map can now hold the hit totals. Keep the declared lines for the gutter.
|
|
156
129
|
const functionCalls = new Map();
|
|
157
|
-
for (const [path, declarations] of
|
|
130
|
+
for (const [path, declarations] of functions) {
|
|
158
131
|
const hits = called.get(path);
|
|
159
|
-
functions.set(path, new Map([...declarations.keys()].map(key => [key, hits?.get(key) ?? 0])));
|
|
160
132
|
const counts = [];
|
|
161
133
|
for (const [key, first] of declarations) {
|
|
162
134
|
const count = hits?.get(key);
|
|
135
|
+
declarations.set(key, count ?? 0);
|
|
163
136
|
if (count !== undefined && first <= sourceLines.get(path))
|
|
164
137
|
counts.push([first, count]);
|
|
165
138
|
}
|
|
@@ -167,6 +140,36 @@ export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
|
|
|
167
140
|
functionCalls.set(path, counts.sort(([left], [right]) => left - right));
|
|
168
141
|
}
|
|
169
142
|
return { files, branches, functions, functionCalls, gaps };
|
|
143
|
+
function readDetails(path, line, record) {
|
|
144
|
+
const branch = /^BRDA:([1-9]\d*),([^,]+),([^,]+),(\d+|-)$/.exec(line);
|
|
145
|
+
if (branch) {
|
|
146
|
+
addHits(fileRecords(branches, path), `${branch[1]},${branch[2]},${branch[3]}`, branch[4] === '-' ? 0 : Number(branch[4]), record);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const declaration = /^FN:([1-9]\d*)(?:,[1-9]\d*)?,(.+)$/.exec(line);
|
|
150
|
+
if (declaration) {
|
|
151
|
+
const number = Number(declaration[1]);
|
|
152
|
+
if (!Number.isSafeInteger(number))
|
|
153
|
+
throw new Error(`Invalid LCOV function line at line ${record}`);
|
|
154
|
+
const records = fileRecords(functions, path);
|
|
155
|
+
const key = occurrence(occurrences.declared, declaration[2]);
|
|
156
|
+
if (!records.has(key))
|
|
157
|
+
records.set(key, number);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const call = /^FNDA:(\d+),(.+)$/.exec(line);
|
|
161
|
+
if (!call)
|
|
162
|
+
throw new Error(`Invalid LCOV data at line ${record}`);
|
|
163
|
+
addHits(fileRecords(called, path), occurrence(occurrences.called, call[2]), Number(call[1]), record);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function fileRecords(files, path) {
|
|
167
|
+
const existing = files.get(path);
|
|
168
|
+
if (existing)
|
|
169
|
+
return existing;
|
|
170
|
+
const records = new Map();
|
|
171
|
+
files.set(path, records);
|
|
172
|
+
return records;
|
|
170
173
|
}
|
|
171
174
|
function addHits(hits, key, count, record) {
|
|
172
175
|
const total = (hits.get(key) ?? 0) + count;
|
|
@@ -176,13 +179,8 @@ function addHits(hits, key, count, record) {
|
|
|
176
179
|
}
|
|
177
180
|
function importCoverage(input) {
|
|
178
181
|
const { files, branches, functions, functionCalls, gaps } = mapCoverage(input);
|
|
179
|
-
const rows = [];
|
|
180
182
|
const lineCoverage = [];
|
|
181
|
-
|
|
182
|
-
let totalLines = 0;
|
|
183
|
-
for (const [path, hits] of [...files].sort(([left], [right]) => comparePaths(left, right))) {
|
|
184
|
-
if (gaps.has(path))
|
|
185
|
-
continue;
|
|
183
|
+
const lines = hitRows(files, gaps, lineMetrics, (path, hits) => {
|
|
186
184
|
const hitLines = [], missedLines = [];
|
|
187
185
|
for (const [line, hit] of hits)
|
|
188
186
|
(hit ? hitLines : missedLines).push(line);
|
|
@@ -197,21 +195,10 @@ function importCoverage(input) {
|
|
|
197
195
|
...(partial.length ? { partial } : {}), hits: mergedHits(measured),
|
|
198
196
|
...(calls === undefined ? {} : { functionCalls: calls }), ...(bodies === undefined ? {} : { functionBodies: bodies }) }]);
|
|
199
197
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
rows.push({ definition: definitions.coverage, target: 'repository', covered: totalCovered, total: totalLines, value: ratio(totalCovered, totalLines) });
|
|
206
|
-
const counts = rows.flatMap(({ target, path, covered, total }) => [
|
|
207
|
-
{ definition: definitions.coveredLines, target, path, value: covered ?? null },
|
|
208
|
-
{ definition: definitions.coverableLines, target, path, value: total ?? null },
|
|
209
|
-
]);
|
|
210
|
-
const extra = [
|
|
211
|
-
...hitRows(branches, gaps, definitions.branchCoverage, definitions.coveredBranches, definitions.coverableBranches),
|
|
212
|
-
...hitRows(functions, gaps, definitions.functionCoverage, definitions.coveredFunctions, definitions.coverableFunctions),
|
|
213
|
-
];
|
|
214
|
-
return { measurements: [...rows, ...counts, ...extra], lineCoverage: Object.fromEntries(lineCoverage),
|
|
198
|
+
return hitLines.length;
|
|
199
|
+
});
|
|
200
|
+
const metrics = [...lines, ...hitRows(branches, gaps, branchMetrics), ...hitRows(functions, gaps, functionMetrics)];
|
|
201
|
+
return { measurements: metrics, lineCoverage: Object.fromEntries(lineCoverage),
|
|
215
202
|
gaps: [...gaps].sort(([left], [right]) => comparePaths(left, right)).map(([path, reason]) => ({ path, reason })) };
|
|
216
203
|
}
|
|
217
204
|
function partiallyCoveredLines(branches, lastLine, codeLines) {
|
|
@@ -251,22 +238,25 @@ function mergedHits(hits) {
|
|
|
251
238
|
return runs;
|
|
252
239
|
}
|
|
253
240
|
/** Per-file and repository ratios with their counts, for a kind the LCOV reports; nothing when it reports none. */
|
|
254
|
-
function hitRows(files, gaps, ratioId, coveredId, totalId) {
|
|
241
|
+
function hitRows(files, gaps, { ids: [ratioId, coveredId, totalId], includeEmpty = false }, coveredCount) {
|
|
255
242
|
const rows = [];
|
|
256
243
|
let totalCovered = 0;
|
|
257
244
|
let totalCount = 0;
|
|
258
245
|
for (const [path, hits] of [...files].sort(([left], [right]) => comparePaths(left, right))) {
|
|
259
|
-
if (gaps.has(path) || hits.size
|
|
246
|
+
if (gaps.has(path) || (!hits.size && !includeEmpty))
|
|
260
247
|
continue;
|
|
261
248
|
let covered = 0;
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
249
|
+
if (coveredCount)
|
|
250
|
+
covered = coveredCount(path, hits);
|
|
251
|
+
else
|
|
252
|
+
for (const hit of hits.values())
|
|
253
|
+
if (hit)
|
|
254
|
+
covered++;
|
|
265
255
|
totalCovered += covered;
|
|
266
256
|
totalCount += hits.size;
|
|
267
257
|
rows.push({ definition: ratioId, target: 'file', path, covered, total: hits.size, value: ratio(covered, hits.size) });
|
|
268
258
|
}
|
|
269
|
-
if (totalCount === 0)
|
|
259
|
+
if (totalCount === 0 && !includeEmpty)
|
|
270
260
|
return [];
|
|
271
261
|
rows.push({ definition: ratioId, target: 'repository', covered: totalCovered, total: totalCount, value: ratio(totalCovered, totalCount) });
|
|
272
262
|
return [...rows, ...rows.flatMap(({ target, path, covered, total }) => [
|
|
@@ -282,8 +272,6 @@ function normalizeLcovPath(root, path) {
|
|
|
282
272
|
const candidate = platform.isAbsolute(path) ? platform.relative(root, path) : path;
|
|
283
273
|
if (platform.isAbsolute(candidate))
|
|
284
274
|
return candidate;
|
|
285
|
-
|
|
286
|
-
return posix.normalize(candidate.replaceAll('\\', '/'));
|
|
287
|
-
return posix.normalize(candidate);
|
|
275
|
+
return posix.normalize(platform === win32 ? candidate.replaceAll('\\', '/') : candidate);
|
|
288
276
|
}
|
|
289
277
|
//# sourceMappingURL=coverage.js.map
|
|
@@ -24,11 +24,10 @@ export const duplicationInput = cloneSources;
|
|
|
24
24
|
function detectClones(sources) {
|
|
25
25
|
const schemes = new Map();
|
|
26
26
|
for (const { path, candidates, scheme } of sources) {
|
|
27
|
-
|
|
28
|
-
let byFingerprint = schemes.get(name);
|
|
27
|
+
let byFingerprint = schemes.get(scheme);
|
|
29
28
|
if (!byFingerprint) {
|
|
30
29
|
byFingerprint = new Map();
|
|
31
|
-
schemes.set(
|
|
30
|
+
schemes.set(scheme, byFingerprint);
|
|
32
31
|
}
|
|
33
32
|
for (const candidate of candidates) {
|
|
34
33
|
const occurrences = byFingerprint.get(candidate.similar);
|
|
@@ -22,7 +22,7 @@ export const babelProvider = {
|
|
|
22
22
|
providesLanguages: [javascriptType, typescriptType],
|
|
23
23
|
settings: parserDefaults,
|
|
24
24
|
produces: [{ contract: codeStructure.id, persistence: 'transient' }],
|
|
25
|
-
tools: { '@babel/parser': require('@babel/parser/package.json').version },
|
|
25
|
+
tools: { '@babel/parser': require('@babel/parser/package.json').version, ...babelTypes },
|
|
26
26
|
operations: [{
|
|
27
27
|
id: 'parse',
|
|
28
28
|
role: 'provider',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FileMetricsReport } from '
|
|
1
|
+
import type { FileMetricsReport } from '../wire/file-metrics-model.js';
|
|
2
2
|
import type { Component, ComponentMetrics } from '../wire/component-model.js';
|
|
3
3
|
export type { Component, ComponentMetrics } from '../wire/component-model.js';
|
|
4
4
|
export declare function componentFiles(components: readonly Component[], metrics: FileMetricsReport): readonly ComponentMetrics[];
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { LanguageLookup } from '../../../core/model/language.js';
|
|
2
2
|
import type { Report } from '../validation/report.js';
|
|
3
3
|
import type { FileMetricsReport } from '../wire/file-metrics-model.js';
|
|
4
|
-
export { fileMetricsSchema } from '../wire/file-metrics-model.js';
|
|
5
|
-
export type { FileMetricsReport } from '../wire/file-metrics-model.js';
|
|
6
4
|
export declare function fileMetrics(report: Report, registry?: LanguageLookup): FileMetricsReport;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { fileTypeId, fileTypes } from '../../../core/model/file-types.js';
|
|
2
2
|
import { isRecord } from '../../../core/engine/plugin.js';
|
|
3
3
|
import { canonicalMetricId, definitions } from '../../../core/model/measurement.js';
|
|
4
|
+
import { legacySyntaxPlugin } from '../../../core/model/report.js';
|
|
4
5
|
import { comparePaths } from '../../../core/model/snapshot.js';
|
|
5
6
|
import { metricProjection } from './metric-values.js';
|
|
6
7
|
import { fileMetricsSchema } from '../wire/file-metrics-model.js';
|
|
7
|
-
export { fileMetricsSchema } from '../wire/file-metrics-model.js';
|
|
8
8
|
export function fileMetrics(report, registry = { id: fileTypeId, catalog: [] }) {
|
|
9
9
|
const byPath = new Map();
|
|
10
|
-
const duplicatedLines = new Map();
|
|
11
10
|
const pluginMetrics = metricProjection(report);
|
|
12
11
|
const languages = [];
|
|
13
12
|
const recorded = new Map(report.pluginData?.languages?.map(item => [item.id, item]));
|
|
@@ -45,61 +44,13 @@ export function fileMetrics(report, registry = { id: fileTypeId, catalog: [] })
|
|
|
45
44
|
if (provider !== undefined)
|
|
46
45
|
entry.provider = provider;
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
continue;
|
|
51
|
-
const id = canonicalMetricId(row.definition);
|
|
52
|
-
if (pluginMetrics)
|
|
53
|
-
file(row.path);
|
|
54
|
-
if (row.target === 'file' && id === definitions.coverage && row.covered !== undefined && row.total !== undefined) {
|
|
55
|
-
file(row.path).lineCoverage = { covered: row.covered, total: row.total };
|
|
56
|
-
}
|
|
57
|
-
if (row.value === null || !Number.isSafeInteger(row.value) || row.value < 0)
|
|
58
|
-
continue;
|
|
59
|
-
if (row.target === 'file' && id === definitions.lines)
|
|
60
|
-
file(row.path).lines = row.value;
|
|
61
|
-
if (row.target === 'file' && id === definitions.functions)
|
|
62
|
-
file(row.path).functions = row.value;
|
|
63
|
-
if (row.target === 'file') {
|
|
64
|
-
switch (id) {
|
|
65
|
-
case definitions.codeLines:
|
|
66
|
-
quality(file(row.path)).codeLines = row.value;
|
|
67
|
-
break;
|
|
68
|
-
case definitions.comments:
|
|
69
|
-
quality(file(row.path)).commentLines = row.value;
|
|
70
|
-
break;
|
|
71
|
-
case definitions.classes:
|
|
72
|
-
quality(file(row.path)).classes = row.value;
|
|
73
|
-
break;
|
|
74
|
-
case definitions.cognitiveComplexity:
|
|
75
|
-
quality(file(row.path)).cognitiveComplexity = row.value;
|
|
76
|
-
break;
|
|
77
|
-
case definitions.churn:
|
|
78
|
-
quality(file(row.path)).churn = row.value;
|
|
79
|
-
break;
|
|
80
|
-
case definitions.duplicatedLines:
|
|
81
|
-
duplicatedLines.set(row.path, row.value);
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (row.target === 'function' && id === definitions.complexity) {
|
|
86
|
-
const target = file(row.path);
|
|
87
|
-
target.complexity = addComplexity(target.complexity, { sum: row.value, maximum: row.value, measuredFunctions: 1 });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
for (const [path, duplicateCount] of duplicatedLines) {
|
|
91
|
-
const entry = byPath.get(path);
|
|
92
|
-
const codeLines = entry?.quality?.codeLines;
|
|
93
|
-
if (entry && codeLines !== undefined && duplicateCount <= codeLines) {
|
|
94
|
-
quality(entry).duplication = { duplicatedLines: duplicateCount, codeLines };
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
addFileFindings(byPath, report.findings);
|
|
47
|
+
const duplicatedLines = collectMeasurements(report.measurements, file, pluginMetrics !== undefined);
|
|
48
|
+
addFileQuality(byPath, duplicatedLines, report.findings);
|
|
98
49
|
let unassignedDiagnostics = 0;
|
|
99
50
|
for (const diagnostic of report.diagnostics) {
|
|
100
51
|
const { path, operation } = diagnostic;
|
|
101
52
|
const target = path === undefined ? undefined
|
|
102
|
-
: operation ===
|
|
53
|
+
: operation === `${legacySyntaxPlugin}/parse` || operation.startsWith('structure/') ? file(path) : byPath.get(path);
|
|
103
54
|
if (target)
|
|
104
55
|
target.diagnosticCount++;
|
|
105
56
|
else
|
|
@@ -140,8 +91,8 @@ export function fileMetrics(report, registry = { id: fileTypeId, catalog: [] })
|
|
|
140
91
|
const complexity = files.filter(entry => entry.complexity?.maximum != null)
|
|
141
92
|
.sort((left, right) => right.complexity.maximum - left.complexity.maximum
|
|
142
93
|
|| right.complexity.sum - left.complexity.sum || byName(left, right));
|
|
143
|
-
const coverage = files
|
|
144
|
-
.
|
|
94
|
+
const coverage = ranked(files, ({ lineCoverage }) => lineCoverage && lineCoverage.covered < lineCoverage.total
|
|
95
|
+
? lineCoverage.total - lineCoverage.covered : undefined) ?? [];
|
|
145
96
|
const cognitive = ranked(files, entry => entry.quality?.cognitiveComplexity);
|
|
146
97
|
const duplication = ranked(files, entry => entry.quality?.duplication?.duplicatedLines);
|
|
147
98
|
const churn = ranked(files, entry => entry.quality?.churn);
|
|
@@ -151,18 +102,57 @@ export function fileMetrics(report, registry = { id: fileTypeId, catalog: [] })
|
|
|
151
102
|
...(pluginMetrics === undefined ? {} : { catalog: pluginMetrics.catalog }),
|
|
152
103
|
...(languages.length === 0 ? {} : { languages }),
|
|
153
104
|
...(churnWindow === undefined ? {} : { churnWindow }),
|
|
154
|
-
hotspots: { complexity: complexity.map(entry => entry.path), missedLines: coverage
|
|
105
|
+
hotspots: { complexity: complexity.map(entry => entry.path), missedLines: coverage,
|
|
155
106
|
...(cognitive === undefined ? {} : { cognitive }), ...(duplication === undefined ? {} : { duplication }),
|
|
156
107
|
...(churn === undefined ? {} : { churn }) } };
|
|
157
108
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
109
|
+
const qualityFields = new Map([
|
|
110
|
+
[definitions.codeLines, 'codeLines'], [definitions.comments, 'commentLines'], [definitions.classes, 'classes'],
|
|
111
|
+
[definitions.cognitiveComplexity, 'cognitiveComplexity'], [definitions.churn, 'churn'],
|
|
112
|
+
]);
|
|
113
|
+
function collectMeasurements(rows, file, includeMeasuredFiles) {
|
|
114
|
+
const duplicated = new Map();
|
|
115
|
+
for (const { path, target, value, definition, covered, total } of rows) {
|
|
116
|
+
if (!path)
|
|
117
|
+
continue;
|
|
118
|
+
if (includeMeasuredFiles)
|
|
119
|
+
file(path);
|
|
120
|
+
const id = canonicalMetricId(definition);
|
|
121
|
+
if (target === 'file' && id === definitions.coverage && covered !== undefined && total !== undefined) {
|
|
122
|
+
file(path).lineCoverage = { covered, total };
|
|
123
|
+
}
|
|
124
|
+
if (value === null || !Number.isSafeInteger(value) || value < 0)
|
|
125
|
+
continue;
|
|
126
|
+
if (target === 'file') {
|
|
127
|
+
const field = qualityFields.get(id);
|
|
128
|
+
if (field)
|
|
129
|
+
quality(file(path))[field] = value;
|
|
130
|
+
else if (id === definitions.lines)
|
|
131
|
+
file(path).lines = value;
|
|
132
|
+
else if (id === definitions.functions)
|
|
133
|
+
file(path).functions = value;
|
|
134
|
+
else if (id === definitions.duplicatedLines)
|
|
135
|
+
duplicated.set(path, value);
|
|
136
|
+
}
|
|
137
|
+
else if (target === 'function' && id === definitions.complexity) {
|
|
138
|
+
const entry = file(path);
|
|
139
|
+
entry.complexity = addComplexity(entry.complexity, { sum: value, maximum: value, measuredFunctions: 1 });
|
|
140
|
+
}
|
|
164
141
|
}
|
|
165
|
-
|
|
142
|
+
return duplicated;
|
|
143
|
+
}
|
|
144
|
+
function addFileQuality(byPath, duplicated, findings) {
|
|
145
|
+
for (const [path, duplicatedLines] of duplicated) {
|
|
146
|
+
const entry = byPath.get(path);
|
|
147
|
+
const codeLines = entry?.quality?.codeLines;
|
|
148
|
+
if (!entry || codeLines === undefined || duplicatedLines > codeLines)
|
|
149
|
+
continue;
|
|
150
|
+
const result = quality(entry);
|
|
151
|
+
result.duplication = { duplicatedLines, codeLines };
|
|
152
|
+
if (findings !== undefined)
|
|
153
|
+
result.maintainability = { smells: 0, effortMinutes: 0 };
|
|
154
|
+
}
|
|
155
|
+
for (const finding of findings ?? []) {
|
|
166
156
|
if (!finding.path || (finding.category !== 'structure' && finding.category !== 'duplication'))
|
|
167
157
|
continue;
|
|
168
158
|
const observations = byPath.get(finding.path)?.quality;
|
|
@@ -255,7 +245,4 @@ function addComplexity(left, right) {
|
|
|
255
245
|
const maximum = left.maximum === null ? right.maximum : Math.max(left.maximum, right.maximum ?? left.maximum);
|
|
256
246
|
return { sum: left.sum + right.sum, maximum, measuredFunctions: left.measuredFunctions + right.measuredFunctions };
|
|
257
247
|
}
|
|
258
|
-
function missedLines(entry) {
|
|
259
|
-
return entry.lineCoverage ? entry.lineCoverage.total - entry.lineCoverage.covered : 0;
|
|
260
|
-
}
|
|
261
248
|
//# sourceMappingURL=file-metrics.js.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Report } from '../validation/report.js';
|
|
2
2
|
import type { InspectionContext } from '../wire/inspection-context-model.js';
|
|
3
|
-
export type { InspectionContext, ProfileBoundary, SourceExclusions } from '../wire/inspection-context-model.js';
|
|
4
3
|
export declare function inspectionProfileDigest(report: Report): string | undefined;
|
|
5
4
|
export declare function inspectionContext(report: Report): InspectionContext | undefined;
|
|
@@ -3,6 +3,7 @@ import { isRecord } from '../../../core/engine/plugin.js';
|
|
|
3
3
|
import { findingImportMethods } from '../../../core/model/scanner-import.js';
|
|
4
4
|
import { nativeScanners, securityCounts } from './security-summary.js';
|
|
5
5
|
import { normalizeFindingIgnore } from '../../../core/model/finding-ignore.js';
|
|
6
|
+
import { historicalPluginTools, legacySyntaxPlugin } from '../../../core/model/report.js';
|
|
6
7
|
import { comparePaths, digest } from '../../../core/model/snapshot.js';
|
|
7
8
|
export function inspectionProfileDigest(report) {
|
|
8
9
|
const profile = readProfile(report.appliedConfig);
|
|
@@ -52,14 +53,15 @@ function readProfile(config) {
|
|
|
52
53
|
coverage = settings;
|
|
53
54
|
}
|
|
54
55
|
const { churnWindow, securityScanners, ...settings } = config;
|
|
55
|
-
const
|
|
56
|
+
const toolchain = historicalPluginTools(settings.plugins);
|
|
57
|
+
const plugins = Array.isArray(toolchain) ? toolchain.map(plugin => {
|
|
56
58
|
if (!isRecord(plugin))
|
|
57
59
|
return plugin;
|
|
58
60
|
const { providesLanguages, ...entry } = plugin;
|
|
59
|
-
if (entry.id ===
|
|
61
|
+
if (entry.id === legacySyntaxPlugin && isDeepStrictEqual(entry.settings, config.parser))
|
|
60
62
|
delete entry.settings;
|
|
61
63
|
return entry;
|
|
62
|
-
}) :
|
|
64
|
+
}) : toolchain;
|
|
63
65
|
// The policy is stable across commits; its matched paths describe this snapshot alone.
|
|
64
66
|
const { generatedExcluded, ...sourceSettings } = source;
|
|
65
67
|
return {
|
|
@@ -3,7 +3,6 @@ import type { LanguageLookup } from '../../../core/model/language.js';
|
|
|
3
3
|
import type { ComplexFunction } from '../wire/public-history-model.js';
|
|
4
4
|
import type { Component } from './components.js';
|
|
5
5
|
import type { InspectionAsset, InspectionDetails, ProfileSettings } from '../wire/inspection-details-model.js';
|
|
6
|
-
export type { InspectionAsset, InspectionDetails, ProfileSettings } from '../wire/inspection-details-model.js';
|
|
7
6
|
export interface InspectionOptions {
|
|
8
7
|
readonly components?: readonly Component[];
|
|
9
8
|
readonly languages?: LanguageLookup;
|