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
|
@@ -2,39 +2,63 @@ import { isRecord } from './plugin-data.js';
|
|
|
2
2
|
import { canonicalMetricId, definitions } from './measurement.js';
|
|
3
3
|
export const debtModel = { name: 'basic-cocomo-organic', scale: 2.4, exponent: 1.05, minutesPerPersonMonth: 9600 };
|
|
4
4
|
export function qualitySummary(report) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
continue;
|
|
11
|
-
const id = canonicalMetricId(item.definition);
|
|
12
|
-
if (id === definitions.codeLines)
|
|
13
|
-
codeMeasuredFiles++;
|
|
14
|
-
if (id === definitions.duplicatedLines)
|
|
15
|
-
duplicationMeasuredFiles++;
|
|
16
|
-
totals.set(id, (totals.get(id) ?? 0) + item.value);
|
|
17
|
-
}
|
|
18
|
-
const codeLines = totals.get(definitions.codeLines) ?? null;
|
|
19
|
-
const duplicatedLines = totals.get(definitions.duplicatedLines) ?? null;
|
|
20
|
-
const smells = report.findings?.filter(finding => finding.category === 'duplication' || finding.category === 'structure');
|
|
21
|
-
const effortMinutes = smells?.reduce((sum, finding) => sum + (finding.effortMinutes ?? 0), 0) ?? 0;
|
|
22
|
-
const hasCompleteData = codeMeasuredFiles === report.scope.files && duplicationMeasuredFiles === report.scope.files;
|
|
23
|
-
const savedConfig = report.appliedConfig.maintainability;
|
|
24
|
-
const model = isRecord(savedConfig) ? readDebtModel(savedConfig.debtModel) : null;
|
|
25
|
-
const debtRatio = !hasCompleteData || codeLines === null || model === null || smells?.some(finding => finding.effortMinutes === undefined)
|
|
26
|
-
? null : technicalDebtRatio(effortMinutes, codeLines, model);
|
|
5
|
+
const files = collectFileMeasures(report);
|
|
6
|
+
const totalFiles = report.scope.files;
|
|
7
|
+
const completeTotal = (id) => totalMeasured(files.get(id), totalFiles);
|
|
8
|
+
const codeLines = completeTotal(definitions.codeLines);
|
|
9
|
+
const duplicatedLines = completeTotal(definitions.duplicatedLines);
|
|
27
10
|
return {
|
|
28
11
|
codeLines,
|
|
29
|
-
comments:
|
|
30
|
-
classes:
|
|
31
|
-
cognitiveComplexity:
|
|
32
|
-
duplication: duplicatedLines === null || codeLines === null
|
|
33
|
-
|
|
34
|
-
maintainability:
|
|
35
|
-
grade: debtRatio === null ? null : maintainabilityGrade(debtRatio) },
|
|
12
|
+
comments: completeTotal(definitions.comments),
|
|
13
|
+
classes: completeTotal(definitions.classes),
|
|
14
|
+
cognitiveComplexity: completeTotal(definitions.cognitiveComplexity),
|
|
15
|
+
duplication: duplicatedLines === null || codeLines === null ? null
|
|
16
|
+
: { duplicatedLines, codeLines, ratio: codeLines === 0 || duplicatedLines > codeLines ? null : duplicatedLines / codeLines },
|
|
17
|
+
maintainability: gradeMeasuredFiles(report, files.get(definitions.codeLines), files.get(definitions.duplicatedLines)),
|
|
36
18
|
};
|
|
37
19
|
}
|
|
20
|
+
function collectFileMeasures(report) {
|
|
21
|
+
const files = new Map();
|
|
22
|
+
for (const { target, path, definition, value } of report.measurements) {
|
|
23
|
+
if (target !== 'file' || path === undefined || value === null || !Number.isSafeInteger(value) || value < 0)
|
|
24
|
+
continue;
|
|
25
|
+
const id = canonicalMetricId(definition);
|
|
26
|
+
let measured = files.get(id);
|
|
27
|
+
if (!measured)
|
|
28
|
+
files.set(id, measured = new Map());
|
|
29
|
+
measured.set(path, (measured.get(path) ?? 0) + value);
|
|
30
|
+
}
|
|
31
|
+
return files;
|
|
32
|
+
}
|
|
33
|
+
function totalMeasured(values, expected) {
|
|
34
|
+
if (values?.size !== expected)
|
|
35
|
+
return null;
|
|
36
|
+
let total = 0;
|
|
37
|
+
for (const value of values.values())
|
|
38
|
+
total += value;
|
|
39
|
+
return total;
|
|
40
|
+
}
|
|
41
|
+
function gradeMeasuredFiles(report, code, duplication) {
|
|
42
|
+
if (report.findings === undefined || code === undefined)
|
|
43
|
+
return null;
|
|
44
|
+
const skipped = new Set(report.ruleSkips?.filter(({ plugin }) => plugin === 'maintainability' || plugin === 'duplication')
|
|
45
|
+
.map(({ path }) => path));
|
|
46
|
+
const measured = new Map([...code].filter(([path]) => duplication?.has(path) && !skipped.has(path)));
|
|
47
|
+
const smells = report.findings.filter(finding => finding.category === 'duplication' || finding.category === 'structure');
|
|
48
|
+
const totalFiles = report.scope.files;
|
|
49
|
+
const complete = measured.size === totalFiles;
|
|
50
|
+
const eligible = complete ? smells : smells.filter(({ path }) => path !== undefined && measured.has(path));
|
|
51
|
+
const effortMinutes = eligible.reduce((sum, finding) => sum + (finding.effortMinutes ?? 0), 0);
|
|
52
|
+
const config = report.appliedConfig.maintainability;
|
|
53
|
+
const model = isRecord(config) ? readDebtModel(config.debtModel) : null;
|
|
54
|
+
const sized = totalMeasured(measured, measured.size);
|
|
55
|
+
const canGrade = complete || (report.scope.parsed === totalFiles
|
|
56
|
+
&& measured.size + skipped.size === totalFiles);
|
|
57
|
+
const debtRatio = !canGrade || !sized || model === null || eligible.some(finding => finding.effortMinutes === undefined)
|
|
58
|
+
? null : technicalDebtRatio(effortMinutes, sized, model);
|
|
59
|
+
return { smells: smells.length, effortMinutes, debtRatio, grade: debtRatio === null ? null : maintainabilityGrade(debtRatio),
|
|
60
|
+
...(!complete && debtRatio !== null ? { gradeCoverage: { measuredFiles: measured.size, totalFiles } } : {}) };
|
|
61
|
+
}
|
|
38
62
|
export function technicalDebtRatio(effortMinutes, codeLines, model = debtModel) {
|
|
39
63
|
if (codeLines <= 0)
|
|
40
64
|
return null;
|
|
@@ -33,7 +33,15 @@ export interface Report {
|
|
|
33
33
|
readonly measurements: readonly Measurement[];
|
|
34
34
|
readonly diagnostics: readonly Diagnostic[];
|
|
35
35
|
readonly findings?: readonly Finding[];
|
|
36
|
+
readonly ruleSkips?: readonly {
|
|
37
|
+
readonly path: string;
|
|
38
|
+
readonly plugin: string;
|
|
39
|
+
readonly rules: readonly string[];
|
|
40
|
+
readonly reason: 'unmeasured';
|
|
41
|
+
}[];
|
|
36
42
|
readonly ignoredFindings?: readonly IgnoredFinding[];
|
|
37
43
|
readonly pluginData?: PluginData;
|
|
38
44
|
}
|
|
39
45
|
export declare function validSubjectId(kind: Subject['kind'], id: string): boolean;
|
|
46
|
+
export declare const legacySyntaxPlugin = "babel-syntax";
|
|
47
|
+
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';
|
|
@@ -3,7 +3,7 @@ export type { DataContract, InspectionInputs, Operation, Plugin, PluginConfigSch
|
|
|
3
3
|
export type { FileClaims, MetricDescriptor, MetricScope, PluginKind, ProductDeclaration } from './core/engine/plugin.js';
|
|
4
4
|
export type { OperationCache, OperationCacheOptions } from './core/engine/operation-cache.js';
|
|
5
5
|
export { codeStructure, codeStructures } from './core/model/code-structure.js';
|
|
6
|
-
export type { CodeStructure, FunctionComplexity, StructuralCheck, StructuralObservation } from './core/model/code-structure.js';
|
|
6
|
+
export type { CodeStructure, FunctionComplexity, StructureMeasure, StructuralCheck, StructuralObservation } from './core/model/code-structure.js';
|
|
7
7
|
export type { LanguageDisplay, ProvidedLanguage } from './core/model/language.js';
|
|
8
8
|
export type { Candidate, CloneSource } from './core/model/clone-source.js';
|
|
9
9
|
export { sourceFile, sourceFiles } from './core/model/snapshot.js';
|
|
@@ -7,6 +7,7 @@ export interface CoverageInput {
|
|
|
7
7
|
readonly root: string;
|
|
8
8
|
readonly sourceLines: ReadonlyMap<string, number>;
|
|
9
9
|
readonly codeLines?: ReadonlyMap<string, ReadonlySet<number>>;
|
|
10
|
+
readonly unclassified?: ReadonlySet<string>;
|
|
10
11
|
readonly functionBodies?: ReadonlyMap<string, readonly SourceLineRange[]>;
|
|
11
12
|
readonly excludes?: (path: string) => boolean;
|
|
12
13
|
}
|
|
@@ -21,7 +22,7 @@ interface CoverageResult {
|
|
|
21
22
|
export declare const lcovInput: DataContract<CoverageInput>;
|
|
22
23
|
export declare const coverageResult: DataContract<CoverageResult>;
|
|
23
24
|
export declare const coverage: Plugin;
|
|
24
|
-
export declare function mapCoverage({ text, root, sourceLines, codeLines, excludes }: CoverageInput): {
|
|
25
|
+
export declare function mapCoverage({ text, root, sourceLines, codeLines, unclassified, excludes }: CoverageInput): {
|
|
25
26
|
files: Map<string, Map<number, number>>;
|
|
26
27
|
branches: Map<string, Map<string, number>>;
|
|
27
28
|
functions: Map<string, Map<string, number>>;
|
|
@@ -9,6 +9,7 @@ export const lcovInput = {
|
|
|
9
9
|
accepts: (value) => isRecord(value) && typeof value.text === 'string'
|
|
10
10
|
&& typeof value.root === 'string' && value.sourceLines instanceof Map
|
|
11
11
|
&& (value.codeLines === undefined || value.codeLines instanceof Map)
|
|
12
|
+
&& (value.unclassified === undefined || value.unclassified instanceof Set)
|
|
12
13
|
&& (value.functionBodies === undefined || value.functionBodies instanceof Map)
|
|
13
14
|
&& (value.excludes === undefined || typeof value.excludes === 'function'),
|
|
14
15
|
};
|
|
@@ -18,25 +19,27 @@ export const coverageResult = {
|
|
|
18
19
|
&& Array.isArray(value.gaps) && value.gaps.every(gap => isRecord(gap) && typeof gap.path === 'string' && typeof gap.reason === 'string')
|
|
19
20
|
&& lcovLines.accepts(value.lineCoverage),
|
|
20
21
|
};
|
|
22
|
+
const kinds = [
|
|
23
|
+
{ ids: [definitions.coverage, definitions.coveredLines, definitions.coverableLines],
|
|
24
|
+
labels: ['Line coverage', 'Covered lines', 'Measured lines'], includeEmpty: true },
|
|
25
|
+
{ ids: [definitions.branchCoverage, definitions.coveredBranches, definitions.coverableBranches],
|
|
26
|
+
labels: ['Branch coverage', 'Covered branches', 'Measured branches'] },
|
|
27
|
+
{ ids: [definitions.functionCoverage, definitions.coveredFunctions, definitions.coverableFunctions],
|
|
28
|
+
labels: ['Function coverage', 'Covered functions', 'Measured functions'] },
|
|
29
|
+
];
|
|
30
|
+
const [lineMetrics, branchMetrics, functionMetrics] = kinds;
|
|
21
31
|
export const coverage = {
|
|
22
32
|
id: 'lcov',
|
|
23
33
|
version: '1.2.0',
|
|
24
34
|
api: pluginApi,
|
|
25
35
|
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',
|
|
36
|
+
produces: [{ contract: coverageResult.id, persistence: 'report',
|
|
37
|
+
metrics: kinds.flatMap(({ ids: [id, of, over], labels }) => [
|
|
38
|
+
{ id, label: labels[0], unit: 'ratio', scope: 'file', aggregate: 'sum', better: 'higher',
|
|
39
|
+
ratio: { of, over }, bands: [0.6, 0.7, 0.8, 0.9], group: 'Coverage' },
|
|
40
|
+
{ id: of, label: labels[1], unit: 'count', scope: 'file', aggregate: 'sum', better: 'higher', group: 'Coverage' },
|
|
41
|
+
{ id: over, label: labels[2], unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Coverage' },
|
|
42
|
+
]) }, { contract: lcovLines.id, persistence: 'report',
|
|
40
43
|
schema: { ...reportSchema.$defs.lcovLines,
|
|
41
44
|
$defs: { lcovLineRanges: reportSchema.$defs.lcovLineRanges, lcovHitRuns: reportSchema.$defs.lcovHitRuns,
|
|
42
45
|
lcovFunctionCalls: reportSchema.$defs.lcovFunctionCalls } } }],
|
|
@@ -54,12 +57,12 @@ export const coverage = {
|
|
|
54
57
|
execute: inputs => inputs.read('coverage', coverageResult).lineCoverage,
|
|
55
58
|
}],
|
|
56
59
|
};
|
|
57
|
-
export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
|
|
60
|
+
export function mapCoverage({ text, root, sourceLines, codeLines, unclassified, excludes }) {
|
|
58
61
|
const files = new Map();
|
|
59
62
|
// Branches by line, block and branch. Functions by name and its occurrence in the record: tools such as c8 repeat a
|
|
60
63
|
// name for different functions and list FNDA in FN order.
|
|
61
64
|
const branches = new Map();
|
|
62
|
-
const
|
|
65
|
+
const functions = new Map();
|
|
63
66
|
const called = new Map();
|
|
64
67
|
const occurrences = { declared: new Map(), called: new Map() };
|
|
65
68
|
const occurrence = (seen, name) => {
|
|
@@ -71,8 +74,7 @@ export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
|
|
|
71
74
|
let active;
|
|
72
75
|
let ignored = false;
|
|
73
76
|
let sawSource = false;
|
|
74
|
-
const
|
|
75
|
-
for (const [index, line] of lines.entries()) {
|
|
77
|
+
for (const [index, line] of text.split(/\r?\n/).entries()) {
|
|
76
78
|
if (line.startsWith('SF:')) {
|
|
77
79
|
if (active !== undefined || line.length === 3)
|
|
78
80
|
throw new Error(`Unexpected LCOV source at line ${index + 1}`);
|
|
@@ -85,62 +87,24 @@ export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
|
|
|
85
87
|
continue;
|
|
86
88
|
if (!sourceLines.has(active))
|
|
87
89
|
gaps.set(active, 'LCOV source is outside the inspected file set');
|
|
88
|
-
else if (codeLines && !codeLines.has(active))
|
|
90
|
+
else if (codeLines && !codeLines.has(active) && !unclassified?.has(active)) {
|
|
89
91
|
gaps.set(active, 'LCOV source has no classified code lines');
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
}
|
|
93
|
+
else
|
|
94
|
+
fileRecords(files, active);
|
|
92
95
|
}
|
|
93
96
|
else if (line.startsWith('DA:')) {
|
|
94
97
|
if (active === undefined)
|
|
95
98
|
throw new Error(`LCOV line data outside a source record at line ${index + 1}`);
|
|
96
|
-
if (ignored)
|
|
97
|
-
|
|
98
|
-
const match = /^DA:([1-9]\d*),(\d+)(?:,[^,]+)?$/.exec(line);
|
|
99
|
-
const number = Number(match?.[1]);
|
|
100
|
-
const hits = Number(match?.[2]);
|
|
101
|
-
if (!Number.isSafeInteger(number) || !Number.isSafeInteger(hits))
|
|
102
|
-
throw new Error(`Invalid LCOV line data at line ${index + 1}`);
|
|
103
|
-
const file = files.get(active);
|
|
104
|
-
const limit = sourceLines.get(active);
|
|
105
|
-
if (limit !== undefined && number > limit)
|
|
106
|
-
gaps.set(active, 'LCOV refers to a line outside the inspected source');
|
|
107
|
-
else if (file && (!codeLines || codeLines.get(active)?.has(number)))
|
|
108
|
-
addHits(file, number, hits, index + 1);
|
|
99
|
+
if (!ignored)
|
|
100
|
+
readLine(active, line, index + 1);
|
|
109
101
|
}
|
|
110
|
-
else if (
|
|
102
|
+
else if (/^(?:BRDA|FN|FNDA):/.test(line)) {
|
|
111
103
|
if (active === undefined)
|
|
112
104
|
throw new Error(`LCOV data outside a source record at line ${index + 1}`);
|
|
113
105
|
if (ignored || !files.has(active))
|
|
114
106
|
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
|
-
}
|
|
107
|
+
readDetails(active, line, index + 1);
|
|
144
108
|
}
|
|
145
109
|
else if (line === 'end_of_record') {
|
|
146
110
|
if (active === undefined)
|
|
@@ -152,21 +116,68 @@ export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
|
|
|
152
116
|
throw new Error('Unterminated LCOV source record');
|
|
153
117
|
if (!sawSource && text.trim() !== '')
|
|
154
118
|
throw new Error('LCOV contains no source records');
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
119
|
+
return { files, branches, functions, functionCalls: countFunctionCalls(), gaps };
|
|
120
|
+
function countFunctionCalls() {
|
|
121
|
+
// The declaration map can now hold hit totals. Keep the declared lines for the gutter.
|
|
122
|
+
const functionCalls = new Map();
|
|
123
|
+
for (const [path, declarations] of functions) {
|
|
124
|
+
const hits = called.get(path);
|
|
125
|
+
const counts = [];
|
|
126
|
+
for (const [key, first] of declarations) {
|
|
127
|
+
const count = hits?.get(key);
|
|
128
|
+
declarations.set(key, count ?? 0);
|
|
129
|
+
if (count !== undefined && first <= sourceLines.get(path))
|
|
130
|
+
counts.push([first, count]);
|
|
131
|
+
}
|
|
132
|
+
if (counts.length)
|
|
133
|
+
functionCalls.set(path, counts.sort(([left], [right]) => left - right));
|
|
134
|
+
}
|
|
135
|
+
return functionCalls;
|
|
136
|
+
}
|
|
137
|
+
function readLine(path, line, record) {
|
|
138
|
+
const match = /^DA:([1-9]\d*),(\d+)(?:,[^,]+)?$/.exec(line);
|
|
139
|
+
const number = Number(match?.[1]);
|
|
140
|
+
const hits = Number(match?.[2]);
|
|
141
|
+
if (!Number.isSafeInteger(number) || !Number.isSafeInteger(hits))
|
|
142
|
+
throw new Error(`Invalid LCOV line data at line ${record}`);
|
|
143
|
+
const file = files.get(path);
|
|
144
|
+
const limit = sourceLines.get(path);
|
|
145
|
+
const classified = codeLines?.get(path);
|
|
146
|
+
if (limit !== undefined && number > limit)
|
|
147
|
+
gaps.set(path, 'LCOV refers to a line outside the inspected source');
|
|
148
|
+
else if (file && (!classified || classified.has(number)))
|
|
149
|
+
addHits(file, number, hits, record);
|
|
150
|
+
}
|
|
151
|
+
function readDetails(path, line, record) {
|
|
152
|
+
const branch = /^BRDA:([1-9]\d*),([^,]+),([^,]+),(\d+|-)$/.exec(line);
|
|
153
|
+
if (branch) {
|
|
154
|
+
addHits(fileRecords(branches, path), `${branch[1]},${branch[2]},${branch[3]}`, branch[4] === '-' ? 0 : Number(branch[4]), record);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const declaration = /^FN:([1-9]\d*)(?:,[1-9]\d*)?,(.+)$/.exec(line);
|
|
158
|
+
if (declaration) {
|
|
159
|
+
const number = Number(declaration[1]);
|
|
160
|
+
if (!Number.isSafeInteger(number))
|
|
161
|
+
throw new Error(`Invalid LCOV function line at line ${record}`);
|
|
162
|
+
const records = fileRecords(functions, path);
|
|
163
|
+
const key = occurrence(occurrences.declared, declaration[2]);
|
|
164
|
+
if (!records.has(key))
|
|
165
|
+
records.set(key, number);
|
|
166
|
+
return;
|
|
165
167
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
const call = /^FNDA:(\d+),(.+)$/.exec(line);
|
|
169
|
+
if (!call)
|
|
170
|
+
throw new Error(`Invalid LCOV data at line ${record}`);
|
|
171
|
+
addHits(fileRecords(called, path), occurrence(occurrences.called, call[2]), Number(call[1]), record);
|
|
168
172
|
}
|
|
169
|
-
|
|
173
|
+
}
|
|
174
|
+
function fileRecords(files, path) {
|
|
175
|
+
const existing = files.get(path);
|
|
176
|
+
if (existing)
|
|
177
|
+
return existing;
|
|
178
|
+
const records = new Map();
|
|
179
|
+
files.set(path, records);
|
|
180
|
+
return records;
|
|
170
181
|
}
|
|
171
182
|
function addHits(hits, key, count, record) {
|
|
172
183
|
const total = (hits.get(key) ?? 0) + count;
|
|
@@ -176,17 +187,14 @@ function addHits(hits, key, count, record) {
|
|
|
176
187
|
}
|
|
177
188
|
function importCoverage(input) {
|
|
178
189
|
const { files, branches, functions, functionCalls, gaps } = mapCoverage(input);
|
|
179
|
-
const rows = [];
|
|
180
190
|
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;
|
|
191
|
+
const lines = hitRows(files, gaps, lineMetrics, (path, hits) => {
|
|
186
192
|
const hitLines = [], missedLines = [];
|
|
187
193
|
for (const [line, hit] of hits)
|
|
188
194
|
(hit ? hitLines : missedLines).push(line);
|
|
189
|
-
const
|
|
195
|
+
const lastLine = input.sourceLines.get(path);
|
|
196
|
+
const classified = input.codeLines?.get(path);
|
|
197
|
+
const partialHits = partiallyCoveredLines(branches.get(path), lastLine, classified);
|
|
190
198
|
const partial = mergedRanges([...partialHits.keys()]);
|
|
191
199
|
const calls = functionCalls.get(path);
|
|
192
200
|
const bodies = input.functionBodies?.get(path);
|
|
@@ -197,21 +205,10 @@ function importCoverage(input) {
|
|
|
197
205
|
...(partial.length ? { partial } : {}), hits: mergedHits(measured),
|
|
198
206
|
...(calls === undefined ? {} : { functionCalls: calls }), ...(bodies === undefined ? {} : { functionBodies: bodies }) }]);
|
|
199
207
|
}
|
|
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),
|
|
208
|
+
return hitLines.length;
|
|
209
|
+
});
|
|
210
|
+
const metrics = [...lines, ...hitRows(branches, gaps, branchMetrics), ...hitRows(functions, gaps, functionMetrics)];
|
|
211
|
+
return { measurements: metrics, lineCoverage: Object.fromEntries(lineCoverage),
|
|
215
212
|
gaps: [...gaps].sort(([left], [right]) => comparePaths(left, right)).map(([path, reason]) => ({ path, reason })) };
|
|
216
213
|
}
|
|
217
214
|
function partiallyCoveredLines(branches, lastLine, codeLines) {
|
|
@@ -251,22 +248,25 @@ function mergedHits(hits) {
|
|
|
251
248
|
return runs;
|
|
252
249
|
}
|
|
253
250
|
/** 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) {
|
|
251
|
+
function hitRows(files, gaps, { ids: [ratioId, coveredId, totalId], includeEmpty = false }, coveredCount) {
|
|
255
252
|
const rows = [];
|
|
256
253
|
let totalCovered = 0;
|
|
257
254
|
let totalCount = 0;
|
|
258
255
|
for (const [path, hits] of [...files].sort(([left], [right]) => comparePaths(left, right))) {
|
|
259
|
-
if (gaps.has(path) || hits.size
|
|
256
|
+
if (gaps.has(path) || (!hits.size && !includeEmpty))
|
|
260
257
|
continue;
|
|
261
258
|
let covered = 0;
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
259
|
+
if (coveredCount)
|
|
260
|
+
covered = coveredCount(path, hits);
|
|
261
|
+
else
|
|
262
|
+
for (const hit of hits.values())
|
|
263
|
+
if (hit)
|
|
264
|
+
covered++;
|
|
265
265
|
totalCovered += covered;
|
|
266
266
|
totalCount += hits.size;
|
|
267
267
|
rows.push({ definition: ratioId, target: 'file', path, covered, total: hits.size, value: ratio(covered, hits.size) });
|
|
268
268
|
}
|
|
269
|
-
if (totalCount === 0)
|
|
269
|
+
if (totalCount === 0 && !includeEmpty)
|
|
270
270
|
return [];
|
|
271
271
|
rows.push({ definition: ratioId, target: 'repository', covered: totalCovered, total: totalCount, value: ratio(totalCovered, totalCount) });
|
|
272
272
|
return [...rows, ...rows.flatMap(({ target, path, covered, total }) => [
|
|
@@ -282,8 +282,6 @@ function normalizeLcovPath(root, path) {
|
|
|
282
282
|
const candidate = platform.isAbsolute(path) ? platform.relative(root, path) : path;
|
|
283
283
|
if (platform.isAbsolute(candidate))
|
|
284
284
|
return candidate;
|
|
285
|
-
|
|
286
|
-
return posix.normalize(candidate.replaceAll('\\', '/'));
|
|
287
|
-
return posix.normalize(candidate);
|
|
285
|
+
return posix.normalize(platform === win32 ? candidate.replaceAll('\\', '/') : candidate);
|
|
288
286
|
}
|
|
289
287
|
//# 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',
|
|
@@ -6,4 +6,4 @@ export declare function functionFacts(ast: Node): {
|
|
|
6
6
|
functionBodies: [number, number][];
|
|
7
7
|
};
|
|
8
8
|
export declare function children(node: Node): Iterable<Node>;
|
|
9
|
-
export declare function functionName(node: BabelFunction): string;
|
|
9
|
+
export declare function functionName(node: BabelFunction): string | undefined;
|