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
|
@@ -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);
|
|
@@ -2,13 +2,14 @@ import { createRequire } from 'node:module';
|
|
|
2
2
|
import { extname } from 'node:path';
|
|
3
3
|
import { parse } from '@babel/parser';
|
|
4
4
|
import { pluginApi } from '../../core/engine/plugin.js';
|
|
5
|
+
import { javascriptType, typescriptType } from '../../core/model/file-types.js';
|
|
5
6
|
import { codeStructure } from '../../core/model/code-structure.js';
|
|
6
7
|
import { physicalLines, sourceFile, utf8 } from '../../core/model/snapshot.js';
|
|
7
8
|
import { cloneCandidates } from './clone-candidates.js';
|
|
8
9
|
import { classifyLines } from './code-lines.js';
|
|
9
10
|
import { functionFacts } from './function-facts.js';
|
|
10
11
|
import { structuralObservations } from './structural-observations.js';
|
|
11
|
-
import {
|
|
12
|
+
import { jsTsExtensions } from './extensions.js';
|
|
12
13
|
const require = createRequire(import.meta.url);
|
|
13
14
|
export const parserDefaults = { sourceType: 'unambiguous', errorRecovery: false, attachComment: false };
|
|
14
15
|
export const babelTypes = { '@babel/types': require('@babel/types/package.json').version };
|
|
@@ -18,13 +19,10 @@ export const babelProvider = {
|
|
|
18
19
|
api: pluginApi,
|
|
19
20
|
kinds: ['language'],
|
|
20
21
|
claims: { extensions: jsTsExtensions, languages: ['javascript', 'typescript'] },
|
|
21
|
-
providesLanguages: [
|
|
22
|
-
{ id: 'javascript', label: 'JavaScript', color: '#f1e05a', extensions: javaScriptExtensions },
|
|
23
|
-
{ id: 'typescript', label: 'TypeScript', color: '#3178c6', extensions: typeScriptExtensions },
|
|
24
|
-
],
|
|
22
|
+
providesLanguages: [javascriptType, typescriptType],
|
|
25
23
|
settings: parserDefaults,
|
|
26
24
|
produces: [{ contract: codeStructure.id, persistence: 'transient' }],
|
|
27
|
-
tools: { '@babel/parser': require('@babel/parser/package.json').version },
|
|
25
|
+
tools: { '@babel/parser': require('@babel/parser/package.json').version, ...babelTypes },
|
|
28
26
|
operations: [{
|
|
29
27
|
id: 'parse',
|
|
30
28
|
role: 'provider',
|
|
@@ -35,7 +33,7 @@ export const babelProvider = {
|
|
|
35
33
|
const source = utf8(file.bytes);
|
|
36
34
|
const ext = extname(file.path);
|
|
37
35
|
const plugins = [];
|
|
38
|
-
if (
|
|
36
|
+
if (typescriptType.extensions.includes(ext)) {
|
|
39
37
|
plugins.push(['typescript', { dts: /\.d\.[cm]?ts$/.test(file.path), disallowAmbiguousJSXLike: ext === '.mts' || ext === '.cts' }]);
|
|
40
38
|
}
|
|
41
39
|
if (ext === '.jsx' || ext === '.tsx')
|
|
@@ -1,3 +1 @@
|
|
|
1
|
-
export declare const javaScriptExtensions: readonly ['.js', '.mjs', '.cjs', '.jsx'];
|
|
2
|
-
export declare const typeScriptExtensions: readonly ['.ts', '.mts', '.cts', '.tsx'];
|
|
3
1
|
export declare const jsTsExtensions: readonly [".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".tsx"];
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export const
|
|
3
|
-
export const jsTsExtensions = [...javaScriptExtensions, ...typeScriptExtensions];
|
|
1
|
+
import { javascriptType, typescriptType } from '../../core/model/file-types.js';
|
|
2
|
+
export const jsTsExtensions = [...javascriptType.extensions, ...typescriptType.extensions];
|
|
4
3
|
//# sourceMappingURL=extensions.js.map
|
|
@@ -33,7 +33,7 @@ function sourceName(path) {
|
|
|
33
33
|
return named;
|
|
34
34
|
}
|
|
35
35
|
function sourceMeta(file) {
|
|
36
|
-
const language = languageOf(file
|
|
36
|
+
const language = languageOf(file);
|
|
37
37
|
const dot = element('span', 'fx-language-dot');
|
|
38
38
|
dot.style.background = languageColor(language);
|
|
39
39
|
const meta = element('span', 'fx-source-meta');
|
|
@@ -149,7 +149,7 @@ function anyOf(clauses, kind, test) {
|
|
|
149
149
|
*/
|
|
150
150
|
export function matches(entry, clauses, facts, text = '') {
|
|
151
151
|
const path = entry.path.toLowerCase();
|
|
152
|
-
const language = languageOf(entry
|
|
152
|
+
const language = languageOf(entry).toLowerCase();
|
|
153
153
|
const components = (facts.components.get(entry.path) ?? []).map(name => name.toLowerCase());
|
|
154
154
|
const widened = [
|
|
155
155
|
path.includes(text.toLowerCase()),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { usePluginMeasures } from './viewer-filter.js';
|
|
2
|
+
import { useLanguages } from './viewer-languages.js';
|
|
2
3
|
import { catalogIndex, entryValue } from './viewer-metric-registry.js';
|
|
3
4
|
import { extendCatalog, pluginMetrics } from './viewer-metrics.js';
|
|
4
5
|
/** How many rows a page of any list holds. */
|
|
@@ -8,6 +9,7 @@ let local = { catalog: undefined, index: new Map() };
|
|
|
8
9
|
export function useDetails(details) {
|
|
9
10
|
const catalog = details.metrics.catalog;
|
|
10
11
|
extendCatalog(catalog);
|
|
12
|
+
useLanguages(details.metrics.languages);
|
|
11
13
|
local = { catalog, index: catalogIndex(catalog) };
|
|
12
14
|
usePluginMeasures(pluginMetrics().filter(spec => spec.descriptor.scope === 'file' && measured(spec.descriptor)).map(spec => [spec.key, {
|
|
13
15
|
label: spec.label, percent: spec.descriptor.unit === 'ratio', minutes: spec.descriptor.unit === 'minutes',
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { FileMetricsReport } from '../../json/wire/file-metrics-model.js';
|
|
2
2
|
type FileEntry = FileMetricsReport['files'][number];
|
|
3
|
+
type Language = NonNullable<FileMetricsReport['languages']>[number];
|
|
4
|
+
/** Takes the languages of the inspection on screen: their names, and the colours the plugins and the catalog give them. */
|
|
5
|
+
export declare function useLanguages(list: readonly Language[] | undefined): void;
|
|
3
6
|
/**
|
|
4
7
|
* Dependency lockfiles, by exact file name. They are generated, often the largest files in a repository, and no
|
|
5
8
|
* plugin reads them: the language bar and the Metrics list give them a category of their own beside the ignored files.
|
|
@@ -16,12 +19,14 @@ export declare const ignoredLabel = "Ignored";
|
|
|
16
19
|
export type ShareMeasure = 'bytes' | 'lines' | 'code-lines';
|
|
17
20
|
/** Whether every file carries its size: inspections made before sizes were recorded carry none. */
|
|
18
21
|
export declare function sized(files: readonly Pick<FileEntry, 'bytes'>[]): boolean;
|
|
19
|
-
type Weighed = Pick<FileEntry, 'path' | 'analysed' | 'lines' | 'quality' | 'bytes'>;
|
|
22
|
+
type Weighed = Pick<FileEntry, 'path' | 'analysed' | 'lines' | 'quality' | 'bytes' | 'language'>;
|
|
20
23
|
/** What the language bar weighs, largest language first, then lockfiles, then the ignored files. */
|
|
21
24
|
export declare function languageShares(files: readonly Weighed[]): {
|
|
22
25
|
readonly measure: ShareMeasure;
|
|
23
26
|
readonly shares: readonly (readonly [string, number])[];
|
|
24
27
|
};
|
|
25
|
-
|
|
28
|
+
/** A file's language by the inspection's name for it; a file it names none for is Other. */
|
|
29
|
+
export declare function languageOf(entry: Pick<FileEntry, 'language'>): string;
|
|
30
|
+
/** A language's colour, as the inspection gives it; a neutral grey for one it gives none. */
|
|
26
31
|
export declare function languageColor(language: string): string;
|
|
27
32
|
export {};
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/** The inspection's languages, which its files point to by index, and the colour of each by its name. */
|
|
2
|
+
let languages = [];
|
|
3
|
+
let colors = new Map();
|
|
4
|
+
function nameOf(language) {
|
|
5
|
+
return language.label ?? language.id;
|
|
6
|
+
}
|
|
7
|
+
/** Takes the languages of the inspection on screen: their names, and the colours the plugins and the catalog give them. */
|
|
8
|
+
export function useLanguages(list) {
|
|
9
|
+
languages = list ?? [];
|
|
10
|
+
colors = new Map(languages.flatMap(language => language.color ? [[nameOf(language), language.color]] : []));
|
|
11
|
+
}
|
|
1
12
|
/**
|
|
2
13
|
* Dependency lockfiles, by exact file name. They are generated, often the largest files in a repository, and no
|
|
3
14
|
* plugin reads them: the language bar and the Metrics list give them a category of their own beside the ignored files.
|
|
@@ -41,7 +52,7 @@ function shareMeasure(files) {
|
|
|
41
52
|
function shareOf(entry) {
|
|
42
53
|
if (isLockfile(entry.path))
|
|
43
54
|
return lockfilesLabel;
|
|
44
|
-
return entry.analysed === false ? ignoredLabel : languageOf(entry
|
|
55
|
+
return entry.analysed === false ? ignoredLabel : languageOf(entry);
|
|
45
56
|
}
|
|
46
57
|
/** What the language bar weighs, largest language first, then lockfiles, then the ignored files. */
|
|
47
58
|
export function languageShares(files) {
|
|
@@ -58,36 +69,12 @@ export function languageShares(files) {
|
|
|
58
69
|
}
|
|
59
70
|
return { measure, shares };
|
|
60
71
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
c: 'C', h: 'C', cc: 'C++', cpp: 'C++', cxx: 'C++', hpp: 'C++', hh: 'C++', swift: 'Swift', scala: 'Scala',
|
|
66
|
-
vue: 'Vue', svelte: 'Svelte', sh: 'Shell', bash: 'Shell', css: 'CSS', scss: 'SCSS', less: 'Less', html: 'HTML',
|
|
67
|
-
yaml: 'YAML', yml: 'YAML', json: 'JSON', dockerfile: 'Dockerfile',
|
|
68
|
-
};
|
|
69
|
-
/** Files a name alone types: Dockerfile and Containerfile, with or without a suffix such as Dockerfile.dev. */
|
|
70
|
-
const namedLanguages = [[/^(?:dockerfile|containerfile)(?:\..+)?$/i, 'Dockerfile']];
|
|
71
|
-
/** Language colours follow the conventions people already know from code hosts. */
|
|
72
|
-
const languageColors = {
|
|
73
|
-
TypeScript: '#3178c6', JavaScript: '#f1e05a', Python: '#3572a5', Go: '#00add8', Rust: '#dea584', Java: '#b07219',
|
|
74
|
-
Kotlin: '#a97bff', Ruby: '#701516', PHP: '#4f5d95', 'C#': '#178600', C: '#555555', 'C++': '#f34b7d', Swift: '#f05138',
|
|
75
|
-
Scala: '#c22d40', Vue: '#41b883', Svelte: '#ff3e00', Shell: '#89e051', CSS: '#663399', SCSS: '#c6538c', Less: '#1d365d',
|
|
76
|
-
HTML: '#e34c26',
|
|
77
|
-
// Configuration reads beside the code, so it takes quieter tones than the code hosts give it.
|
|
78
|
-
YAML: '#c47d84', JSON: '#9b86b5', Dockerfile: '#4f9a94',
|
|
79
|
-
};
|
|
80
|
-
export function languageOf(path) {
|
|
81
|
-
const name = path.slice(path.lastIndexOf('/') + 1);
|
|
82
|
-
const named = namedLanguages.find(([pattern]) => pattern.test(name));
|
|
83
|
-
if (named)
|
|
84
|
-
return named[1];
|
|
85
|
-
const dot = name.lastIndexOf('.');
|
|
86
|
-
const extension = dot > 0 ? name.slice(dot + 1).toLowerCase() : '';
|
|
87
|
-
if (!extension)
|
|
88
|
-
return 'Other';
|
|
89
|
-
return languages[extension] ?? extension.toUpperCase();
|
|
72
|
+
/** A file's language by the inspection's name for it; a file it names none for is Other. */
|
|
73
|
+
export function languageOf(entry) {
|
|
74
|
+
const language = entry.language === undefined ? undefined : languages[entry.language];
|
|
75
|
+
return language ? nameOf(language) : 'Other';
|
|
90
76
|
}
|
|
77
|
+
/** A language's colour, as the inspection gives it; a neutral grey for one it gives none. */
|
|
91
78
|
export function languageColor(language) {
|
|
92
|
-
return
|
|
79
|
+
return colors.get(language) ?? 'var(--neutral-2)';
|
|
93
80
|
}
|
|
@@ -25,7 +25,7 @@ function tallied(names) {
|
|
|
25
25
|
return counts;
|
|
26
26
|
}
|
|
27
27
|
function languageSuggestions(files, typing) {
|
|
28
|
-
const counts = [...tallied(files.map(file => languageOf(file
|
|
28
|
+
const counts = [...tallied(files.map(file => languageOf(file)))].sort((a, b) => b[1] - a[1]);
|
|
29
29
|
return counts.flatMap(([language, total]) => {
|
|
30
30
|
const clause = { kind: 'lang', value: language };
|
|
31
31
|
if (typing.taken(clause) || !offered(typing, language, 'lang'))
|
|
@@ -35,7 +35,7 @@ function entryIcon(row) {
|
|
|
35
35
|
const icon = element('span', icons[row.kind]);
|
|
36
36
|
icon.setAttribute('aria-hidden', 'true');
|
|
37
37
|
if (row.kind === 'file')
|
|
38
|
-
icon.style.color = isLockfile(row.entry.path) ? 'var(--lockfile)' : languageColor(languageOf(row.entry
|
|
38
|
+
icon.style.color = isLockfile(row.entry.path) ? 'var(--lockfile)' : languageColor(languageOf(row.entry));
|
|
39
39
|
return icon;
|
|
40
40
|
}
|
|
41
41
|
function cell(entry, column) {
|
|
@@ -2,10 +2,9 @@ import type { ReadCommitMetadata } from '../../json/projections/commit-summary.j
|
|
|
2
2
|
import type { CommitSummary, SourceLocator } from '../../json/wire/summary-model.js';
|
|
3
3
|
import type { Report, ReportReader } from '../../json/validation/report.js';
|
|
4
4
|
import type { PullReview } from '../../json/wire/pull-review-model.js';
|
|
5
|
-
import type {
|
|
6
|
-
export interface SiteOptions {
|
|
5
|
+
import type { InspectionOptions } from '../../json/projections/inspection-details.js';
|
|
6
|
+
export interface SiteOptions extends InspectionOptions {
|
|
7
7
|
readonly title?: string;
|
|
8
|
-
readonly components?: readonly Component[];
|
|
9
8
|
readonly pulls?: readonly PullReview[];
|
|
10
9
|
readonly sources?: SourceLocator;
|
|
11
10
|
readonly branch?: string;
|
|
@@ -57,7 +57,7 @@ export async function siteFiles(reports, options = {}) {
|
|
|
57
57
|
const details = new Map();
|
|
58
58
|
for (const report of commits) {
|
|
59
59
|
const sha = report.subject.id;
|
|
60
|
-
const data = JSON.stringify(packJson(inspectionAsset(report, options
|
|
60
|
+
const data = JSON.stringify(packJson(inspectionAsset(report, options))) + '\n';
|
|
61
61
|
const name = `details/${sha}-${digest(data)}.json`;
|
|
62
62
|
details.set(sha, name);
|
|
63
63
|
files.set(name, Buffer.from(data));
|
|
@@ -41,7 +41,7 @@ export async function serveSite(reader, port, options = {}, source) {
|
|
|
41
41
|
if (versioned) {
|
|
42
42
|
const inspection = await read(versioned[1]);
|
|
43
43
|
return inspection && reportRevision(inspection) === versioned[2]
|
|
44
|
-
? Buffer.from(JSON.stringify(packJson(inspectionAsset(inspection, options
|
|
44
|
+
? Buffer.from(JSON.stringify(packJson(inspectionAsset(inspection, options)))) : undefined;
|
|
45
45
|
}
|
|
46
46
|
return files.get(name);
|
|
47
47
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { canonicalMetricId, definitions } from '../../../core/model/measurement.js';
|
|
2
|
+
import { isRecord } from '../../../core/model/plugin-data.js';
|
|
2
3
|
import { qualitySummary } from '../../../core/model/quality-summary.js';
|
|
3
4
|
import { securityCounts } from './security-summary.js';
|
|
4
5
|
import { compareHistoryEntries } from '../wire/public-history-model.js';
|
|
@@ -105,7 +106,9 @@ export function historyEntry(report) {
|
|
|
105
106
|
lineCoverage = { covered: item.covered, total: item.total };
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
|
-
const
|
|
109
|
+
const window = report.appliedConfig.churnWindow;
|
|
110
|
+
const endingAt = isRecord(window) && typeof window.endingAt === 'string' ? window.endingAt : '';
|
|
111
|
+
const committedAt = Date.parse(report.committedAt ?? endingAt);
|
|
109
112
|
const generatedAt = Date.parse(report.generatedAt);
|
|
110
113
|
return { sha: report.subject.id, generatedAt: Number.isFinite(generatedAt) ? new Date(generatedAt).toISOString() : '',
|
|
111
114
|
...(Number.isFinite(committedAt) ? { committedAt: new Date(committedAt).toISOString() } : {}), status: report.status,
|
|
@@ -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,5 +1,4 @@
|
|
|
1
|
+
import type { LanguageLookup } from '../../../core/model/language.js';
|
|
1
2
|
import type { Report } from '../validation/report.js';
|
|
2
3
|
import type { FileMetricsReport } from '../wire/file-metrics-model.js';
|
|
3
|
-
export
|
|
4
|
-
export type { FileMetricsReport } from '../wire/file-metrics-model.js';
|
|
5
|
-
export declare function fileMetrics(report: Report): FileMetricsReport;
|
|
4
|
+
export declare function fileMetrics(report: Report, registry?: LanguageLookup): FileMetricsReport;
|