repometry 0.6.0 → 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/cli/main.js +1 -1
- package/target/main/ts/cli/reporting.js +3 -2
- package/target/main/ts/compose/analysis-files.js +1 -1
- package/target/main/ts/compose/analysis-report.js +4 -4
- 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/languages.d.ts +2 -2
- package/target/main/ts/compose/languages.js +3 -23
- 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/file-types.d.ts +19 -0
- package/target/main/ts/core/model/file-types.js +39 -0
- package/target/main/ts/core/model/language.d.ts +4 -0
- 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 +5 -7
- package/target/main/ts/plugins/language-js/extensions.d.ts +0 -2
- package/target/main/ts/plugins/language-js/extensions.js +2 -3
- package/target/main/ts/report/html/app/viewer-file-source.js +1 -1
- package/target/main/ts/report/html/app/viewer-filter.js +1 -1
- package/target/main/ts/report/html/app/viewer-inspection.js +2 -0
- package/target/main/ts/report/html/app/viewer-languages.d.ts +7 -2
- package/target/main/ts/report/html/app/viewer-languages.js +18 -31
- package/target/main/ts/report/html/app/viewer-suggest.js +1 -1
- package/target/main/ts/report/html/app/viewer-table-cells.js +1 -1
- package/target/main/ts/report/html/site/export-site.d.ts +2 -3
- package/target/main/ts/report/html/site/export-site.js +1 -1
- package/target/main/ts/report/html/site/local-server.js +1 -1
- package/target/main/ts/report/json/projections/commit-summary.js +4 -1
- package/target/main/ts/report/json/projections/components.d.ts +1 -1
- package/target/main/ts/report/json/projections/file-metrics.d.ts +2 -3
- package/target/main/ts/report/json/projections/file-metrics.js +75 -78
- package/target/main/ts/report/json/projections/inspection-context.d.ts +1 -3
- package/target/main/ts/report/json/projections/inspection-context.js +10 -24
- package/target/main/ts/report/json/projections/inspection-details.d.ts +7 -4
- package/target/main/ts/report/json/projections/inspection-details.js +5 -5
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
import { fileTypeId, fileTypes } from '../../../core/model/file-types.js';
|
|
1
2
|
import { isRecord } from '../../../core/engine/plugin.js';
|
|
2
3
|
import { canonicalMetricId, definitions } from '../../../core/model/measurement.js';
|
|
4
|
+
import { legacySyntaxPlugin } from '../../../core/model/report.js';
|
|
3
5
|
import { comparePaths } from '../../../core/model/snapshot.js';
|
|
4
6
|
import { metricProjection } from './metric-values.js';
|
|
5
7
|
import { fileMetricsSchema } from '../wire/file-metrics-model.js';
|
|
6
|
-
export {
|
|
7
|
-
export function fileMetrics(report) {
|
|
8
|
+
export function fileMetrics(report, registry = { id: fileTypeId, catalog: [] }) {
|
|
8
9
|
const byPath = new Map();
|
|
9
|
-
const duplicatedLines = new Map();
|
|
10
10
|
const pluginMetrics = metricProjection(report);
|
|
11
11
|
const languages = [];
|
|
12
|
-
const
|
|
12
|
+
const recorded = new Map(report.pluginData?.languages?.map(item => [item.id, item]));
|
|
13
|
+
const languageCatalog = new Map([...fileTypes, ...registry.catalog, ...recorded.values()].map(item => [item.id, item]));
|
|
13
14
|
const languageIndexes = new Map();
|
|
14
15
|
function file(path) {
|
|
15
16
|
const existing = byPath.get(path);
|
|
@@ -19,80 +20,37 @@ export function fileMetrics(report) {
|
|
|
19
20
|
byPath.set(path, metrics);
|
|
20
21
|
return metrics;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
else if (analysed) {
|
|
30
|
-
languages[index].analysed = true;
|
|
23
|
+
function languageIndex(id, analysed) {
|
|
24
|
+
const existing = languageIndexes.get(id);
|
|
25
|
+
if (existing !== undefined) {
|
|
26
|
+
if (analysed)
|
|
27
|
+
languages[existing].analysed = true;
|
|
28
|
+
return existing;
|
|
31
29
|
}
|
|
30
|
+
const index = languages.length;
|
|
31
|
+
languageIndexes.set(id, index);
|
|
32
|
+
const display = languageCatalog.get(id);
|
|
33
|
+
languages.push({ id, label: display?.label ?? (id === 'other' ? 'Other' : id.toUpperCase()),
|
|
34
|
+
...(display?.color === undefined ? {} : { color: display.color }), analysed });
|
|
35
|
+
return index;
|
|
36
|
+
}
|
|
37
|
+
for (const { path, lines, bytes, language, analysed, provider } of report.pluginData?.inventory ?? []) {
|
|
32
38
|
const entry = file(path);
|
|
33
39
|
entry.lines = lines;
|
|
34
40
|
if (bytes !== undefined)
|
|
35
41
|
entry.bytes = bytes;
|
|
36
|
-
entry.language =
|
|
42
|
+
entry.language = languageIndex(provider !== undefined || recorded.has(language) ? language : fileTypeId(path, language), analysed);
|
|
37
43
|
entry.analysed = analysed;
|
|
38
44
|
if (provider !== undefined)
|
|
39
45
|
entry.provider = provider;
|
|
40
46
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
continue;
|
|
44
|
-
const id = canonicalMetricId(row.definition);
|
|
45
|
-
if (pluginMetrics)
|
|
46
|
-
file(row.path);
|
|
47
|
-
if (row.target === 'file' && id === definitions.coverage && row.covered !== undefined && row.total !== undefined) {
|
|
48
|
-
file(row.path).lineCoverage = { covered: row.covered, total: row.total };
|
|
49
|
-
}
|
|
50
|
-
if (row.value === null || !Number.isSafeInteger(row.value) || row.value < 0)
|
|
51
|
-
continue;
|
|
52
|
-
if (row.target === 'file' && id === definitions.lines)
|
|
53
|
-
file(row.path).lines = row.value;
|
|
54
|
-
if (row.target === 'file' && id === definitions.functions)
|
|
55
|
-
file(row.path).functions = row.value;
|
|
56
|
-
if (row.target === 'file') {
|
|
57
|
-
switch (id) {
|
|
58
|
-
case definitions.codeLines:
|
|
59
|
-
quality(file(row.path)).codeLines = row.value;
|
|
60
|
-
break;
|
|
61
|
-
case definitions.comments:
|
|
62
|
-
quality(file(row.path)).commentLines = row.value;
|
|
63
|
-
break;
|
|
64
|
-
case definitions.classes:
|
|
65
|
-
quality(file(row.path)).classes = row.value;
|
|
66
|
-
break;
|
|
67
|
-
case definitions.cognitiveComplexity:
|
|
68
|
-
quality(file(row.path)).cognitiveComplexity = row.value;
|
|
69
|
-
break;
|
|
70
|
-
case definitions.churn:
|
|
71
|
-
quality(file(row.path)).churn = row.value;
|
|
72
|
-
break;
|
|
73
|
-
case definitions.duplicatedLines:
|
|
74
|
-
duplicatedLines.set(row.path, row.value);
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (row.target === 'function' && id === definitions.complexity) {
|
|
79
|
-
const target = file(row.path);
|
|
80
|
-
target.complexity = addComplexity(target.complexity, { sum: row.value, maximum: row.value, measuredFunctions: 1 });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
for (const [path, duplicateCount] of duplicatedLines) {
|
|
84
|
-
const entry = byPath.get(path);
|
|
85
|
-
const codeLines = entry?.quality?.codeLines;
|
|
86
|
-
if (entry && codeLines !== undefined && duplicateCount <= codeLines) {
|
|
87
|
-
quality(entry).duplication = { duplicatedLines: duplicateCount, codeLines };
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
addFileFindings(byPath, report.findings);
|
|
47
|
+
const duplicatedLines = collectMeasurements(report.measurements, file, pluginMetrics !== undefined);
|
|
48
|
+
addFileQuality(byPath, duplicatedLines, report.findings);
|
|
91
49
|
let unassignedDiagnostics = 0;
|
|
92
50
|
for (const diagnostic of report.diagnostics) {
|
|
93
51
|
const { path, operation } = diagnostic;
|
|
94
52
|
const target = path === undefined ? undefined
|
|
95
|
-
: operation ===
|
|
53
|
+
: operation === `${legacySyntaxPlugin}/parse` || operation.startsWith('structure/') ? file(path) : byPath.get(path);
|
|
96
54
|
if (target)
|
|
97
55
|
target.diagnosticCount++;
|
|
98
56
|
else
|
|
@@ -101,6 +59,9 @@ export function fileMetrics(report) {
|
|
|
101
59
|
const files = [...byPath.values()].sort(byName);
|
|
102
60
|
const directories = new Map();
|
|
103
61
|
for (const entry of files) {
|
|
62
|
+
if (entry.language === undefined) {
|
|
63
|
+
entry.language = languageIndex(registry.id(entry.path), entry.lines !== null || entry.lineCoverage !== null || entry.functions !== null);
|
|
64
|
+
}
|
|
104
65
|
if (pluginMetrics && entry.analysed !== false) {
|
|
105
66
|
const values = pluginMetrics.values(entry.path);
|
|
106
67
|
if (Object.keys(values).length)
|
|
@@ -130,8 +91,8 @@ export function fileMetrics(report) {
|
|
|
130
91
|
const complexity = files.filter(entry => entry.complexity?.maximum != null)
|
|
131
92
|
.sort((left, right) => right.complexity.maximum - left.complexity.maximum
|
|
132
93
|
|| right.complexity.sum - left.complexity.sum || byName(left, right));
|
|
133
|
-
const coverage = files
|
|
134
|
-
.
|
|
94
|
+
const coverage = ranked(files, ({ lineCoverage }) => lineCoverage && lineCoverage.covered < lineCoverage.total
|
|
95
|
+
? lineCoverage.total - lineCoverage.covered : undefined) ?? [];
|
|
135
96
|
const cognitive = ranked(files, entry => entry.quality?.cognitiveComplexity);
|
|
136
97
|
const duplication = ranked(files, entry => entry.quality?.duplication?.duplicatedLines);
|
|
137
98
|
const churn = ranked(files, entry => entry.quality?.churn);
|
|
@@ -141,18 +102,57 @@ export function fileMetrics(report) {
|
|
|
141
102
|
...(pluginMetrics === undefined ? {} : { catalog: pluginMetrics.catalog }),
|
|
142
103
|
...(languages.length === 0 ? {} : { languages }),
|
|
143
104
|
...(churnWindow === undefined ? {} : { churnWindow }),
|
|
144
|
-
hotspots: { complexity: complexity.map(entry => entry.path), missedLines: coverage
|
|
105
|
+
hotspots: { complexity: complexity.map(entry => entry.path), missedLines: coverage,
|
|
145
106
|
...(cognitive === undefined ? {} : { cognitive }), ...(duplication === undefined ? {} : { duplication }),
|
|
146
107
|
...(churn === undefined ? {} : { churn }) } };
|
|
147
108
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
+
}
|
|
141
|
+
}
|
|
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
154
|
}
|
|
155
|
-
for (const finding of findings) {
|
|
155
|
+
for (const finding of findings ?? []) {
|
|
156
156
|
if (!finding.path || (finding.category !== 'structure' && finding.category !== 'duplication'))
|
|
157
157
|
continue;
|
|
158
158
|
const observations = byPath.get(finding.path)?.quality;
|
|
@@ -245,7 +245,4 @@ function addComplexity(left, right) {
|
|
|
245
245
|
const maximum = left.maximum === null ? right.maximum : Math.max(left.maximum, right.maximum ?? left.maximum);
|
|
246
246
|
return { sum: left.sum + right.sum, maximum, measuredFunctions: left.measuredFunctions + right.measuredFunctions };
|
|
247
247
|
}
|
|
248
|
-
function missedLines(entry) {
|
|
249
|
-
return entry.lineCoverage ? entry.lineCoverage.total - entry.lineCoverage.covered : 0;
|
|
250
|
-
}
|
|
251
248
|
//# sourceMappingURL=file-metrics.js.map
|
|
@@ -1,6 +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
|
-
|
|
6
|
-
export declare function inspectionHistory(reports: readonly Report[]): Record<string, InspectionContext>;
|
|
4
|
+
export declare function inspectionContext(report: Report): InspectionContext | undefined;
|
|
@@ -3,33 +3,18 @@ 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);
|
|
9
10
|
return profile ? digest(JSON.stringify(profile.settings, (_key, value) => isRecord(value)
|
|
10
11
|
? Object.fromEntries(Object.entries(value).sort(([a], [b]) => comparePaths(a, b))) : value)) : undefined;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const previous = entries[index + 1];
|
|
18
|
-
let boundary = null;
|
|
19
|
-
if (previous) {
|
|
20
|
-
if (!profile || !previous.profile)
|
|
21
|
-
boundary = 'unavailable';
|
|
22
|
-
else if (!isDeepStrictEqual(profile.settings, previous.profile.settings))
|
|
23
|
-
boundary = 'changed';
|
|
24
|
-
}
|
|
25
|
-
const context = {
|
|
26
|
-
exclusions: profile?.exclusions ?? null,
|
|
27
|
-
boundary,
|
|
28
|
-
...scannerContext(report),
|
|
29
|
-
...ignoreContext(report),
|
|
30
|
-
};
|
|
31
|
-
return [report.subject.id, context];
|
|
32
|
-
}));
|
|
13
|
+
export function inspectionContext(report) {
|
|
14
|
+
if (report.subject.kind !== 'commit')
|
|
15
|
+
return undefined;
|
|
16
|
+
return { exclusions: readProfile(report.appliedConfig)?.exclusions ?? null, boundary: null,
|
|
17
|
+
...scannerContext(report), ...ignoreContext(report) };
|
|
33
18
|
}
|
|
34
19
|
function ignoreContext(report) {
|
|
35
20
|
if (report.appliedConfig.findingIgnore === undefined)
|
|
@@ -68,14 +53,15 @@ function readProfile(config) {
|
|
|
68
53
|
coverage = settings;
|
|
69
54
|
}
|
|
70
55
|
const { churnWindow, securityScanners, ...settings } = config;
|
|
71
|
-
const
|
|
56
|
+
const toolchain = historicalPluginTools(settings.plugins);
|
|
57
|
+
const plugins = Array.isArray(toolchain) ? toolchain.map(plugin => {
|
|
72
58
|
if (!isRecord(plugin))
|
|
73
59
|
return plugin;
|
|
74
60
|
const { providesLanguages, ...entry } = plugin;
|
|
75
|
-
if (entry.id ===
|
|
61
|
+
if (entry.id === legacySyntaxPlugin && isDeepStrictEqual(entry.settings, config.parser))
|
|
76
62
|
delete entry.settings;
|
|
77
63
|
return entry;
|
|
78
|
-
}) :
|
|
64
|
+
}) : toolchain;
|
|
79
65
|
// The policy is stable across commits; its matched paths describe this snapshot alone.
|
|
80
66
|
const { generatedExcluded, ...sourceSettings } = source;
|
|
81
67
|
return {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { Report } from '../validation/report.js';
|
|
2
|
-
import type {
|
|
2
|
+
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
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export interface InspectionOptions {
|
|
7
|
+
readonly components?: readonly Component[];
|
|
8
|
+
readonly languages?: LanguageLookup;
|
|
9
|
+
}
|
|
10
|
+
export declare function inspectionAsset(report: Report, options?: InspectionOptions): InspectionAsset;
|
|
11
|
+
export declare function inspectionDetails(report: Report, { components, languages }?: InspectionOptions): InspectionDetails;
|
|
9
12
|
/** The applied configuration, field by field; whatever is missing or malformed is left out rather than guessed. */
|
|
10
13
|
export declare function profileSettings(applied: unknown): ProfileSettings | undefined;
|
|
11
14
|
export declare function complexFunctions(report: Report): readonly ComplexFunction[];
|
|
@@ -2,14 +2,14 @@ import { canonicalMetricId, definitions } from '../../../core/model/measurement.
|
|
|
2
2
|
import { lcovLines } from '../../../core/model/line-coverage.js';
|
|
3
3
|
import { comparePaths } from '../../../core/model/snapshot.js';
|
|
4
4
|
import { fileMetrics } from './file-metrics.js';
|
|
5
|
-
import {
|
|
5
|
+
import { inspectionContext } from './inspection-context.js';
|
|
6
6
|
import { componentFiles } from './components.js';
|
|
7
|
-
export function inspectionAsset(report,
|
|
7
|
+
export function inspectionAsset(report, options) {
|
|
8
8
|
return { schema: 'urn:repometry:schema:viewer-inspection:1', sha: report.subject.id,
|
|
9
|
-
context, inspection: inspectionDetails(report,
|
|
9
|
+
context: inspectionContext(report), inspection: inspectionDetails(report, options) };
|
|
10
10
|
}
|
|
11
|
-
export function inspectionDetails(report, components = []) {
|
|
12
|
-
const metrics = fileMetrics(report);
|
|
11
|
+
export function inspectionDetails(report, { components = [], languages } = {}) {
|
|
12
|
+
const metrics = fileMetrics(report, languages);
|
|
13
13
|
const lineCoverage = report.pluginData?.products[lcovLines.id]?.[0]?.value;
|
|
14
14
|
const profile = profileSettings(report.appliedConfig);
|
|
15
15
|
const ruleCatalog = report.pluginData?.rules.flatMap(({ plugin, rules }) => rules.map(rule => ({
|