repometry 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/target/main/resources/config/process-plugins-v1.schema.json +75 -0
- package/target/main/resources/report/json/report-v2.schema.json +21 -1
- package/target/main/resources/report/json/repository-summary-v1.schema.json +9 -0
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +11 -3
- package/target/main/resources/viewer/files.css +6 -0
- package/target/main/resources/viewer/index.html +1 -1
- package/target/main/resources/viewer/styles.css +1 -0
- package/target/main/ts/cli/config.d.ts +1 -0
- package/target/main/ts/cli/config.js +3 -2
- package/target/main/ts/cli/main.js +37 -19
- package/target/main/ts/cli/reporting.js +3 -3
- package/target/main/ts/compose/analysis-files.d.ts +1 -0
- package/target/main/ts/compose/analysis-files.js +27 -7
- package/target/main/ts/compose/analysis-imports.js +2 -1
- package/target/main/ts/compose/analysis-report.js +9 -5
- package/target/main/ts/compose/analysis-results.d.ts +4 -1
- package/target/main/ts/compose/analysis-results.js +3 -0
- package/target/main/ts/compose/analysis-sources.d.ts +2 -32
- package/target/main/ts/compose/analysis-sources.js +4 -4
- package/target/main/ts/compose/languages.js +4 -1
- package/target/main/ts/compose/plugin-list.d.ts +11 -2
- package/target/main/ts/compose/plugin-list.js +6 -3
- package/target/main/ts/compose/process-plugins.d.ts +2 -0
- package/target/main/ts/compose/process-plugins.js +63 -0
- package/target/main/ts/compose/structure-measures.d.ts +5 -0
- package/target/main/ts/compose/structure-measures.js +57 -0
- package/target/main/ts/core/engine/execute.js +40 -39
- package/target/main/ts/core/engine/manifest.js +45 -38
- package/target/main/ts/core/model/clone-source.js +0 -1
- package/target/main/ts/core/model/code-structure.d.ts +14 -9
- package/target/main/ts/core/model/code-structure.js +23 -10
- package/target/main/ts/core/model/language.d.ts +2 -0
- package/target/main/ts/core/model/plugin-data.d.ts +2 -0
- package/target/main/ts/core/model/quality-summary.d.ts +4 -0
- package/target/main/ts/core/model/quality-summary.js +53 -29
- package/target/main/ts/core/model/report.d.ts +8 -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/plugin.d.ts +1 -1
- package/target/main/ts/plugins/coverage/coverage.d.ts +2 -1
- package/target/main/ts/plugins/coverage/coverage.js +106 -108
- 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/plugins/language-js/function-facts.d.ts +1 -1
- package/target/main/ts/plugins/language-js/function-facts.js +0 -1
- package/target/main/ts/plugins/language-js/js-security.js +25 -37
- package/target/main/ts/plugins/language-js/structural-observations.js +5 -4
- package/target/main/ts/plugins/maintainability/maintainability.d.ts +1 -1
- package/target/main/ts/plugins/maintainability/maintainability.js +9 -8
- package/target/main/ts/plugins/security/dockerfile.js +45 -37
- package/target/main/ts/plugins/structure/structure.js +2 -2
- package/target/main/ts/report/html/app/viewer-code-map.js +6 -5
- package/target/main/ts/report/html/app/viewer-columns.d.ts +2 -0
- package/target/main/ts/report/html/app/viewer-columns.js +9 -4
- package/target/main/ts/report/html/app/viewer-data.d.ts +2 -1
- package/target/main/ts/report/html/app/viewer-data.js +1 -1
- package/target/main/ts/report/html/app/viewer-file-aside.d.ts +5 -9
- package/target/main/ts/report/html/app/viewer-file-aside.js +18 -8
- package/target/main/ts/report/html/app/viewer-file-figures.d.ts +2 -0
- package/target/main/ts/report/html/app/viewer-file-figures.js +6 -1
- package/target/main/ts/report/html/app/viewer-hotspots.js +7 -5
- package/target/main/ts/report/html/app/viewer-inspection.js +1 -1
- package/target/main/ts/report/html/app/viewer-issue-group.js +2 -2
- package/target/main/ts/report/html/app/viewer-languages.d.ts +3 -2
- package/target/main/ts/report/html/app/viewer-languages.js +14 -7
- package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +4 -4
- package/target/main/ts/report/html/app/viewer-line-coverage.js +11 -24
- package/target/main/ts/report/html/app/viewer-map-scale.d.ts +1 -1
- package/target/main/ts/report/html/app/viewer-map-scale.js +1 -1
- package/target/main/ts/report/html/app/viewer-map-shape.d.ts +2 -2
- package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -3
- package/target/main/ts/report/html/app/viewer-metric-registry.js +0 -9
- package/target/main/ts/report/html/app/viewer-metrics-view.js +1 -4
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +2 -0
- package/target/main/ts/report/html/app/viewer-metrics.js +5 -0
- package/target/main/ts/report/html/app/viewer-overview-cards.js +4 -1
- package/target/main/ts/report/html/app/viewer-overview-hotspots.js +2 -2
- package/target/main/ts/report/html/app/viewer-profile.js +15 -1
- package/target/main/ts/report/html/app/viewer-source-view.js +7 -6
- package/target/main/ts/report/html/app/viewer-table-cells.js +8 -2
- package/target/main/ts/report/html/app/viewer-table-rows.d.ts +2 -0
- package/target/main/ts/report/html/app/viewer-table-rows.js +7 -5
- package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +2 -5
- package/target/main/ts/report/html/app/viewer-tokenizer.js +9 -12
- package/target/main/ts/report/html/app/viewer-totals.d.ts +6 -0
- package/target/main/ts/report/html/app/viewer-totals.js +11 -0
- package/target/main/ts/report/html/app/viewer-trend-data.d.ts +1 -1
- package/target/main/ts/report/html/app/viewer-trend-data.js +1 -1
- package/target/main/ts/report/html/app/viewer-trend-nav.js +3 -2
- package/target/main/ts/report/html/app/viewer.js +1 -7
- package/target/main/ts/report/json/projections/commit-summary.js +5 -0
- 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 +69 -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/target/main/ts/report/json/projections/inspection-details.js +32 -14
- package/target/main/ts/report/json/projections/metric-values.d.ts +1 -0
- package/target/main/ts/report/json/projections/metric-values.js +36 -3
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +8 -1
|
@@ -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,14 @@ export function fileMetrics(report, registry = { id: fileTypeId, catalog: [] })
|
|
|
45
44
|
if (provider !== undefined)
|
|
46
45
|
entry.provider = provider;
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
+
const skipped = new Set(report.ruleSkips?.map(({ path }) => path));
|
|
49
|
+
addFileQuality(byPath, duplicatedLines, report.findings, skipped);
|
|
98
50
|
let unassignedDiagnostics = 0;
|
|
99
51
|
for (const diagnostic of report.diagnostics) {
|
|
100
52
|
const { path, operation } = diagnostic;
|
|
101
53
|
const target = path === undefined ? undefined
|
|
102
|
-
: operation ===
|
|
54
|
+
: operation === `${legacySyntaxPlugin}/parse` || operation.startsWith('structure/') ? file(path) : byPath.get(path);
|
|
103
55
|
if (target)
|
|
104
56
|
target.diagnosticCount++;
|
|
105
57
|
else
|
|
@@ -116,7 +68,7 @@ export function fileMetrics(report, registry = { id: fileTypeId, catalog: [] })
|
|
|
116
68
|
if (Object.keys(values).length)
|
|
117
69
|
entry.values = values;
|
|
118
70
|
}
|
|
119
|
-
if (entry.functions === 0 && !entry.complexity) {
|
|
71
|
+
if (entry.functions === 0 && !entry.complexity && pluginMetrics?.isAvailable(definitions.complexity, entry.path) !== false) {
|
|
120
72
|
entry.complexity = { sum: 0, maximum: null, measuredFunctions: 0 };
|
|
121
73
|
}
|
|
122
74
|
let path = entry.path;
|
|
@@ -135,13 +87,14 @@ export function fileMetrics(report, registry = { id: fileTypeId, catalog: [] })
|
|
|
135
87
|
const values = pluginMetrics.values(entry.path, true);
|
|
136
88
|
if (Object.keys(values).length)
|
|
137
89
|
entry.values = values;
|
|
90
|
+
applyDirectoryAvailability(entry, pluginMetrics.isAvailable);
|
|
138
91
|
}
|
|
139
92
|
}
|
|
140
93
|
const complexity = files.filter(entry => entry.complexity?.maximum != null)
|
|
141
94
|
.sort((left, right) => right.complexity.maximum - left.complexity.maximum
|
|
142
95
|
|| right.complexity.sum - left.complexity.sum || byName(left, right));
|
|
143
|
-
const coverage = files
|
|
144
|
-
.
|
|
96
|
+
const coverage = ranked(files, ({ lineCoverage }) => lineCoverage && lineCoverage.covered < lineCoverage.total
|
|
97
|
+
? lineCoverage.total - lineCoverage.covered : undefined) ?? [];
|
|
145
98
|
const cognitive = ranked(files, entry => entry.quality?.cognitiveComplexity);
|
|
146
99
|
const duplication = ranked(files, entry => entry.quality?.duplication?.duplicatedLines);
|
|
147
100
|
const churn = ranked(files, entry => entry.quality?.churn);
|
|
@@ -151,18 +104,71 @@ export function fileMetrics(report, registry = { id: fileTypeId, catalog: [] })
|
|
|
151
104
|
...(pluginMetrics === undefined ? {} : { catalog: pluginMetrics.catalog }),
|
|
152
105
|
...(languages.length === 0 ? {} : { languages }),
|
|
153
106
|
...(churnWindow === undefined ? {} : { churnWindow }),
|
|
154
|
-
hotspots: { complexity: complexity.map(entry => entry.path), missedLines: coverage
|
|
107
|
+
hotspots: { complexity: complexity.map(entry => entry.path), missedLines: coverage,
|
|
155
108
|
...(cognitive === undefined ? {} : { cognitive }), ...(duplication === undefined ? {} : { duplication }),
|
|
156
109
|
...(churn === undefined ? {} : { churn }) } };
|
|
157
110
|
}
|
|
158
|
-
|
|
159
|
-
|
|
111
|
+
const qualityFields = new Map([
|
|
112
|
+
[definitions.codeLines, 'codeLines'], [definitions.comments, 'commentLines'], [definitions.classes, 'classes'],
|
|
113
|
+
[definitions.cognitiveComplexity, 'cognitiveComplexity'], [definitions.churn, 'churn'],
|
|
114
|
+
]);
|
|
115
|
+
function collectMeasurements(rows, file, includeMeasuredFiles) {
|
|
116
|
+
const duplicated = new Map();
|
|
117
|
+
for (const { path, target, value, definition, covered, total } of rows) {
|
|
118
|
+
if (!path)
|
|
119
|
+
continue;
|
|
120
|
+
if (includeMeasuredFiles)
|
|
121
|
+
file(path);
|
|
122
|
+
const id = canonicalMetricId(definition);
|
|
123
|
+
if (target === 'file' && id === definitions.coverage && covered !== undefined && total !== undefined) {
|
|
124
|
+
file(path).lineCoverage = { covered, total };
|
|
125
|
+
}
|
|
126
|
+
if (value === null || !Number.isSafeInteger(value) || value < 0)
|
|
127
|
+
continue;
|
|
128
|
+
if (target === 'file') {
|
|
129
|
+
const field = qualityFields.get(id);
|
|
130
|
+
if (field)
|
|
131
|
+
quality(file(path))[field] = value;
|
|
132
|
+
else if (id === definitions.lines)
|
|
133
|
+
file(path).lines = value;
|
|
134
|
+
else if (id === definitions.functions)
|
|
135
|
+
file(path).functions = value;
|
|
136
|
+
else if (id === definitions.duplicatedLines)
|
|
137
|
+
duplicated.set(path, value);
|
|
138
|
+
}
|
|
139
|
+
else if (target === 'function' && id === definitions.complexity) {
|
|
140
|
+
const entry = file(path);
|
|
141
|
+
entry.complexity = addComplexity(entry.complexity, { sum: value, maximum: value, measuredFunctions: 1 });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return duplicated;
|
|
145
|
+
}
|
|
146
|
+
function applyDirectoryAvailability(entry, available) {
|
|
147
|
+
const known = (id) => available(id, entry.path, true);
|
|
148
|
+
if (!known(definitions.functions))
|
|
149
|
+
entry.functions = null;
|
|
150
|
+
if (!known(definitions.complexity))
|
|
151
|
+
entry.complexity = null;
|
|
152
|
+
if (!entry.quality)
|
|
160
153
|
return;
|
|
161
|
-
for (const
|
|
162
|
-
if (
|
|
163
|
-
entry.quality
|
|
154
|
+
for (const [id, field] of qualityFields)
|
|
155
|
+
if (!known(id))
|
|
156
|
+
delete entry.quality[field];
|
|
157
|
+
if (!known(definitions.duplicatedLines) || !known(definitions.codeLines))
|
|
158
|
+
delete entry.quality.duplication;
|
|
159
|
+
}
|
|
160
|
+
function addFileQuality(byPath, duplicated, findings, skipped) {
|
|
161
|
+
for (const [path, duplicatedLines] of duplicated) {
|
|
162
|
+
const entry = byPath.get(path);
|
|
163
|
+
const codeLines = entry?.quality?.codeLines;
|
|
164
|
+
if (!entry || codeLines === undefined || duplicatedLines > codeLines)
|
|
165
|
+
continue;
|
|
166
|
+
const result = quality(entry);
|
|
167
|
+
result.duplication = { duplicatedLines, codeLines };
|
|
168
|
+
if (findings !== undefined && !skipped.has(path))
|
|
169
|
+
result.maintainability = { smells: 0, effortMinutes: 0 };
|
|
164
170
|
}
|
|
165
|
-
for (const finding of findings) {
|
|
171
|
+
for (const finding of findings ?? []) {
|
|
166
172
|
if (!finding.path || (finding.category !== 'structure' && finding.category !== 'duplication'))
|
|
167
173
|
continue;
|
|
168
174
|
const observations = byPath.get(finding.path)?.quality;
|
|
@@ -255,7 +261,4 @@ function addComplexity(left, right) {
|
|
|
255
261
|
const maximum = left.maximum === null ? right.maximum : Math.max(left.maximum, right.maximum ?? left.maximum);
|
|
256
262
|
return { sum: left.sum + right.sum, maximum, measuredFunctions: left.measuredFunctions + right.measuredFunctions };
|
|
257
263
|
}
|
|
258
|
-
function missedLines(entry) {
|
|
259
|
-
return entry.lineCoverage ? entry.lineCoverage.total - entry.lineCoverage.covered : 0;
|
|
260
|
-
}
|
|
261
264
|
//# 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;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { javascriptType, typescriptType } from '../../../core/model/file-types.js';
|
|
2
|
+
import { isRecord } from '../../../core/model/plugin-data.js';
|
|
3
|
+
import { legacySyntaxPlugin } from '../../../core/model/report.js';
|
|
1
4
|
import { canonicalMetricId, definitions } from '../../../core/model/measurement.js';
|
|
2
5
|
import { lcovLines } from '../../../core/model/line-coverage.js';
|
|
3
6
|
import { comparePaths } from '../../../core/model/snapshot.js';
|
|
4
7
|
import { fileMetrics } from './file-metrics.js';
|
|
5
8
|
import { inspectionContext } from './inspection-context.js';
|
|
9
|
+
import { isLanguageDisplay } from '../../../core/model/language.js';
|
|
6
10
|
import { componentFiles } from './components.js';
|
|
7
11
|
export function inspectionAsset(report, options) {
|
|
8
12
|
return { schema: 'urn:repometry:schema:viewer-inspection:1', sha: report.subject.id,
|
|
@@ -25,34 +29,48 @@ export function inspectionDetails(report, { components = [], languages } = {}) {
|
|
|
25
29
|
}
|
|
26
30
|
/** The applied configuration, field by field; whatever is missing or malformed is left out rather than guessed. */
|
|
27
31
|
export function profileSettings(applied) {
|
|
28
|
-
if (!
|
|
32
|
+
if (!isRecord(applied))
|
|
29
33
|
return undefined;
|
|
30
|
-
const source =
|
|
31
|
-
const maintainability =
|
|
32
|
-
const rules =
|
|
34
|
+
const source = isRecord(applied.source) ? applied.source : {};
|
|
35
|
+
const maintainability = isRecord(applied.maintainability) ? applied.maintainability : {};
|
|
36
|
+
const rules = isRecord(maintainability.structuralRules) ? Object.entries(maintainability.structuralRules).flatMap(([rule, value]) => isRecord(value) && finite(value.limit) && finite(value.minutesPerExcess)
|
|
33
37
|
? [{ plugin: 'maintainability', rule, limit: value.limit, minutesPerExcess: value.minutesPerExcess }] : []) : [];
|
|
34
38
|
const duplication = maintainability.duplication;
|
|
35
39
|
const model = maintainability.debtModel;
|
|
36
40
|
const churn = applied.churn;
|
|
41
|
+
const plugins = Array.isArray(applied.plugins) ? applied.plugins.filter(isRecord) : [];
|
|
42
|
+
const languages = profileLanguages(plugins, new Set(strings(source.extensions)));
|
|
37
43
|
return {
|
|
38
44
|
id: typeof applied.profile === 'string' ? applied.profile : null,
|
|
39
|
-
|
|
45
|
+
...(languages.length ? { languages } : {}),
|
|
40
46
|
excludedPaths: [...new Set([...strings(source.defaultExclusions), ...strings(source.excludedPaths), ...strings(source.generatedExcluded)])],
|
|
41
47
|
excludedDirectories: strings(source.excludedDirectories),
|
|
42
48
|
rules,
|
|
43
|
-
duplication:
|
|
49
|
+
duplication: isRecord(duplication) && finite(duplication.minCodeLines) && finite(duplication.minNodes) && finite(duplication.minutesPerRepeatedLine)
|
|
44
50
|
? { minCodeLines: duplication.minCodeLines, minNodes: duplication.minNodes, minutesPerRepeatedLine: duplication.minutesPerRepeatedLine } : null,
|
|
45
|
-
debtModel:
|
|
51
|
+
debtModel: isRecord(model) && typeof model.name === 'string' && finite(model.scale) && finite(model.exponent) && finite(model.minutesPerPersonMonth)
|
|
46
52
|
? { name: model.name, scale: model.scale, exponent: model.exponent, minutesPerPersonMonth: model.minutesPerPersonMonth } : null,
|
|
47
|
-
churn:
|
|
48
|
-
ignore: Array.isArray(applied.findingIgnore) ? applied.findingIgnore.flatMap(entry =>
|
|
49
|
-
analyzers:
|
|
50
|
-
? [{ id
|
|
51
|
-
? Object.fromEntries(Object.entries(
|
|
53
|
+
churn: isRecord(churn) && finite(churn.lookbackDays) && finite(churn.maxCommits) ? { lookbackDays: churn.lookbackDays, maxCommits: churn.maxCommits } : null,
|
|
54
|
+
ignore: Array.isArray(applied.findingIgnore) ? applied.findingIgnore.flatMap(entry => isRecord(entry) ? [Object.fromEntries(['tool', 'rule', 'path', 'reason'].flatMap(key => typeof entry[key] === 'string' ? [[key, entry[key]]] : []))] : []) : [],
|
|
55
|
+
analyzers: plugins.flatMap(({ id, version, tools }) => typeof id === 'string' && typeof version === 'string'
|
|
56
|
+
? [{ id, version, tools: isRecord(tools)
|
|
57
|
+
? Object.fromEntries(Object.entries(tools).filter((entry) => typeof entry[1] === 'string')) : {} }] : []),
|
|
52
58
|
};
|
|
53
59
|
}
|
|
54
|
-
function
|
|
55
|
-
|
|
60
|
+
function profileLanguages(plugins, recordedExtensions) {
|
|
61
|
+
const recorded = plugins.flatMap(({ id: plugin, providesLanguages }) => {
|
|
62
|
+
if (typeof plugin !== 'string' || !Array.isArray(providesLanguages))
|
|
63
|
+
return [];
|
|
64
|
+
return providesLanguages.flatMap(language => isRecord(language) && isLanguageDisplay(language)
|
|
65
|
+
? [{ plugin, id: language.id, label: language.label, extensions: strings(language.extensions), globs: strings(language.globs) }]
|
|
66
|
+
: []);
|
|
67
|
+
});
|
|
68
|
+
if (recorded.length)
|
|
69
|
+
return recorded;
|
|
70
|
+
return [javascriptType, typescriptType].flatMap(({ id, label, extensions }) => {
|
|
71
|
+
const selected = extensions.filter(ext => recordedExtensions.has(ext));
|
|
72
|
+
return selected.length ? [{ plugin: legacySyntaxPlugin, id, label, extensions: selected, globs: [] }] : [];
|
|
73
|
+
});
|
|
56
74
|
}
|
|
57
75
|
function finite(value) {
|
|
58
76
|
return typeof value === 'number' && Number.isFinite(value);
|
|
@@ -4,5 +4,6 @@ export declare function metricProjection(report: Report): {
|
|
|
4
4
|
catalog: MetricDescriptor[];
|
|
5
5
|
privateMetrics: string[] | undefined;
|
|
6
6
|
values: (path?: string, directory?: boolean) => MetricValues;
|
|
7
|
+
isAvailable: (id: string, path?: string, directory?: boolean) => boolean;
|
|
7
8
|
} | undefined;
|
|
8
9
|
export declare function canonicalMetricDescriptor(metric: MetricDescriptor): MetricDescriptor;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { canonicalMetricId } from '../../../core/model/measurement.js';
|
|
1
|
+
import { canonicalMetricId, definitions } from '../../../core/model/measurement.js';
|
|
2
|
+
const structureMetricIds = {
|
|
3
|
+
functions: definitions.functions, cyclomaticComplexity: definitions.complexity,
|
|
4
|
+
cognitiveComplexity: definitions.cognitiveComplexity, classes: definitions.classes,
|
|
5
|
+
commentLines: definitions.comments, codeLines: definitions.codeLines, duplication: definitions.duplicatedLines,
|
|
6
|
+
};
|
|
2
7
|
export function metricProjection(report) {
|
|
3
8
|
const metadata = report.pluginData;
|
|
4
9
|
if (!metadata?.metrics.length)
|
|
@@ -16,6 +21,31 @@ export function metricProjection(report) {
|
|
|
16
21
|
else
|
|
17
22
|
rows.set(id, [row]);
|
|
18
23
|
}
|
|
24
|
+
const unavailable = new Map();
|
|
25
|
+
for (const { path, unmeasured } of metadata.inventory ?? []) {
|
|
26
|
+
for (const measure of unmeasured ?? []) {
|
|
27
|
+
const id = structureMetricIds[measure];
|
|
28
|
+
if (id === undefined)
|
|
29
|
+
continue;
|
|
30
|
+
let files = unavailable.get(id);
|
|
31
|
+
if (!files)
|
|
32
|
+
unavailable.set(id, files = new Set());
|
|
33
|
+
files.add(path);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function isAvailable(id, path, directory = false) {
|
|
37
|
+
const files = unavailable.get(id);
|
|
38
|
+
if (!files)
|
|
39
|
+
return true;
|
|
40
|
+
if (path === undefined || (directory && path === ''))
|
|
41
|
+
return false;
|
|
42
|
+
if (!directory)
|
|
43
|
+
return !files.has(path);
|
|
44
|
+
for (const file of files)
|
|
45
|
+
if (file.startsWith(path + '/'))
|
|
46
|
+
return false;
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
19
49
|
function values(path, directory = false) {
|
|
20
50
|
const result = {};
|
|
21
51
|
for (const [index, metric] of metrics.entries()) {
|
|
@@ -23,7 +53,10 @@ export function metricProjection(report) {
|
|
|
23
53
|
continue;
|
|
24
54
|
const rowValues = (id) => rows.get(id) ?? [];
|
|
25
55
|
let value;
|
|
26
|
-
if (metric.
|
|
56
|
+
if (!isAvailable(metric.id, path, directory)) {
|
|
57
|
+
value = null;
|
|
58
|
+
}
|
|
59
|
+
else if (metric.ratio) {
|
|
27
60
|
const numerator = rollup(rowValues(metric.ratio.of), 'sum', path, directory);
|
|
28
61
|
const denominator = rollup(rowValues(metric.ratio.over), 'sum', path, directory);
|
|
29
62
|
value = denominator && numerator !== null ? numerator / denominator : null;
|
|
@@ -37,7 +70,7 @@ export function metricProjection(report) {
|
|
|
37
70
|
return result;
|
|
38
71
|
}
|
|
39
72
|
const privateMetrics = metadata.privateMetrics?.map(canonicalMetricId).filter(id => measured.has(id));
|
|
40
|
-
return { catalog: metrics, privateMetrics: privateMetrics?.length ? privateMetrics : undefined, values };
|
|
73
|
+
return { catalog: metrics, privateMetrics: privateMetrics?.length ? privateMetrics : undefined, values, isAvailable };
|
|
41
74
|
}
|
|
42
75
|
export function canonicalMetricDescriptor(metric) {
|
|
43
76
|
const id = canonicalMetricId(metric.id);
|
|
@@ -22,7 +22,7 @@ export interface InspectionDetails {
|
|
|
22
22
|
/** What the inspection read and how it scored it: a projection of the report's applied configuration. */
|
|
23
23
|
export interface ProfileSettings {
|
|
24
24
|
readonly id: string | null;
|
|
25
|
-
readonly
|
|
25
|
+
readonly languages?: readonly ProfileLanguage[];
|
|
26
26
|
readonly excludedPaths: readonly string[];
|
|
27
27
|
readonly excludedDirectories: readonly string[];
|
|
28
28
|
/** Every check the profile applies, each named with the plugin that runs it. */
|
|
@@ -60,6 +60,13 @@ export interface ProfileSettings {
|
|
|
60
60
|
readonly tools: Readonly<Record<string, string>>;
|
|
61
61
|
}[];
|
|
62
62
|
}
|
|
63
|
+
export interface ProfileLanguage {
|
|
64
|
+
readonly plugin: string;
|
|
65
|
+
readonly id: string;
|
|
66
|
+
readonly label: string;
|
|
67
|
+
readonly extensions: readonly string[];
|
|
68
|
+
readonly globs: readonly string[];
|
|
69
|
+
}
|
|
63
70
|
export interface ProfileRule {
|
|
64
71
|
readonly source: string;
|
|
65
72
|
readonly kind: 'check' | 'scanner';
|