flashtrace 0.9.2 → 0.11.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/README.md +0 -1
- package/dist/flashtrace.mjs +428 -149
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/flashtrace.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
7
7
|
|
|
8
8
|
// src/cli.mjs
|
|
9
9
|
import { promises as fs2, readFileSync } from "node:fs";
|
|
10
|
-
import
|
|
10
|
+
import path5 from "node:path";
|
|
11
11
|
import process3 from "node:process";
|
|
12
12
|
|
|
13
13
|
// src/errors.mjs
|
|
@@ -163,7 +163,7 @@ var CODE_EXT = new Set(Object.keys(BY_EXT));
|
|
|
163
163
|
var grammarFor = (ext) => BY_EXT[ext] ?? null;
|
|
164
164
|
|
|
165
165
|
// src/files.mjs
|
|
166
|
-
var
|
|
166
|
+
var SPEC_EXT = /* @__PURE__ */ new Set([".md", ".markdown"]);
|
|
167
167
|
var GIT_LOCATIONS = process.platform === "win32" ? [
|
|
168
168
|
String.raw`C:\Program Files\Git\cmd\git.exe`,
|
|
169
169
|
String.raw`C:\Program Files (x86)\Git\cmd\git.exe`
|
|
@@ -222,7 +222,7 @@ async function collectFiles(dirs) {
|
|
|
222
222
|
}
|
|
223
223
|
return [...files].filter((file) => {
|
|
224
224
|
const ext = path.extname(file).toLowerCase();
|
|
225
|
-
return
|
|
225
|
+
return SPEC_EXT.has(ext) || CODE_EXT.has(ext);
|
|
226
226
|
}).sort(compareStrings);
|
|
227
227
|
}
|
|
228
228
|
|
|
@@ -233,18 +233,23 @@ var WILDCARD_SRC = String.raw`(?:\d+\.\d+\.x|\d+\.x\.y|x\.y\.z|\d+\.x|x\.y|x)`;
|
|
|
233
233
|
var REV_REF_SRC = `(?:${WILDCARD_SRC}|${REV_SRC})`;
|
|
234
234
|
var ID_SRC = String.raw`([A-Za-z]+):(?:((?:${SEGMENT_SRC}\/)*${SEGMENT_SRC})\/)?(${SEGMENT_SRC})#(${REV_SRC})`;
|
|
235
235
|
var ID_RE = new RegExp(`^${ID_SRC}$`);
|
|
236
|
-
var
|
|
237
|
-
var
|
|
236
|
+
var PATH_SRC = String.raw`(?:${SEGMENT_SRC}\/)*${SEGMENT_SRC}`;
|
|
237
|
+
var REF_SRC = `([A-Za-z]+)(?::(${PATH_SRC}))?(?:#(${REV_REF_SRC}))?`;
|
|
238
|
+
var REF_RE = new RegExp(`^${REF_SRC}$`);
|
|
239
|
+
var COVER_REF_RE = new RegExp(`^([A-Za-z]+)(?::(${PATH_SRC}))?(?:#(${REV_SRC}))?$`);
|
|
238
240
|
var FORWARD_SRC = String.raw`\[\s*${ID_SRC}\s*-->\s*${ID_SRC}\s*\]`;
|
|
239
241
|
var makeId = (type, group, name, rev) => `${type}:${group ? group + "/" : ""}${name}#${rev}`;
|
|
240
|
-
var makeForward = (m, base, file, line) => ({
|
|
242
|
+
var makeForward = (m, base, file, line, character) => ({
|
|
241
243
|
from: makeId(m[base], m[base + 1], m[base + 2], m[base + 3]),
|
|
242
244
|
to: makeId(m[base + 4], m[base + 5], m[base + 6], m[base + 7]),
|
|
243
245
|
file,
|
|
244
|
-
line
|
|
246
|
+
line,
|
|
247
|
+
character
|
|
245
248
|
});
|
|
246
249
|
var keyOf = (id) => id.slice(0, id.lastIndexOf("#"));
|
|
247
250
|
var revOf = (id) => id.slice(id.lastIndexOf("#") + 1);
|
|
251
|
+
var pathOf = (id) => id.slice(id.indexOf(":") + 1, id.lastIndexOf("#"));
|
|
252
|
+
var resolveRef = (type, path6, rev, ownerId) => `${type}:${path6 ?? pathOf(ownerId)}#${rev ?? revOf(ownerId)}`;
|
|
248
253
|
function compareRev(a, b) {
|
|
249
254
|
const partsA = a.split(".");
|
|
250
255
|
const partsB = b.split(".");
|
|
@@ -268,25 +273,27 @@ function revMatches(pattern, concrete) {
|
|
|
268
273
|
return true;
|
|
269
274
|
}
|
|
270
275
|
var idMatches = (need, id) => keyOf(need) === keyOf(id) && revMatches(revOf(need), revOf(id));
|
|
271
|
-
function
|
|
276
|
+
function parseNeedEntry(raw, ownerId) {
|
|
272
277
|
const cleaned = raw.replaceAll("`", "").trim();
|
|
273
|
-
const m = cleaned.match(
|
|
274
|
-
return m ?
|
|
278
|
+
const m = cleaned.match(REF_RE);
|
|
279
|
+
return m ? resolveRef(m[1], m[2], m[3], ownerId) : null;
|
|
275
280
|
}
|
|
276
|
-
function
|
|
281
|
+
function parseCoverEntry(raw, ownerId) {
|
|
277
282
|
const cleaned = raw.replaceAll("`", "").trim();
|
|
278
|
-
const m = cleaned.match(
|
|
279
|
-
return m ?
|
|
283
|
+
const m = cleaned.match(COVER_REF_RE);
|
|
284
|
+
return m ? resolveRef(m[1], m[2], m[3], ownerId) : null;
|
|
280
285
|
}
|
|
281
|
-
function newItem(id, origin, file, line) {
|
|
286
|
+
function newItem(id, origin, file, line, character) {
|
|
282
287
|
return {
|
|
283
288
|
id,
|
|
284
289
|
key: keyOf(id),
|
|
285
290
|
revision: revOf(id),
|
|
286
291
|
origin,
|
|
287
|
-
// '
|
|
292
|
+
// 'spec' | 'code'
|
|
288
293
|
file,
|
|
289
294
|
line,
|
|
295
|
+
character,
|
|
296
|
+
// 1-based column of the first character of the defining construct
|
|
290
297
|
title: null,
|
|
291
298
|
description: [],
|
|
292
299
|
needs: [],
|
|
@@ -307,9 +314,10 @@ var KEYWORD_RE = /^(Needs|Covers|Tags):\s*((?:\S.*)?)$/;
|
|
|
307
314
|
var BULLET_RE = /^\s*[-*+]\s+(\S(?:.*\S)?)\s*$/;
|
|
308
315
|
var DELIMITER_CELL_RE = /^:?-+:?$/;
|
|
309
316
|
var FORWARD_LINE_RE = new RegExp(String.raw`^\s*(\`?)${FORWARD_SRC}\1\s*$`);
|
|
317
|
+
var firstNonBlankColumn = (line) => line.search(/\S/) + 1;
|
|
310
318
|
function takeForward(line, file, lineIndex, forwards) {
|
|
311
319
|
const forward = line.match(FORWARD_LINE_RE);
|
|
312
|
-
if (forward) forwards.push(makeForward(forward, 2, file, lineIndex + 1));
|
|
320
|
+
if (forward) forwards.push(makeForward(forward, 2, file, lineIndex + 1, firstNonBlankColumn(line)));
|
|
313
321
|
return !!forward;
|
|
314
322
|
}
|
|
315
323
|
function isParagraphLine(line) {
|
|
@@ -358,13 +366,24 @@ function titleAbove(lines, inTable, definitionIndex) {
|
|
|
358
366
|
}
|
|
359
367
|
function keywordEntries(lines, j, inline) {
|
|
360
368
|
if (inline.trim() !== "") {
|
|
361
|
-
|
|
369
|
+
const inlineStart = lines[j].length - inline.length;
|
|
370
|
+
const entries2 = [];
|
|
371
|
+
let pos = 0;
|
|
372
|
+
for (const part of inline.split(",")) {
|
|
373
|
+
const value = part.trim();
|
|
374
|
+
if (value) {
|
|
375
|
+
const leading = part.length - part.trimStart().length;
|
|
376
|
+
entries2.push({ value, line: j + 1, character: inlineStart + pos + leading + 1 });
|
|
377
|
+
}
|
|
378
|
+
pos += part.length + 1;
|
|
379
|
+
}
|
|
380
|
+
return { entries: entries2, j };
|
|
362
381
|
}
|
|
363
382
|
const entries = [];
|
|
364
383
|
while (j + 1 < lines.length) {
|
|
365
384
|
const bullet = lines[j + 1].match(BULLET_RE);
|
|
366
385
|
if (!bullet) break;
|
|
367
|
-
entries.push(bullet[1].trim());
|
|
386
|
+
entries.push({ value: bullet[1].trim(), line: j + 2, character: lines[j + 1].indexOf(bullet[1]) + 1 });
|
|
368
387
|
j++;
|
|
369
388
|
}
|
|
370
389
|
return { entries, j };
|
|
@@ -376,6 +395,26 @@ function rowCells(line) {
|
|
|
376
395
|
if (row.endsWith("|")) row = row.slice(0, -1);
|
|
377
396
|
return row.split("|").map((cell) => cell.trim());
|
|
378
397
|
}
|
|
398
|
+
function rowCellColumns(line) {
|
|
399
|
+
if (rowCells(line) === null) return [firstNonBlankColumn(line)];
|
|
400
|
+
let base = line.length - line.trimStart().length;
|
|
401
|
+
const trimmed = line.trim();
|
|
402
|
+
let body = trimmed;
|
|
403
|
+
if (body.startsWith("|")) {
|
|
404
|
+
body = body.slice(1);
|
|
405
|
+
base += 1;
|
|
406
|
+
}
|
|
407
|
+
if (body.endsWith("|")) body = body.slice(0, -1);
|
|
408
|
+
const columns = [];
|
|
409
|
+
let pos = 0;
|
|
410
|
+
for (const part of body.split("|")) {
|
|
411
|
+
const value = part.trim();
|
|
412
|
+
const leading = value ? part.length - part.trimStart().length : 0;
|
|
413
|
+
columns.push(base + pos + leading + 1);
|
|
414
|
+
pos += part.length + 1;
|
|
415
|
+
}
|
|
416
|
+
return columns;
|
|
417
|
+
}
|
|
379
418
|
function tableStartsAt(lines, j) {
|
|
380
419
|
const header = rowCells(lines[j]);
|
|
381
420
|
if (!header) return false;
|
|
@@ -403,12 +442,14 @@ function scanTables(lines, file, problems) {
|
|
|
403
442
|
for (let k = start; k <= end; k++) {
|
|
404
443
|
inTable[k] = true;
|
|
405
444
|
if (k === start + 1) continue;
|
|
445
|
+
const columns = rowCellColumns(lines[k]);
|
|
406
446
|
rowCellsInTable(lines[k]).forEach((cell, col) => {
|
|
407
447
|
const definition = keywordColumns.has(col) ? null : cell.match(DEFINITION_RE);
|
|
408
448
|
if (definition)
|
|
409
449
|
problems.push({
|
|
410
450
|
file,
|
|
411
451
|
line: k + 1,
|
|
452
|
+
character: columns[col],
|
|
412
453
|
message: `item ${makeId(definition[1], definition[2], definition[3], definition[4])} defined inside a table; a table cell is not an item definition`
|
|
413
454
|
});
|
|
414
455
|
});
|
|
@@ -428,28 +469,37 @@ function takeKeywordTable(lines, inTable, j, item, file, problems) {
|
|
|
428
469
|
while (j + 1 < lines.length && inTable[j + 1]) {
|
|
429
470
|
j++;
|
|
430
471
|
const cells = rowCellsInTable(lines[j]);
|
|
472
|
+
const cellColumns = rowCellColumns(lines[j]);
|
|
431
473
|
for (const [col, keyword] of columns) {
|
|
432
474
|
if (cells[col])
|
|
433
|
-
applyKeyword(
|
|
475
|
+
applyKeyword(
|
|
476
|
+
item,
|
|
477
|
+
keyword,
|
|
478
|
+
[{ value: cells[col], line: j + 1, character: cellColumns[col] }],
|
|
479
|
+
file,
|
|
480
|
+
problems,
|
|
481
|
+
`the ${keyword} column of ${item.id}`
|
|
482
|
+
);
|
|
434
483
|
}
|
|
435
484
|
}
|
|
436
485
|
return j;
|
|
437
486
|
}
|
|
438
|
-
function applyKeyword(item, keyword, entries, file,
|
|
487
|
+
function applyKeyword(item, keyword, entries, file, problems, source) {
|
|
439
488
|
if (keyword === "Tags") {
|
|
440
|
-
item.tags.push(
|
|
489
|
+
for (const entry of entries) item.tags.push(entry.value);
|
|
441
490
|
return;
|
|
442
491
|
}
|
|
443
492
|
const target = keyword === "Needs" ? "needs" : "covers";
|
|
444
|
-
const parse = keyword === "Needs" ? parseNeedEntry :
|
|
493
|
+
const parse = keyword === "Needs" ? parseNeedEntry : parseCoverEntry;
|
|
445
494
|
for (const entry of entries) {
|
|
446
|
-
const id = parse(entry);
|
|
495
|
+
const id = parse(entry.value, item.id);
|
|
447
496
|
if (id) item[target].push(id);
|
|
448
497
|
else
|
|
449
498
|
problems.push({
|
|
450
499
|
file,
|
|
451
|
-
line:
|
|
452
|
-
|
|
500
|
+
line: entry.line,
|
|
501
|
+
character: entry.character,
|
|
502
|
+
message: `invalid ID "${entry.value}" in ${source}`
|
|
453
503
|
});
|
|
454
504
|
}
|
|
455
505
|
}
|
|
@@ -473,7 +523,6 @@ function parseItemBody(lines, boundary, start, item, file, problems, forwards) {
|
|
|
473
523
|
keywordMatch[1],
|
|
474
524
|
collected.entries,
|
|
475
525
|
file,
|
|
476
|
-
j + 1,
|
|
477
526
|
problems,
|
|
478
527
|
`${keywordMatch[1]}: list of ${item.id}`
|
|
479
528
|
);
|
|
@@ -508,6 +557,7 @@ function parseMarkdown(file, text, problems, forwards = []) {
|
|
|
508
557
|
problems.push({
|
|
509
558
|
file,
|
|
510
559
|
line: i + 1,
|
|
560
|
+
character: firstNonBlankColumn(lines[i]),
|
|
511
561
|
message: `item ${makeId(definition[1], definition[2], definition[3], definition[4])} defined inside a setext heading; a heading is not an item definition`
|
|
512
562
|
});
|
|
513
563
|
i++;
|
|
@@ -517,7 +567,7 @@ function parseMarkdown(file, text, problems, forwards = []) {
|
|
|
517
567
|
i++;
|
|
518
568
|
continue;
|
|
519
569
|
}
|
|
520
|
-
const item = newItem(makeId(definition[1], definition[2], definition[3], definition[4]), "
|
|
570
|
+
const item = newItem(makeId(definition[1], definition[2], definition[3], definition[4]), "spec", file, i + 1, firstNonBlankColumn(lines[i]));
|
|
521
571
|
item.title = titleAbove(lines, inTable, i);
|
|
522
572
|
i = parseItemBody(lines, boundary, i + 1, item, file, problems, forwards);
|
|
523
573
|
items.push(item);
|
|
@@ -528,7 +578,7 @@ function parseMarkdown(file, text, problems, forwards = []) {
|
|
|
528
578
|
// src/parse-code.mjs
|
|
529
579
|
import path2 from "node:path";
|
|
530
580
|
var TAG_RE = new RegExp(
|
|
531
|
-
String.raw`\[(?:\s*${ID_SRC}\s*)?>>\s*${
|
|
581
|
+
String.raw`\[(?:\s*${ID_SRC}\s*)?>>\s*${REF_SRC}\s*\]|\[\s*${ID_SRC}\s*\]`,
|
|
532
582
|
"g"
|
|
533
583
|
);
|
|
534
584
|
var FORWARD_RE = new RegExp(FORWARD_SRC, "g");
|
|
@@ -607,9 +657,9 @@ function readBlockRest(line, pos, block, limit = line.length) {
|
|
|
607
657
|
}
|
|
608
658
|
block.depth--;
|
|
609
659
|
i = closeIdx + close.length;
|
|
610
|
-
if (block.depth === 0) return {
|
|
660
|
+
if (block.depth === 0) return { end: closeIdx, pos: i, closed: true };
|
|
611
661
|
}
|
|
612
|
-
return {
|
|
662
|
+
return { end: limit, pos: limit, closed: false };
|
|
613
663
|
}
|
|
614
664
|
function regionExitAt(line, pos, region) {
|
|
615
665
|
const m = matchAt(region.exit, line, pos);
|
|
@@ -619,31 +669,34 @@ function consumeBlock(line, pos, state, exit) {
|
|
|
619
669
|
const rest = readBlockRest(line, pos, state.block, exit ? exit.idx : line.length);
|
|
620
670
|
if (rest.closed) {
|
|
621
671
|
state.block = null;
|
|
622
|
-
return {
|
|
672
|
+
return { end: rest.end, pos: rest.pos };
|
|
623
673
|
}
|
|
624
674
|
if (exit) {
|
|
625
675
|
state.block = null;
|
|
626
676
|
state.region = null;
|
|
627
|
-
return {
|
|
677
|
+
return { end: rest.end, pos: exit.idx + exit.len };
|
|
628
678
|
}
|
|
629
|
-
return {
|
|
679
|
+
return { end: rest.end, pos: rest.pos };
|
|
630
680
|
}
|
|
631
681
|
function consumeLine(line, pos, state, exit) {
|
|
632
682
|
if (exit) {
|
|
633
683
|
state.region = null;
|
|
634
|
-
return {
|
|
684
|
+
return { end: exit.idx, pos: exit.idx + exit.len, done: false };
|
|
635
685
|
}
|
|
636
|
-
return {
|
|
686
|
+
return { end: line.length, pos: line.length, done: true };
|
|
637
687
|
}
|
|
638
688
|
function commentText(line, state, grammar) {
|
|
639
689
|
const spans = urlSpans(line);
|
|
640
|
-
|
|
690
|
+
const buffer = new Array(line.length).fill(" ");
|
|
691
|
+
const keep = (from, to) => {
|
|
692
|
+
for (let k = from; k < to; k++) buffer[k] = line[k];
|
|
693
|
+
};
|
|
641
694
|
let pos = 0;
|
|
642
695
|
while (pos < line.length) {
|
|
643
696
|
const exit = state.region ? regionExitAt(line, pos, state.region) : null;
|
|
644
697
|
if (state.block) {
|
|
645
698
|
const consumed = consumeBlock(line, pos, state, exit);
|
|
646
|
-
|
|
699
|
+
keep(pos, consumed.end);
|
|
647
700
|
pos = consumed.pos;
|
|
648
701
|
continue;
|
|
649
702
|
}
|
|
@@ -652,7 +705,7 @@ function commentText(line, state, grammar) {
|
|
|
652
705
|
pos = event.idx + event.len;
|
|
653
706
|
if (event.kind === "line") {
|
|
654
707
|
const consumed = consumeLine(line, pos, state, exit);
|
|
655
|
-
|
|
708
|
+
keep(pos, consumed.end);
|
|
656
709
|
pos = consumed.pos;
|
|
657
710
|
if (consumed.done) break;
|
|
658
711
|
} else if (event.kind === "block") {
|
|
@@ -663,38 +716,33 @@ function commentText(line, state, grammar) {
|
|
|
663
716
|
state.region = null;
|
|
664
717
|
}
|
|
665
718
|
}
|
|
666
|
-
return
|
|
719
|
+
return buffer.join("");
|
|
720
|
+
}
|
|
721
|
+
function attachNeed(m, file, line, character, state, problems) {
|
|
722
|
+
const source = m[1] ? makeId(m[1], m[2], m[3], m[4]) : null;
|
|
723
|
+
const anchor = source ? state.byId.get(source) : state.lastItem;
|
|
724
|
+
if (!anchor) {
|
|
725
|
+
const written = m[5] + (m[6] ? `:${m[6]}` : "") + (m[7] ? `#${m[7]}` : "");
|
|
726
|
+
problems.push({
|
|
727
|
+
file,
|
|
728
|
+
line,
|
|
729
|
+
character,
|
|
730
|
+
message: source ? `need tag [${source} >> ${written}] has no preceding item tag [${source}] in this file` : `need tag [>>${written}] has no preceding item tag in this file`
|
|
731
|
+
});
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
anchor.needs.push(resolveRef(m[5], m[6], m[7], anchor.id));
|
|
667
735
|
}
|
|
668
736
|
function collectTags(comment, file, line, state, items, problems) {
|
|
669
737
|
for (const m of comment.matchAll(TAG_RE)) {
|
|
670
|
-
|
|
671
|
-
|
|
738
|
+
const character = m.index + 1;
|
|
739
|
+
if (m[8]) {
|
|
740
|
+
const item = newItem(makeId(m[8], m[9], m[10], m[11]), "code", file, line, character);
|
|
672
741
|
state.lastItem = item;
|
|
673
742
|
state.byId.set(item.id, item);
|
|
674
743
|
items.push(item);
|
|
675
|
-
continue;
|
|
676
|
-
}
|
|
677
|
-
const id = makeId(m[5], m[6], m[7], m[8]);
|
|
678
|
-
if (m[1]) {
|
|
679
|
-
const source = makeId(m[1], m[2], m[3], m[4]);
|
|
680
|
-
const anchor = state.byId.get(source);
|
|
681
|
-
if (anchor) {
|
|
682
|
-
anchor.needs.push(id);
|
|
683
|
-
} else {
|
|
684
|
-
problems.push({
|
|
685
|
-
file,
|
|
686
|
-
line,
|
|
687
|
-
message: `need tag [${source} >> ${id}] has no preceding item tag [${source}] in this file`
|
|
688
|
-
});
|
|
689
|
-
}
|
|
690
|
-
} else if (state.lastItem) {
|
|
691
|
-
state.lastItem.needs.push(id);
|
|
692
744
|
} else {
|
|
693
|
-
problems
|
|
694
|
-
file,
|
|
695
|
-
line,
|
|
696
|
-
message: `need tag [>>${id}] has no preceding item tag in this file`
|
|
697
|
-
});
|
|
745
|
+
attachNeed(m, file, line, character, state, problems);
|
|
698
746
|
}
|
|
699
747
|
}
|
|
700
748
|
}
|
|
@@ -707,35 +755,81 @@ function parseCode(file, text, problems, forwards = []) {
|
|
|
707
755
|
for (let i = 0; i < lines.length; i++) {
|
|
708
756
|
const comment = commentText(lines[i], state, grammar);
|
|
709
757
|
for (const m of comment.matchAll(FORWARD_RE)) {
|
|
710
|
-
forwards.push(makeForward(m, 1, file, i + 1));
|
|
758
|
+
forwards.push(makeForward(m, 1, file, i + 1, m.index + 1));
|
|
711
759
|
}
|
|
712
760
|
collectTags(comment, file, i + 1, state, items, problems);
|
|
713
761
|
}
|
|
714
762
|
return items;
|
|
715
763
|
}
|
|
716
764
|
|
|
765
|
+
// src/defects.mjs
|
|
766
|
+
var DEFECT_KINDS = Object.freeze([
|
|
767
|
+
"uncovered-need",
|
|
768
|
+
"uncovered-forward",
|
|
769
|
+
"orphaned-cover",
|
|
770
|
+
"unwanted-cover",
|
|
771
|
+
"unwanted-item",
|
|
772
|
+
"duplicate-id",
|
|
773
|
+
"duplicate-forwarding"
|
|
774
|
+
]);
|
|
775
|
+
var uncoveredNeed = (need) => ({
|
|
776
|
+
kind: "uncovered-need",
|
|
777
|
+
ref: need,
|
|
778
|
+
message: `uncovered: needs ${need}, which does not exist`
|
|
779
|
+
});
|
|
780
|
+
var uncoveredForward = (target) => ({
|
|
781
|
+
kind: "uncovered-forward",
|
|
782
|
+
ref: target,
|
|
783
|
+
message: `uncovered: forwards to ${target}, which does not exist`
|
|
784
|
+
});
|
|
785
|
+
var orphanedCover = (coverId) => ({
|
|
786
|
+
kind: "orphaned-cover",
|
|
787
|
+
ref: coverId,
|
|
788
|
+
message: `orphaned: covers ${coverId}, which does not exist`
|
|
789
|
+
});
|
|
790
|
+
var unwantedCover = (coverId, itemId) => ({
|
|
791
|
+
kind: "unwanted-cover",
|
|
792
|
+
ref: coverId,
|
|
793
|
+
message: `unwanted: covers ${coverId}, but ${coverId} does not need ${itemId}`
|
|
794
|
+
});
|
|
795
|
+
var unwantedItem = (itemId) => ({
|
|
796
|
+
kind: "unwanted-item",
|
|
797
|
+
ref: itemId,
|
|
798
|
+
message: `unwanted: no item needs ${itemId}`
|
|
799
|
+
});
|
|
800
|
+
var duplicateId = (id, count) => ({
|
|
801
|
+
kind: "duplicate-id",
|
|
802
|
+
ref: id,
|
|
803
|
+
message: `duplicate: ID ${id} is defined ${count} times`
|
|
804
|
+
});
|
|
805
|
+
var duplicateForwarding = (from, count) => ({
|
|
806
|
+
kind: "duplicate-forwarding",
|
|
807
|
+
ref: from,
|
|
808
|
+
message: `duplicate: forwarding for ${from} is declared ${count} times`
|
|
809
|
+
});
|
|
810
|
+
|
|
717
811
|
// src/analyze.mjs
|
|
718
|
-
function checkItemReferences(item, byId, matchesOf, isNeeded,
|
|
812
|
+
function checkItemReferences(item, byId, matchesOf, isNeeded, withRevisions, forwardTargets) {
|
|
719
813
|
const forwardTarget = forwardTargets.get(item.id);
|
|
720
814
|
if (forwardTarget !== void 0) {
|
|
721
815
|
if (!byId.has(forwardTarget))
|
|
722
|
-
item.defects.push(
|
|
816
|
+
item.defects.push(withRevisions(uncoveredForward(forwardTarget)));
|
|
723
817
|
} else {
|
|
724
818
|
for (const need of item.needs) {
|
|
725
819
|
if (matchesOf(need).length === 0)
|
|
726
|
-
item.defects.push(
|
|
820
|
+
item.defects.push(withRevisions(uncoveredNeed(need)));
|
|
727
821
|
}
|
|
728
822
|
}
|
|
729
823
|
for (const coverId of item.covers) {
|
|
730
824
|
const targets = byId.get(coverId);
|
|
731
825
|
if (!targets) {
|
|
732
|
-
item.defects.push(
|
|
826
|
+
item.defects.push(withRevisions(orphanedCover(coverId)));
|
|
733
827
|
} else if (!targets.some((target) => target.needs.some((need) => idMatches(need, item.id)))) {
|
|
734
|
-
item.defects.push(
|
|
828
|
+
item.defects.push(unwantedCover(coverId, item.id));
|
|
735
829
|
}
|
|
736
830
|
}
|
|
737
831
|
if (item.origin === "code" && !isNeeded(item.id)) {
|
|
738
|
-
item.defects.push(
|
|
832
|
+
item.defects.push(unwantedItem(item.id));
|
|
739
833
|
}
|
|
740
834
|
}
|
|
741
835
|
function dropCyclicForwards(forwardTargets, declarationBySource, problems) {
|
|
@@ -743,23 +837,30 @@ function dropCyclicForwards(forwardTargets, declarationBySource, problems) {
|
|
|
743
837
|
for (const start of forwardTargets.keys()) {
|
|
744
838
|
if (done.has(start)) continue;
|
|
745
839
|
const seen = /* @__PURE__ */ new Map();
|
|
746
|
-
const
|
|
840
|
+
const path6 = [];
|
|
747
841
|
let current = start;
|
|
748
842
|
while (forwardTargets.has(current) && !done.has(current) && !seen.has(current)) {
|
|
749
|
-
seen.set(current,
|
|
750
|
-
|
|
843
|
+
seen.set(current, path6.length);
|
|
844
|
+
path6.push(current);
|
|
751
845
|
current = forwardTargets.get(current);
|
|
752
846
|
}
|
|
753
847
|
if (seen.has(current)) {
|
|
754
|
-
const cycle =
|
|
848
|
+
const cycle = path6.slice(seen.get(current));
|
|
755
849
|
const chain = [...cycle, current].join(" --> ");
|
|
756
850
|
for (const id of cycle) {
|
|
757
851
|
const declaration = declarationBySource.get(id);
|
|
758
|
-
|
|
852
|
+
declaration.effective = false;
|
|
853
|
+
declaration.voidedBy = "cycle";
|
|
854
|
+
problems.push({
|
|
855
|
+
file: declaration.file,
|
|
856
|
+
line: declaration.line,
|
|
857
|
+
character: declaration.character,
|
|
858
|
+
message: `cyclic forwarding: ${chain}`
|
|
859
|
+
});
|
|
759
860
|
forwardTargets.delete(id);
|
|
760
861
|
}
|
|
761
862
|
}
|
|
762
|
-
for (const id of
|
|
863
|
+
for (const id of path6) done.add(id);
|
|
763
864
|
}
|
|
764
865
|
}
|
|
765
866
|
function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
|
|
@@ -772,17 +873,25 @@ function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
|
|
|
772
873
|
for (const [from, group] of forwardsBySource) {
|
|
773
874
|
const sources = byId.get(from);
|
|
774
875
|
if (!sources) {
|
|
775
|
-
for (const forward of group)
|
|
876
|
+
for (const forward of group) {
|
|
877
|
+
forward.effective = false;
|
|
878
|
+
forward.voidedBy = "missing-source";
|
|
776
879
|
problems.push({
|
|
777
880
|
file: forward.file,
|
|
778
881
|
line: forward.line,
|
|
882
|
+
character: forward.character,
|
|
779
883
|
message: `forwarding from ${from}, which does not exist${revHint(from)}`
|
|
780
884
|
});
|
|
885
|
+
}
|
|
781
886
|
continue;
|
|
782
887
|
}
|
|
783
888
|
if (group.length > 1)
|
|
784
|
-
for (const item of sources)
|
|
785
|
-
|
|
889
|
+
for (const item of sources) item.defects.push(duplicateForwarding(from, group.length));
|
|
890
|
+
group[0].effective = true;
|
|
891
|
+
for (let i = 1; i < group.length; i++) {
|
|
892
|
+
group[i].effective = false;
|
|
893
|
+
group[i].voidedBy = "duplicate";
|
|
894
|
+
}
|
|
786
895
|
forwardTargets.set(from, group[0].to);
|
|
787
896
|
declarationBySource.set(from, group[0]);
|
|
788
897
|
}
|
|
@@ -819,13 +928,43 @@ function groupIdsByKey(byId) {
|
|
|
819
928
|
(idsByKey.get(keyOf(id)) ?? idsByKey.set(keyOf(id), []).get(keyOf(id))).push(id);
|
|
820
929
|
return idsByKey;
|
|
821
930
|
}
|
|
931
|
+
function buildWantedBy(items, byId, matchesOf) {
|
|
932
|
+
const wantedBy = /* @__PURE__ */ new Map();
|
|
933
|
+
for (const item of items)
|
|
934
|
+
for (const need of item.needs)
|
|
935
|
+
for (const id of matchesOf(need))
|
|
936
|
+
for (const provider of byId.get(id))
|
|
937
|
+
(wantedBy.get(provider) ?? wantedBy.set(provider, /* @__PURE__ */ new Set()).get(provider)).add(item);
|
|
938
|
+
return wantedBy;
|
|
939
|
+
}
|
|
822
940
|
function buildResolver(items) {
|
|
823
941
|
const byId = /* @__PURE__ */ new Map();
|
|
824
942
|
for (const item of items) (byId.get(item.id) ?? byId.set(item.id, []).get(item.id)).push(item);
|
|
825
943
|
const idsByKey = groupIdsByKey(byId);
|
|
826
944
|
const matchesOf = (ref) => (idsByKey.get(keyOf(ref)) ?? []).filter((id) => idMatches(ref, id));
|
|
827
|
-
return { byId, matchesOf };
|
|
945
|
+
return { byId, matchesOf, wantedBy: buildWantedBy(items, byId, matchesOf) };
|
|
946
|
+
}
|
|
947
|
+
function statusOf(item) {
|
|
948
|
+
if (item.defects.length > 0) return "defective";
|
|
949
|
+
return item.deepCovered ? "deep-covered" : "shallow-covered";
|
|
950
|
+
}
|
|
951
|
+
function summarize(items, problems) {
|
|
952
|
+
const specItems = items.filter((item) => item.origin === "spec").length;
|
|
953
|
+
const defectiveItems = items.filter((item) => item.defects.length > 0).length;
|
|
954
|
+
const shallowCoveredItems = items.filter(
|
|
955
|
+
(item) => item.defects.length === 0 && !item.deepCovered
|
|
956
|
+
).length;
|
|
957
|
+
return {
|
|
958
|
+
items: items.length,
|
|
959
|
+
specItems,
|
|
960
|
+
codeItems: items.length - specItems,
|
|
961
|
+
okItems: items.length - defectiveItems,
|
|
962
|
+
defectiveItems,
|
|
963
|
+
shallowCoveredItems,
|
|
964
|
+
problems: problems.length
|
|
965
|
+
};
|
|
828
966
|
}
|
|
967
|
+
var isClean = (summary) => summary.defectiveItems === 0 && summary.problems === 0;
|
|
829
968
|
function splitNeeds(items) {
|
|
830
969
|
const exact = /* @__PURE__ */ new Set();
|
|
831
970
|
const wildcard = [];
|
|
@@ -844,17 +983,30 @@ function analyze(items, forwards = [], problems = []) {
|
|
|
844
983
|
const { exact: exactNeeds, wildcard: wildcardNeeds } = splitNeeds(items);
|
|
845
984
|
const isNeeded = (id) => exactNeeds.has(id) || wildcardNeeds.some((wildcard) => idMatches(wildcard, id));
|
|
846
985
|
for (const [id, group] of byId) {
|
|
847
|
-
if (group.length > 1)
|
|
848
|
-
for (const item of group) item.defects.push(`duplicate: ID ${id} is defined ${group.length} times`);
|
|
986
|
+
if (group.length > 1) for (const item of group) item.defects.push(duplicateId(id, group.length));
|
|
849
987
|
}
|
|
850
|
-
const
|
|
988
|
+
const existingRevisionsOf = (id) => {
|
|
851
989
|
const revs = revsByKey.get(keyOf(id));
|
|
852
|
-
return revs ?
|
|
990
|
+
return revs ? [...revs].sort(compareRev) : null;
|
|
991
|
+
};
|
|
992
|
+
const revHint = (id) => {
|
|
993
|
+
const revs = existingRevisionsOf(id);
|
|
994
|
+
return revs ? ` (revision mismatch: existing revision(s) of ${keyOf(id)}: ${revs.join(", ")})` : "";
|
|
995
|
+
};
|
|
996
|
+
const withRevisions = (defect) => {
|
|
997
|
+
const existingRevisions = existingRevisionsOf(defect.ref);
|
|
998
|
+
if (!existingRevisions) return defect;
|
|
999
|
+
return {
|
|
1000
|
+
kind: defect.kind,
|
|
1001
|
+
ref: defect.ref,
|
|
1002
|
+
existingRevisions,
|
|
1003
|
+
message: `${defect.message} (revision mismatch: existing revision(s) of ${keyOf(defect.ref)}: ${existingRevisions.join(", ")})`
|
|
1004
|
+
};
|
|
853
1005
|
};
|
|
854
1006
|
const forwardTargets = buildForwardMap(forwards, byId, exactNeeds, revHint, problems);
|
|
855
1007
|
for (const item of items) {
|
|
856
1008
|
item.forwardsTo = forwardTargets.get(item.id) ?? null;
|
|
857
|
-
checkItemReferences(item, byId, matchesOf, isNeeded,
|
|
1009
|
+
checkItemReferences(item, byId, matchesOf, isNeeded, withRevisions, forwardTargets);
|
|
858
1010
|
}
|
|
859
1011
|
markDeepCoverage(items, byId, matchesOf, forwardTargets);
|
|
860
1012
|
}
|
|
@@ -874,19 +1026,15 @@ function makeStyler() {
|
|
|
874
1026
|
bold: wrap("1")
|
|
875
1027
|
};
|
|
876
1028
|
}
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
}
|
|
882
|
-
function
|
|
883
|
-
const
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
for (const id of matchesOf(need))
|
|
887
|
-
for (const provider of byId.get(id))
|
|
888
|
-
(wantedBy.get(provider) ?? wantedBy.set(provider, /* @__PURE__ */ new Set()).get(provider)).add(item);
|
|
889
|
-
return wantedBy;
|
|
1029
|
+
var STATUS_STYLES = {
|
|
1030
|
+
defective: ["\u2718", "red"],
|
|
1031
|
+
"shallow-covered": ["~", "yellow"],
|
|
1032
|
+
"deep-covered": ["\u2714", "green"]
|
|
1033
|
+
};
|
|
1034
|
+
function styledStatus(item, style) {
|
|
1035
|
+
const status = statusOf(item);
|
|
1036
|
+
const [mark, color] = STATUS_STYLES[status];
|
|
1037
|
+
return { mark: style[color](mark), tag: style[color](`[${status}]`) };
|
|
890
1038
|
}
|
|
891
1039
|
function byFileLine(a, b) {
|
|
892
1040
|
if (a.file !== b.file) return a.file < b.file ? -1 : 1;
|
|
@@ -895,7 +1043,7 @@ function byFileLine(a, b) {
|
|
|
895
1043
|
function forwardEdge(item, byId, style, dimLocation) {
|
|
896
1044
|
const target = byId.get(item.forwardsTo)?.[0];
|
|
897
1045
|
if (!target) return ` ${style.cyan("\u2192")} ${item.forwardsTo} ${style.red("\u2718 missing")}`;
|
|
898
|
-
return ` ${style.cyan("\u2192")} ${item.forwardsTo} ${
|
|
1046
|
+
return ` ${style.cyan("\u2192")} ${item.forwardsTo} ${styledStatus(target, style).mark} ${dimLocation(target.file, target.line)}`;
|
|
899
1047
|
}
|
|
900
1048
|
function needEdges(item, byId, matchesOf, style, dimLocation) {
|
|
901
1049
|
const lines = [];
|
|
@@ -910,7 +1058,7 @@ function needEdges(item, byId, matchesOf, style, dimLocation) {
|
|
|
910
1058
|
const covering = byId.get(id)[0];
|
|
911
1059
|
const arrow = style.dim(`(\u2192 ${id})`);
|
|
912
1060
|
const ref = wildcard ? `${need} ${arrow}` : need;
|
|
913
|
-
lines.push(` ${style.dim("needs")} ${ref} ${
|
|
1061
|
+
lines.push(` ${style.dim("needs")} ${ref} ${styledStatus(covering, style).mark} ${dimLocation(covering.file, covering.line)}`);
|
|
914
1062
|
}
|
|
915
1063
|
}
|
|
916
1064
|
return lines;
|
|
@@ -927,27 +1075,26 @@ function coverEdges(item, byId, style, dimLocation) {
|
|
|
927
1075
|
function edgeLines(item, byId, matchesOf, wantedBy, style, dimLocation) {
|
|
928
1076
|
const lines = [];
|
|
929
1077
|
if (item.forwardsTo !== null) lines.push(forwardEdge(item, byId, style, dimLocation));
|
|
930
|
-
else if (item.origin === "
|
|
1078
|
+
else if (item.origin === "spec") lines.push(...needEdges(item, byId, matchesOf, style, dimLocation));
|
|
931
1079
|
lines.push(...coverEdges(item, byId, style, dimLocation));
|
|
932
1080
|
for (const wanting of wantedBy.get(item) ?? [])
|
|
933
1081
|
lines.push(` ${style.dim("wanted by")} ${wanting.id} ${dimLocation(wanting.file, wanting.line)}`);
|
|
934
1082
|
return lines;
|
|
935
1083
|
}
|
|
936
1084
|
function renderVerbose(items, out, style, dimLocation) {
|
|
937
|
-
const { byId, matchesOf } = buildResolver(items);
|
|
938
|
-
const wantedBy = buildWantedBy(items, byId, matchesOf);
|
|
1085
|
+
const { byId, matchesOf, wantedBy } = buildResolver(items);
|
|
939
1086
|
const sorted = [...items].sort(byFileLine);
|
|
940
1087
|
let prevFile = null;
|
|
941
1088
|
for (const item of sorted) {
|
|
942
1089
|
if (prevFile !== null && item.file !== prevFile) out.push("");
|
|
943
1090
|
prevFile = item.file;
|
|
944
|
-
const { mark, tag } =
|
|
1091
|
+
const { mark, tag } = styledStatus(item, style);
|
|
945
1092
|
const title = item.title ? " " + style.dim(`"${item.title}"`) : "";
|
|
946
1093
|
out.push(
|
|
947
1094
|
`${mark} ${style.bold(item.id)}${title} ${dimLocation(item.file, item.line)} ${tag}`,
|
|
948
1095
|
...edgeLines(item, byId, matchesOf, wantedBy, style, dimLocation)
|
|
949
1096
|
);
|
|
950
|
-
for (const defect of item.defects) out.push(` ${style.red("\u2022")} ${defect}`);
|
|
1097
|
+
for (const defect of item.defects) out.push(` ${style.red("\u2022")} ${defect.message}`);
|
|
951
1098
|
}
|
|
952
1099
|
if (sorted.length) out.push("");
|
|
953
1100
|
}
|
|
@@ -955,25 +1102,22 @@ function renderDefective(defective, out, style, dimLocation) {
|
|
|
955
1102
|
for (const item of defective) {
|
|
956
1103
|
const title = item.title ? " " + style.dim(`"${item.title}"`) : "";
|
|
957
1104
|
out.push(
|
|
958
|
-
`${
|
|
1105
|
+
`${styledStatus(item, style).mark} ${style.bold(item.id)}${title} ${dimLocation(item.file, item.line)}`
|
|
959
1106
|
);
|
|
960
|
-
for (const defect of item.defects) out.push(` ${style.red("\u2022")} ${defect}`);
|
|
1107
|
+
for (const defect of item.defects) out.push(` ${style.red("\u2022")} ${defect.message}`);
|
|
961
1108
|
out.push("");
|
|
962
1109
|
}
|
|
963
1110
|
}
|
|
964
|
-
function renderSummary(
|
|
965
|
-
const
|
|
966
|
-
const shallowCount = items.filter((item) => item.defects.length === 0 && !item.deepCovered).length;
|
|
967
|
-
const markdownCount = items.filter((item) => item.origin === "markdown").length;
|
|
968
|
-
const originBreakdown = style.dim(`(${markdownCount} from markdown, ${items.length - markdownCount} from code)`);
|
|
1111
|
+
function renderSummary(summary, out, style) {
|
|
1112
|
+
const originBreakdown = style.dim(`(${summary.specItems} from specs, ${summary.codeItems} from code)`);
|
|
969
1113
|
out.push(
|
|
970
1114
|
style.bold("Summary"),
|
|
971
|
-
` items ${items
|
|
972
|
-
` ok ${style.green(String(
|
|
973
|
-
` defective ${
|
|
1115
|
+
` items ${summary.items} ${originBreakdown}`,
|
|
1116
|
+
` ok ${style.green(String(summary.okItems))}`,
|
|
1117
|
+
` defective ${summary.defectiveItems ? style.red(String(summary.defectiveItems)) : "0"}`
|
|
974
1118
|
);
|
|
975
|
-
if (
|
|
976
|
-
if (problems
|
|
1119
|
+
if (summary.shallowCoveredItems) out.push(" " + style.dim(`of the ok items, ${summary.shallowCoveredItems} are only shallow-covered (an item further down the tracing chain is defective)`));
|
|
1120
|
+
if (summary.problems) out.push(` problems ${style.yellow(String(summary.problems))}`);
|
|
977
1121
|
out.push("");
|
|
978
1122
|
}
|
|
979
1123
|
function report(items, problems, cwd, opts = {}) {
|
|
@@ -981,21 +1125,105 @@ function report(items, problems, cwd, opts = {}) {
|
|
|
981
1125
|
const style = makeStyler();
|
|
982
1126
|
const relativePath = (file) => path3.relative(cwd, file) || file;
|
|
983
1127
|
const dimLocation = (file, line) => style.dim(`${relativePath(file)}:${line}`);
|
|
984
|
-
const
|
|
1128
|
+
const summary = summarize(items, problems);
|
|
985
1129
|
const out = [];
|
|
986
1130
|
if (verbose) renderVerbose(items, out, style, dimLocation);
|
|
987
|
-
else renderDefective(
|
|
1131
|
+
else renderDefective(items.filter((item) => item.defects.length > 0), out, style, dimLocation);
|
|
988
1132
|
for (const problem of problems) {
|
|
989
1133
|
out.push(`${style.yellow("\u26A0")} ${problem.message} ${dimLocation(problem.file, problem.line)}`);
|
|
990
1134
|
}
|
|
991
1135
|
if (problems.length) out.push("");
|
|
992
|
-
renderSummary(
|
|
993
|
-
const clean =
|
|
1136
|
+
renderSummary(summary, out, style);
|
|
1137
|
+
const clean = isClean(summary);
|
|
994
1138
|
out.push(clean ? style.green(style.bold("ok")) : style.red(style.bold("not ok")));
|
|
995
1139
|
console.log(out.join("\n"));
|
|
996
1140
|
return clean;
|
|
997
1141
|
}
|
|
998
1142
|
|
|
1143
|
+
// src/report-json.mjs
|
|
1144
|
+
import path4 from "node:path";
|
|
1145
|
+
var SCHEMA_VERSION = 0;
|
|
1146
|
+
function coverStatusOf(item) {
|
|
1147
|
+
const status = /* @__PURE__ */ new Map();
|
|
1148
|
+
for (const defect of item.defects) {
|
|
1149
|
+
if (defect.kind === "orphaned-cover") status.set(defect.ref, "orphaned");
|
|
1150
|
+
else if (defect.kind === "unwanted-cover") status.set(defect.ref, "unwanted");
|
|
1151
|
+
}
|
|
1152
|
+
return (ref) => status.get(ref) ?? "valid";
|
|
1153
|
+
}
|
|
1154
|
+
function buildForwardedFrom(items, byId) {
|
|
1155
|
+
const forwardedFrom = /* @__PURE__ */ new Map();
|
|
1156
|
+
for (const item of items) {
|
|
1157
|
+
if (item.forwardsTo === null) continue;
|
|
1158
|
+
for (const target of byId.get(item.forwardsTo) ?? [])
|
|
1159
|
+
(forwardedFrom.get(target) ?? forwardedFrom.set(target, []).get(target)).push(item);
|
|
1160
|
+
}
|
|
1161
|
+
return forwardedFrom;
|
|
1162
|
+
}
|
|
1163
|
+
function defectDocument(defect) {
|
|
1164
|
+
const out = { kind: defect.kind, ref: defect.ref };
|
|
1165
|
+
if (defect.existingRevisions) out.existingRevisions = defect.existingRevisions;
|
|
1166
|
+
out.message = defect.message;
|
|
1167
|
+
return out;
|
|
1168
|
+
}
|
|
1169
|
+
function buildReportDocument(items, forwards, problems, cwd, opts = {}) {
|
|
1170
|
+
const { version } = opts;
|
|
1171
|
+
if (typeof version !== "string")
|
|
1172
|
+
throw new TypeError(`opts.version is required: it becomes the document's "flashtrace" field`);
|
|
1173
|
+
const relative = (file) => (path4.relative(cwd, file) || file).replaceAll("\\", "/");
|
|
1174
|
+
const location = (x) => ({ file: relative(x.file), line: x.line, character: x.character });
|
|
1175
|
+
const byLocation = (a, b) => {
|
|
1176
|
+
if (a.file !== b.file) return a.file < b.file ? -1 : 1;
|
|
1177
|
+
if (a.line !== b.line) return a.line - b.line;
|
|
1178
|
+
return a.character - b.character;
|
|
1179
|
+
};
|
|
1180
|
+
const { byId, matchesOf, wantedBy } = buildResolver(items);
|
|
1181
|
+
const forwardedFrom = buildForwardedFrom(items, byId);
|
|
1182
|
+
const resolvedTo = (ref) => matchesOf(ref).sort((a, b) => compareRev(revOf(a), revOf(b)));
|
|
1183
|
+
const itemRefs = (related) => [...related].map((other) => ({ id: other.id, ...location(other) })).sort(byLocation);
|
|
1184
|
+
const itemDocument = (item) => {
|
|
1185
|
+
const coverStatus = coverStatusOf(item);
|
|
1186
|
+
return {
|
|
1187
|
+
id: item.id,
|
|
1188
|
+
title: item.title,
|
|
1189
|
+
origin: item.origin,
|
|
1190
|
+
tags: item.tags,
|
|
1191
|
+
...location(item),
|
|
1192
|
+
status: statusOf(item),
|
|
1193
|
+
defective: item.defects.length > 0,
|
|
1194
|
+
deepCovered: item.deepCovered,
|
|
1195
|
+
needs: item.needs.map((ref) => ({ ref, resolvedTo: resolvedTo(ref) })),
|
|
1196
|
+
covers: item.covers.map((ref) => ({ ref, status: coverStatus(ref) })),
|
|
1197
|
+
forwardsTo: item.forwardsTo,
|
|
1198
|
+
forwardedFrom: itemRefs(forwardedFrom.get(item) ?? []),
|
|
1199
|
+
defects: item.defects.map(defectDocument),
|
|
1200
|
+
wantedBy: itemRefs(wantedBy.get(item) ?? [])
|
|
1201
|
+
};
|
|
1202
|
+
};
|
|
1203
|
+
const forwardDocument = (forward) => {
|
|
1204
|
+
const document = { from: forward.from, to: forward.to, ...location(forward), effective: forward.effective };
|
|
1205
|
+
if (!forward.effective) document.voidedBy = forward.voidedBy;
|
|
1206
|
+
return document;
|
|
1207
|
+
};
|
|
1208
|
+
const itemDocuments = items.map(itemDocument).sort(byLocation);
|
|
1209
|
+
const problemDocuments = problems.map((problem) => ({ ...location(problem), message: problem.message })).sort(byLocation);
|
|
1210
|
+
const summary = summarize(items, problems);
|
|
1211
|
+
return {
|
|
1212
|
+
schemaVersion: SCHEMA_VERSION,
|
|
1213
|
+
flashtrace: version,
|
|
1214
|
+
ok: isClean(summary),
|
|
1215
|
+
items: itemDocuments,
|
|
1216
|
+
forwards: forwards.map(forwardDocument).sort(byLocation),
|
|
1217
|
+
problems: problemDocuments,
|
|
1218
|
+
summary
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
function reportJson(items, forwards, problems, cwd, opts = {}) {
|
|
1222
|
+
const document = buildReportDocument(items, forwards, problems, cwd, opts);
|
|
1223
|
+
console.log(JSON.stringify(document, null, 2));
|
|
1224
|
+
return document.ok;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
999
1227
|
// src/cli.mjs
|
|
1000
1228
|
var HELP = `Usage: flashtrace [options] [directory-or-file ...]
|
|
1001
1229
|
|
|
@@ -1004,10 +1232,13 @@ Traces requirement coverage between Markdown specifications and source code
|
|
|
1004
1232
|
by git are excluded.
|
|
1005
1233
|
|
|
1006
1234
|
Options:
|
|
1007
|
-
-t, --tags <t1,t2,...> only import
|
|
1235
|
+
-t, --tags <t1,t2,...> only import spec items carrying one of these
|
|
1008
1236
|
tags; add "_" to also include untagged items
|
|
1237
|
+
-f, --format <format> report format: "text" (default) or "json"; --json
|
|
1238
|
+
is shorthand for --format json. The format may be
|
|
1239
|
+
selected only once
|
|
1009
1240
|
-v, --verbose list every item with its coverage status and trace
|
|
1010
|
-
edges, not only the defective ones
|
|
1241
|
+
edges, not only the defective ones; text format only
|
|
1011
1242
|
-V, --version print the version number
|
|
1012
1243
|
-h, --help show this help
|
|
1013
1244
|
|
|
@@ -1020,36 +1251,81 @@ function packageVersion() {
|
|
|
1020
1251
|
}
|
|
1021
1252
|
function splitLongOption(token) {
|
|
1022
1253
|
const eqIndex = token.startsWith("--") ? token.indexOf("=") : -1;
|
|
1023
|
-
return eqIndex === -1 ? [token,
|
|
1254
|
+
return eqIndex === -1 ? [token, void 0] : [token.slice(0, eqIndex), token.slice(eqIndex + 1)];
|
|
1024
1255
|
}
|
|
1025
1256
|
function rejectValue(name, inline) {
|
|
1026
|
-
if (inline !==
|
|
1027
|
-
}
|
|
1257
|
+
if (inline !== void 0) throw new UsageError(`option ${name} does not take a value`);
|
|
1258
|
+
}
|
|
1259
|
+
function selectFormat(opts, raw, format) {
|
|
1260
|
+
if (opts.formatSelectedBy !== null)
|
|
1261
|
+
throw new UsageError(`the report format is already selected by ${opts.formatSelectedBy}`);
|
|
1262
|
+
opts.format = format;
|
|
1263
|
+
opts.formatSelectedBy = raw;
|
|
1264
|
+
}
|
|
1265
|
+
function reportFormat(raw, value) {
|
|
1266
|
+
if (value !== "text" && value !== "json")
|
|
1267
|
+
throw new UsageError(`invalid value for ${raw}: "${value}" (expected "text" or "json")`);
|
|
1268
|
+
return value;
|
|
1269
|
+
}
|
|
1270
|
+
var LONG_ALIAS = {
|
|
1271
|
+
"-h": "--help",
|
|
1272
|
+
"-v": "--verbose",
|
|
1273
|
+
"-V": "--version",
|
|
1274
|
+
"-t": "--tags",
|
|
1275
|
+
"-f": "--format"
|
|
1276
|
+
};
|
|
1277
|
+
function printHelp() {
|
|
1278
|
+
console.log(HELP);
|
|
1279
|
+
process3.exit(0);
|
|
1280
|
+
}
|
|
1281
|
+
function printVersion() {
|
|
1282
|
+
console.log(packageVersion());
|
|
1283
|
+
process3.exit(0);
|
|
1284
|
+
}
|
|
1285
|
+
function enableVerbose(opts) {
|
|
1286
|
+
opts.verbose = true;
|
|
1287
|
+
}
|
|
1288
|
+
function selectJsonFormat(opts, raw) {
|
|
1289
|
+
selectFormat(opts, raw, "json");
|
|
1290
|
+
}
|
|
1291
|
+
var VALUELESS_OPTIONS = /* @__PURE__ */ new Map([
|
|
1292
|
+
["--help", printHelp],
|
|
1293
|
+
["--version", printVersion],
|
|
1294
|
+
["--verbose", enableVerbose],
|
|
1295
|
+
["--json", selectJsonFormat]
|
|
1296
|
+
]);
|
|
1297
|
+
function setFormat(opts, raw, value) {
|
|
1298
|
+
selectFormat(opts, raw, reportFormat(raw, value));
|
|
1299
|
+
}
|
|
1300
|
+
function setTags(opts, raw, value) {
|
|
1301
|
+
opts.tags = value.split(",").map((tag) => tag.trim()).filter(Boolean);
|
|
1302
|
+
}
|
|
1303
|
+
var VALUED_OPTIONS = /* @__PURE__ */ new Map([
|
|
1304
|
+
["--format", setFormat],
|
|
1305
|
+
["--tags", setTags]
|
|
1306
|
+
]);
|
|
1028
1307
|
function parseArgs(argv) {
|
|
1029
|
-
const opts = { dirs: [], tags: null, verbose: false };
|
|
1308
|
+
const opts = { dirs: [], tags: null, verbose: false, format: "text", formatSelectedBy: null };
|
|
1030
1309
|
for (let i = 0; i < argv.length; i++) {
|
|
1031
|
-
const [
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
} else if (name === "-V" || name === "--version") {
|
|
1040
|
-
rejectValue(name, inline);
|
|
1041
|
-
console.log(packageVersion());
|
|
1042
|
-
process3.exit(0);
|
|
1043
|
-
} else if (name === "-t" || name === "--tags") {
|
|
1310
|
+
const [raw, inline] = splitLongOption(argv[i]);
|
|
1311
|
+
const name = LONG_ALIAS[raw] ?? raw;
|
|
1312
|
+
const applyValuelessOption = VALUELESS_OPTIONS.get(name);
|
|
1313
|
+
const applyValuedOption = VALUED_OPTIONS.get(name);
|
|
1314
|
+
if (applyValuelessOption) {
|
|
1315
|
+
rejectValue(raw, inline);
|
|
1316
|
+
applyValuelessOption(opts, raw);
|
|
1317
|
+
} else if (applyValuedOption) {
|
|
1044
1318
|
const value = inline ?? argv[++i];
|
|
1045
|
-
if (!value) throw new UsageError(`missing value for ${
|
|
1046
|
-
opts
|
|
1047
|
-
} else if (
|
|
1048
|
-
throw new UsageError(`unknown option: ${
|
|
1319
|
+
if (!value) throw new UsageError(`missing value for ${raw}`);
|
|
1320
|
+
applyValuedOption(opts, raw, value);
|
|
1321
|
+
} else if (raw.startsWith("-")) {
|
|
1322
|
+
throw new UsageError(`unknown option: ${raw}`);
|
|
1049
1323
|
} else {
|
|
1050
|
-
opts.dirs.push(
|
|
1324
|
+
opts.dirs.push(raw);
|
|
1051
1325
|
}
|
|
1052
1326
|
}
|
|
1327
|
+
if (opts.format === "json" && opts.verbose)
|
|
1328
|
+
throw new UsageError("-v/--verbose applies to the text format only");
|
|
1053
1329
|
if (opts.dirs.length === 0) opts.dirs.push(".");
|
|
1054
1330
|
return opts;
|
|
1055
1331
|
}
|
|
@@ -1061,9 +1337,9 @@ async function main() {
|
|
|
1061
1337
|
let items = [];
|
|
1062
1338
|
for (const file of files) {
|
|
1063
1339
|
const text = await fs2.readFile(file, "utf8");
|
|
1064
|
-
const ext =
|
|
1340
|
+
const ext = path5.extname(file).toLowerCase();
|
|
1065
1341
|
items.push(
|
|
1066
|
-
...
|
|
1342
|
+
...SPEC_EXT.has(ext) ? parseMarkdown(file, text, problems, forwards) : parseCode(file, text, problems, forwards)
|
|
1067
1343
|
);
|
|
1068
1344
|
}
|
|
1069
1345
|
if (opts.tags) {
|
|
@@ -1073,7 +1349,7 @@ async function main() {
|
|
|
1073
1349
|
);
|
|
1074
1350
|
}
|
|
1075
1351
|
analyze(items, forwards, problems);
|
|
1076
|
-
const clean = report(items, problems, process3.cwd(), { verbose: opts.verbose });
|
|
1352
|
+
const clean = opts.format === "json" ? reportJson(items, forwards, problems, process3.cwd(), { version: packageVersion() }) : report(items, problems, process3.cwd(), { verbose: opts.verbose });
|
|
1077
1353
|
process3.exit(clean ? 0 : 1);
|
|
1078
1354
|
}
|
|
1079
1355
|
function runCli() {
|
|
@@ -1101,9 +1377,12 @@ function runAsCli() {
|
|
|
1101
1377
|
}
|
|
1102
1378
|
if (runAsCli()) runCli();
|
|
1103
1379
|
export {
|
|
1380
|
+
DEFECT_KINDS,
|
|
1104
1381
|
UsageError,
|
|
1105
1382
|
analyze,
|
|
1383
|
+
buildReportDocument,
|
|
1106
1384
|
collectFiles,
|
|
1107
1385
|
parseCode,
|
|
1108
|
-
parseMarkdown
|
|
1386
|
+
parseMarkdown,
|
|
1387
|
+
reportJson
|
|
1109
1388
|
};
|