flashtrace 0.8.0 → 0.9.1
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 +52 -15
- package/dist/flashtrace.mjs +126 -48
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,61 @@
|
|
|
1
|
-
<
|
|
2
|
-
<
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<table>
|
|
3
|
+
<tr>
|
|
4
|
+
<td align="center">
|
|
5
|
+
<a href="https://github.com/flashtrace">
|
|
6
|
+
<img src="https://github.com/flashtrace.png" alt="flashtrace logo" width="140">
|
|
7
|
+
</a>
|
|
8
|
+
</td>
|
|
9
|
+
<td align="left">
|
|
10
|
+
<h3>flashtrace</h3>
|
|
11
|
+
<p>
|
|
12
|
+
Lightning-fast, reference-based requirement tracing that works anywhere.
|
|
13
|
+
</p>
|
|
14
|
+
<p>
|
|
15
|
+
<a href="https://github.com/flashtrace/flashtrace/blob/main/docs/index.md">
|
|
16
|
+
<img src="https://img.shields.io/badge/Spec-Driven-8e4d13.svg?labelColor=1e1e1e" alt="Spec-driven documentation." />
|
|
17
|
+
</a>
|
|
18
|
+
<a href="https://github.com/flashtrace/flashtrace/blob/main/CLAUDE.md">
|
|
19
|
+
<img src="https://img.shields.io/badge/Agent-Native-d97d0e.svg?labelColor=1e1e1e" alt="This repository was created agent-native." />
|
|
20
|
+
</a>
|
|
21
|
+
<a href="https://github.com/flashtrace/flashtrace/blob/main/LICENSE">
|
|
22
|
+
<img src="https://img.shields.io/badge/License-Apache_2.0-f9c21d.svg?labelColor=1e1e1e" alt="Released under the Apache 2.0 license." />
|
|
23
|
+
</a>
|
|
24
|
+
</p>
|
|
25
|
+
</td>
|
|
26
|
+
</tr>
|
|
27
|
+
</table>
|
|
28
|
+
</div>
|
|
6
29
|
|
|
7
|
-
|
|
30
|
+
---
|
|
31
|
+
---
|
|
8
32
|
|
|
9
|
-
<
|
|
10
|
-
Lightning-fast, reference-based requirement tracing that works anywhere.
|
|
11
|
-
</p>
|
|
33
|
+
<h4 align="center">Quality Summary</h4>
|
|
12
34
|
|
|
13
35
|
<p align="center">
|
|
14
|
-
<a href="https://
|
|
15
|
-
<img src="https://
|
|
36
|
+
<a href="https://sonarcloud.io/project/overview?id=flashtrace_flashtrace">
|
|
37
|
+
<img src="https://github.com/flashtrace/flashtrace/actions/workflows/ci.yml/badge.svg" alt="Continuous Integration status." />
|
|
38
|
+
</a>
|
|
39
|
+
<a href="https://sonarcloud.io/component_measures?metric=reliability_rating&id=flashtrace_flashtrace">
|
|
40
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=flashtrace_flashtrace&metric=reliability_rating" alt="SonarCloud reliability rating." />
|
|
41
|
+
</a>
|
|
42
|
+
<a href="https://sonarcloud.io/component_measures?metric=security_rating&id=flashtrace_flashtrace">
|
|
43
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=flashtrace_flashtrace&metric=security_rating" alt="SonarCloud security rating." />
|
|
44
|
+
</a>
|
|
45
|
+
<a href="https://sonarcloud.io/component_measures?metric=sqale_rating&id=flashtrace_flashtrace">
|
|
46
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=flashtrace_flashtrace&metric=sqale_rating" alt="SonarCloud maintainability rating." />
|
|
47
|
+
</a>
|
|
48
|
+
<a href="https://sonarcloud.io/component_measures?metric=ncloc&id=flashtrace_flashtrace">
|
|
49
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=flashtrace_flashtrace&metric=ncloc" alt="Number of lines of code." />
|
|
50
|
+
</a>
|
|
51
|
+
<a href="https://sonarcloud.io/component_measures?metric=code_smells&id=flashtrace_flashtrace">
|
|
52
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=flashtrace_flashtrace&metric=code_smells" alt="SonarCloud amount of code smells." />
|
|
16
53
|
</a>
|
|
17
|
-
<a href="https://
|
|
18
|
-
<img src="https://
|
|
54
|
+
<a href="https://sonarcloud.io/component_measures?metric=duplicated_lines&id=flashtrace_flashtrace">
|
|
55
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=flashtrace_flashtrace&metric=duplicated_lines_density" alt="SonarCloud percent of duplicated lines." />
|
|
19
56
|
</a>
|
|
20
|
-
<a href="https://
|
|
21
|
-
<img src="https://
|
|
57
|
+
<a href="https://sonarcloud.io/component_measures?metric=vulnerabilities&id=flashtrace_flashtrace">
|
|
58
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=flashtrace_flashtrace&metric=vulnerabilities" alt="SonarCloud amount of vulnerabilities." />
|
|
22
59
|
</a>
|
|
23
60
|
</p>
|
|
24
61
|
|
package/dist/flashtrace.mjs
CHANGED
|
@@ -302,27 +302,46 @@ function newItem(id, origin, file, line) {
|
|
|
302
302
|
var DEFINITION_RE = new RegExp(String.raw`^\s*\`${ID_SRC}\`\s*$`);
|
|
303
303
|
var HEADING_RE = /^(#{1,6})\s+(\S(?:.*\S)?)\s*$/;
|
|
304
304
|
var SETEXT_UNDERLINE_RE = /^ {0,3}(?:=+|-+)[ \t]*$/;
|
|
305
|
+
var THEMATIC_BREAK_RE = /^ {0,3}-{3,}[ \t]*$/;
|
|
305
306
|
var KEYWORD_RE = /^(Needs|Covers|Tags):\s*((?:\S.*)?)$/;
|
|
306
307
|
var BULLET_RE = /^\s*[-*+]\s+(\S(?:.*\S)?)\s*$/;
|
|
307
308
|
var DELIMITER_CELL_RE = /^:?-+:?$/;
|
|
308
309
|
var FORWARD_LINE_RE = new RegExp(String.raw`^\s*(\`?)${FORWARD_SRC}\1\s*$`);
|
|
309
|
-
var isBoundary = (line) => DEFINITION_RE.test(line) || HEADING_RE.test(line);
|
|
310
310
|
function takeForward(line, file, lineIndex, forwards) {
|
|
311
311
|
const forward = line.match(FORWARD_LINE_RE);
|
|
312
312
|
if (forward) forwards.push(makeForward(forward, 2, file, lineIndex + 1));
|
|
313
313
|
return !!forward;
|
|
314
314
|
}
|
|
315
315
|
function isParagraphLine(line) {
|
|
316
|
-
return line.trim() !== "" && !HEADING_RE.test(line) && !
|
|
316
|
+
return line.trim() !== "" && !HEADING_RE.test(line) && !BULLET_RE.test(line) && !SETEXT_UNDERLINE_RE.test(line);
|
|
317
317
|
}
|
|
318
|
-
|
|
318
|
+
var isParagraphAt = (lines, inTable, j) => !inTable[j] && isParagraphLine(lines[j]);
|
|
319
|
+
var isSetextHeading = (lines, inTable, titleIndex) => titleIndex + 1 < lines.length && SETEXT_UNDERLINE_RE.test(lines[titleIndex + 1]) && isParagraphAt(lines, inTable, titleIndex);
|
|
320
|
+
function opensSetextHeading(lines, inTable, j) {
|
|
321
|
+
if (!isParagraphAt(lines, inTable, j)) return false;
|
|
322
|
+
let k = j;
|
|
323
|
+
while (k + 1 < lines.length && isParagraphAt(lines, inTable, k + 1)) k++;
|
|
324
|
+
return isSetextHeading(lines, inTable, k);
|
|
325
|
+
}
|
|
326
|
+
var isBoundary = (lines, inTable, j) => !inTable[j] && DEFINITION_RE.test(lines[j]) || HEADING_RE.test(lines[j]) || opensSetextHeading(lines, inTable, j);
|
|
327
|
+
function foldSetextTitle(lines, inTable, lastIndex) {
|
|
328
|
+
let first = lastIndex;
|
|
329
|
+
while (first > 0 && isParagraphAt(lines, inTable, first - 1)) first--;
|
|
330
|
+
let title = "";
|
|
331
|
+
for (let k = first; k <= lastIndex; k++) {
|
|
332
|
+
title += lines[k].trim();
|
|
333
|
+
if (k < lastIndex) title += / {2}$/.test(lines[k]) ? "\n" : " ";
|
|
334
|
+
}
|
|
335
|
+
return title;
|
|
336
|
+
}
|
|
337
|
+
function titleAbove(lines, inTable, definitionIndex) {
|
|
319
338
|
for (let k = definitionIndex - 1; k >= 0; k--) {
|
|
320
339
|
const line = lines[k];
|
|
321
340
|
if (line.trim() === "") continue;
|
|
322
341
|
const heading = line.match(HEADING_RE);
|
|
323
342
|
if (heading) return heading[2];
|
|
324
|
-
if (
|
|
325
|
-
return lines
|
|
343
|
+
if (k > 0 && isSetextHeading(lines, inTable, k - 1)) {
|
|
344
|
+
return foldSetextTitle(lines, inTable, k - 1);
|
|
326
345
|
}
|
|
327
346
|
return null;
|
|
328
347
|
}
|
|
@@ -348,28 +367,66 @@ function rowCells(line) {
|
|
|
348
367
|
if (row.endsWith("|")) row = row.slice(0, -1);
|
|
349
368
|
return row.split("|").map((cell) => cell.trim());
|
|
350
369
|
}
|
|
351
|
-
function
|
|
370
|
+
function tableStartsAt(lines, j) {
|
|
352
371
|
const header = rowCells(lines[j]);
|
|
353
|
-
if (!header) return
|
|
372
|
+
if (!header) return false;
|
|
373
|
+
const delimiter = j + 1 < lines.length ? rowCells(lines[j + 1]) : null;
|
|
374
|
+
return delimiter?.length === header.length && delimiter.every((cell) => DELIMITER_CELL_RE.test(cell));
|
|
375
|
+
}
|
|
376
|
+
var continuesTable = (line) => line.trim() !== "" && !HEADING_RE.test(line) && !THEMATIC_BREAK_RE.test(line) && (line.includes("|") || SETEXT_UNDERLINE_RE.test(line) || DEFINITION_RE.test(line));
|
|
377
|
+
var rowCellsInTable = (line) => rowCells(line) ?? [line.trim()];
|
|
378
|
+
var isKeywordCell = (cell) => cell === "Needs" || cell === "Covers" || cell === "Tags";
|
|
379
|
+
function scanTables(lines, file, problems) {
|
|
380
|
+
const inTable = new Array(lines.length).fill(false);
|
|
381
|
+
let j = 0;
|
|
382
|
+
while (j < lines.length) {
|
|
383
|
+
if (!tableStartsAt(lines, j)) {
|
|
384
|
+
j++;
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
const keywordColumns = /* @__PURE__ */ new Set();
|
|
388
|
+
rowCells(lines[j]).forEach((cell, col) => {
|
|
389
|
+
if (isKeywordCell(cell)) keywordColumns.add(col);
|
|
390
|
+
});
|
|
391
|
+
const start = j;
|
|
392
|
+
let end = j + 1;
|
|
393
|
+
while (end + 1 < lines.length && continuesTable(lines[end + 1])) end++;
|
|
394
|
+
for (let k = start; k <= end; k++) {
|
|
395
|
+
inTable[k] = true;
|
|
396
|
+
if (k === start + 1) continue;
|
|
397
|
+
rowCellsInTable(lines[k]).forEach((cell, col) => {
|
|
398
|
+
const definition = keywordColumns.has(col) ? null : cell.match(DEFINITION_RE);
|
|
399
|
+
if (definition)
|
|
400
|
+
problems.push({
|
|
401
|
+
file,
|
|
402
|
+
line: k + 1,
|
|
403
|
+
message: `item ${makeId(definition[1], definition[2], definition[3], definition[4])} defined inside a table; a table cell is not an item definition`
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
j = end + 1;
|
|
408
|
+
}
|
|
409
|
+
return inTable;
|
|
410
|
+
}
|
|
411
|
+
function takeKeywordTable(lines, inTable, j, item, file, problems) {
|
|
412
|
+
if (!inTable[j] || j > 0 && inTable[j - 1]) return null;
|
|
354
413
|
const columns = [];
|
|
355
|
-
|
|
356
|
-
if (cell
|
|
414
|
+
rowCells(lines[j]).forEach((cell, col) => {
|
|
415
|
+
if (isKeywordCell(cell)) columns.push([col, cell]);
|
|
357
416
|
});
|
|
358
417
|
if (columns.length === 0) return null;
|
|
359
|
-
const delimiter = j + 1 < lines.length ? rowCells(lines[j + 1]) : null;
|
|
360
|
-
if (delimiter?.length !== header.length || !delimiter.every((cell) => DELIMITER_CELL_RE.test(cell))) return null;
|
|
361
418
|
j++;
|
|
362
|
-
while (j + 1 < lines.length &&
|
|
363
|
-
const cells = rowCells(lines[j + 1]);
|
|
364
|
-
if (!cells) break;
|
|
419
|
+
while (j + 1 < lines.length && inTable[j + 1]) {
|
|
365
420
|
j++;
|
|
421
|
+
const cells = rowCellsInTable(lines[j]);
|
|
366
422
|
for (const [col, keyword] of columns) {
|
|
367
|
-
if (cells[col])
|
|
423
|
+
if (cells[col])
|
|
424
|
+
applyKeyword(item, keyword, [cells[col]], file, j + 1, problems, `the ${keyword} column of ${item.id}`);
|
|
368
425
|
}
|
|
369
426
|
}
|
|
370
427
|
return j;
|
|
371
428
|
}
|
|
372
|
-
function applyKeyword(item, keyword, entries, file, keywordLine, problems) {
|
|
429
|
+
function applyKeyword(item, keyword, entries, file, keywordLine, problems, source) {
|
|
373
430
|
if (keyword === "Tags") {
|
|
374
431
|
item.tags.push(...entries);
|
|
375
432
|
return;
|
|
@@ -381,28 +438,35 @@ function applyKeyword(item, keyword, entries, file, keywordLine, problems) {
|
|
|
381
438
|
if (id) item[target].push(id);
|
|
382
439
|
else
|
|
383
440
|
problems.push({
|
|
384
|
-
severity: "error",
|
|
385
441
|
file,
|
|
386
442
|
line: keywordLine,
|
|
387
|
-
message: `invalid ID "${entry}" in ${
|
|
443
|
+
message: `invalid ID "${entry}" in ${source}`
|
|
388
444
|
});
|
|
389
445
|
}
|
|
390
446
|
}
|
|
391
|
-
function parseItemBody(lines, start, item, file, problems, forwards) {
|
|
447
|
+
function parseItemBody(lines, inTable, start, item, file, problems, forwards) {
|
|
392
448
|
let j = start;
|
|
393
449
|
let descriptionDone = false;
|
|
394
|
-
while (j < lines.length && !isBoundary(lines
|
|
450
|
+
while (j < lines.length && !isBoundary(lines, inTable, j)) {
|
|
395
451
|
const line = lines[j];
|
|
396
452
|
if (takeForward(line, file, j, forwards)) {
|
|
397
453
|
j++;
|
|
398
454
|
continue;
|
|
399
455
|
}
|
|
400
456
|
const keywordMatch = line.match(KEYWORD_RE);
|
|
401
|
-
const tableEnd = keywordMatch ? null : takeKeywordTable(lines, j, item, file, problems);
|
|
457
|
+
const tableEnd = keywordMatch ? null : takeKeywordTable(lines, inTable, j, item, file, problems);
|
|
402
458
|
if (keywordMatch) {
|
|
403
459
|
descriptionDone = true;
|
|
404
460
|
const collected = keywordEntries(lines, j, keywordMatch[2]);
|
|
405
|
-
applyKeyword(
|
|
461
|
+
applyKeyword(
|
|
462
|
+
item,
|
|
463
|
+
keywordMatch[1],
|
|
464
|
+
collected.entries,
|
|
465
|
+
file,
|
|
466
|
+
j + 1,
|
|
467
|
+
problems,
|
|
468
|
+
`${keywordMatch[1]}: list of ${item.id}`
|
|
469
|
+
);
|
|
406
470
|
j = collected.j;
|
|
407
471
|
} else if (tableEnd !== null) {
|
|
408
472
|
descriptionDone = true;
|
|
@@ -418,21 +482,32 @@ function parseItemBody(lines, start, item, file, problems, forwards) {
|
|
|
418
482
|
}
|
|
419
483
|
function parseMarkdown(file, text, problems, forwards = []) {
|
|
420
484
|
const lines = text.split(/\r?\n/);
|
|
485
|
+
const inTable = scanTables(lines, file, problems);
|
|
421
486
|
const items = [];
|
|
422
487
|
let i = 0;
|
|
423
488
|
while (i < lines.length) {
|
|
424
|
-
|
|
489
|
+
const startsHeading = opensSetextHeading(lines, inTable, i);
|
|
490
|
+
if (!startsHeading && takeForward(lines[i], file, i, forwards)) {
|
|
491
|
+
i++;
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
const definition = inTable[i] ? null : lines[i].match(DEFINITION_RE);
|
|
495
|
+
if (definition && startsHeading) {
|
|
496
|
+
problems.push({
|
|
497
|
+
file,
|
|
498
|
+
line: i + 1,
|
|
499
|
+
message: `item ${makeId(definition[1], definition[2], definition[3], definition[4])} defined inside a setext heading; a heading is not an item definition`
|
|
500
|
+
});
|
|
425
501
|
i++;
|
|
426
502
|
continue;
|
|
427
503
|
}
|
|
428
|
-
const definition = lines[i].match(DEFINITION_RE);
|
|
429
504
|
if (!definition) {
|
|
430
505
|
i++;
|
|
431
506
|
continue;
|
|
432
507
|
}
|
|
433
508
|
const item = newItem(makeId(definition[1], definition[2], definition[3], definition[4]), "markdown", file, i + 1);
|
|
434
|
-
item.title = titleAbove(lines, i);
|
|
435
|
-
i = parseItemBody(lines, i + 1, item, file, problems, forwards);
|
|
509
|
+
item.title = titleAbove(lines, inTable, i);
|
|
510
|
+
i = parseItemBody(lines, inTable, i + 1, item, file, problems, forwards);
|
|
436
511
|
items.push(item);
|
|
437
512
|
}
|
|
438
513
|
return items;
|
|
@@ -445,6 +520,19 @@ var TAG_RE = new RegExp(
|
|
|
445
520
|
"g"
|
|
446
521
|
);
|
|
447
522
|
var FORWARD_RE = new RegExp(FORWARD_SRC, "g");
|
|
523
|
+
var URL_RE = /[A-Za-z][A-Za-z0-9+.-]{0,63}:\/\/[^\s"'`<>[\]]*/g;
|
|
524
|
+
function urlSpans(line) {
|
|
525
|
+
if (!line.includes("://")) return [];
|
|
526
|
+
return [...line.matchAll(URL_RE)].map((m) => ({ start: m.index, end: m.index + m[0].length }));
|
|
527
|
+
}
|
|
528
|
+
function markerIndex(line, marker, pos, spans) {
|
|
529
|
+
let idx = line.indexOf(marker, pos);
|
|
530
|
+
for (const span of spans) {
|
|
531
|
+
if (idx === -1 || idx < span.start) break;
|
|
532
|
+
if (idx < span.end) idx = line.indexOf(marker, span.end);
|
|
533
|
+
}
|
|
534
|
+
return idx;
|
|
535
|
+
}
|
|
448
536
|
function activeLeaf(grammar, state) {
|
|
449
537
|
if (state.region) return state.region.grammar;
|
|
450
538
|
return grammar.regions ? grammar.default : grammar;
|
|
@@ -468,7 +556,7 @@ function* regionEvents(line, pos, grammar, state) {
|
|
|
468
556
|
}
|
|
469
557
|
}
|
|
470
558
|
}
|
|
471
|
-
function nextEvent(line, pos, grammar, state) {
|
|
559
|
+
function nextEvent(line, pos, grammar, state, spans) {
|
|
472
560
|
const leaf = activeLeaf(grammar, state);
|
|
473
561
|
let best = null;
|
|
474
562
|
const consider = (idx, event) => {
|
|
@@ -478,10 +566,10 @@ function nextEvent(line, pos, grammar, state) {
|
|
|
478
566
|
}
|
|
479
567
|
};
|
|
480
568
|
for (const marker of leaf.line) {
|
|
481
|
-
consider(line
|
|
569
|
+
consider(markerIndex(line, marker, pos, spans), { kind: "line", len: marker.length });
|
|
482
570
|
}
|
|
483
571
|
for (const [open, close, nestable] of leaf.block) {
|
|
484
|
-
consider(line
|
|
572
|
+
consider(markerIndex(line, open, pos, spans), {
|
|
485
573
|
kind: "block",
|
|
486
574
|
len: open.length,
|
|
487
575
|
open,
|
|
@@ -536,6 +624,7 @@ function consumeLine(line, pos, state, exit) {
|
|
|
536
624
|
return { text: line.slice(pos) + " ", pos: line.length, done: true };
|
|
537
625
|
}
|
|
538
626
|
function commentText(line, state, grammar) {
|
|
627
|
+
const spans = urlSpans(line);
|
|
539
628
|
let comment = "";
|
|
540
629
|
let pos = 0;
|
|
541
630
|
while (pos < line.length) {
|
|
@@ -546,7 +635,7 @@ function commentText(line, state, grammar) {
|
|
|
546
635
|
pos = consumed.pos;
|
|
547
636
|
continue;
|
|
548
637
|
}
|
|
549
|
-
const event = nextEvent(line, pos, grammar, state);
|
|
638
|
+
const event = nextEvent(line, pos, grammar, state, spans);
|
|
550
639
|
if (!event) break;
|
|
551
640
|
pos = event.idx + event.len;
|
|
552
641
|
if (event.kind === "line") {
|
|
@@ -581,7 +670,6 @@ function collectTags(comment, file, line, state, items, problems) {
|
|
|
581
670
|
anchor.needs.push(id);
|
|
582
671
|
} else {
|
|
583
672
|
problems.push({
|
|
584
|
-
severity: "error",
|
|
585
673
|
file,
|
|
586
674
|
line,
|
|
587
675
|
message: `need tag [${source} >> ${id}] has no preceding item tag [${source}] in this file`
|
|
@@ -591,7 +679,6 @@ function collectTags(comment, file, line, state, items, problems) {
|
|
|
591
679
|
state.lastItem.needs.push(id);
|
|
592
680
|
} else {
|
|
593
681
|
problems.push({
|
|
594
|
-
severity: "error",
|
|
595
682
|
file,
|
|
596
683
|
line,
|
|
597
684
|
message: `need tag [>>${id}] has no preceding item tag in this file`
|
|
@@ -656,7 +743,7 @@ function dropCyclicForwards(forwardTargets, declarationBySource, problems) {
|
|
|
656
743
|
const chain = [...cycle, current].join(" --> ");
|
|
657
744
|
for (const id of cycle) {
|
|
658
745
|
const declaration = declarationBySource.get(id);
|
|
659
|
-
problems.push({
|
|
746
|
+
problems.push({ file: declaration.file, line: declaration.line, message: `cyclic forwarding: ${chain}` });
|
|
660
747
|
forwardTargets.delete(id);
|
|
661
748
|
}
|
|
662
749
|
}
|
|
@@ -675,7 +762,6 @@ function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
|
|
|
675
762
|
if (!sources) {
|
|
676
763
|
for (const forward of group)
|
|
677
764
|
problems.push({
|
|
678
|
-
severity: "error",
|
|
679
765
|
file: forward.file,
|
|
680
766
|
line: forward.line,
|
|
681
767
|
message: `forwarding from ${from}, which does not exist${revHint(from)}`
|
|
@@ -769,7 +855,6 @@ function makeStyler() {
|
|
|
769
855
|
const wrap = (code) => (text) => on ? `\x1B[${code}m${text}\x1B[0m` : text;
|
|
770
856
|
return {
|
|
771
857
|
red: wrap("31"),
|
|
772
|
-
brightRed: wrap("91"),
|
|
773
858
|
green: wrap("32"),
|
|
774
859
|
yellow: wrap("33"),
|
|
775
860
|
cyan: wrap("36"),
|
|
@@ -864,7 +949,7 @@ function renderDefective(defective, out, style, dimLocation) {
|
|
|
864
949
|
out.push("");
|
|
865
950
|
}
|
|
866
951
|
}
|
|
867
|
-
function renderSummary(items, defective,
|
|
952
|
+
function renderSummary(items, defective, problems, out, style) {
|
|
868
953
|
const okCount = items.length - defective.length;
|
|
869
954
|
const shallowCount = items.filter((item) => item.defects.length === 0 && !item.deepCovered).length;
|
|
870
955
|
const markdownCount = items.filter((item) => item.origin === "markdown").length;
|
|
@@ -876,30 +961,24 @@ function renderSummary(items, defective, errorCount, warningCount, out, style) {
|
|
|
876
961
|
` defective ${defective.length ? style.red(String(defective.length)) : "0"}`
|
|
877
962
|
);
|
|
878
963
|
if (shallowCount) out.push(" " + style.dim(`of the ok items, ${shallowCount} are only shallow-covered (an item further down the tracing chain is defective)`));
|
|
879
|
-
if (
|
|
880
|
-
if (warningCount) out.push(` warnings ${style.yellow(String(warningCount))}`);
|
|
964
|
+
if (problems.length) out.push(` problems ${style.yellow(String(problems.length))}`);
|
|
881
965
|
out.push("");
|
|
882
966
|
}
|
|
883
|
-
function problemMark(problem, style) {
|
|
884
|
-
return problem.severity === "warning" ? style.yellow("\u26A0") : style.brightRed("\u25B2");
|
|
885
|
-
}
|
|
886
967
|
function report(items, problems, cwd, opts = {}) {
|
|
887
968
|
const { verbose = false } = opts;
|
|
888
969
|
const style = makeStyler();
|
|
889
970
|
const relativePath = (file) => path3.relative(cwd, file) || file;
|
|
890
971
|
const dimLocation = (file, line) => style.dim(`${relativePath(file)}:${line}`);
|
|
891
972
|
const defective = items.filter((item) => item.defects.length > 0);
|
|
892
|
-
const warningCount = problems.filter((problem) => problem.severity === "warning").length;
|
|
893
|
-
const errorCount = problems.length - warningCount;
|
|
894
973
|
const out = [];
|
|
895
974
|
if (verbose) renderVerbose(items, out, style, dimLocation);
|
|
896
975
|
else renderDefective(defective, out, style, dimLocation);
|
|
897
976
|
for (const problem of problems) {
|
|
898
|
-
out.push(`${
|
|
977
|
+
out.push(`${style.yellow("\u26A0")} ${problem.message} ${dimLocation(problem.file, problem.line)}`);
|
|
899
978
|
}
|
|
900
979
|
if (problems.length) out.push("");
|
|
901
|
-
renderSummary(items, defective,
|
|
902
|
-
const clean = defective.length === 0 &&
|
|
980
|
+
renderSummary(items, defective, problems, out, style);
|
|
981
|
+
const clean = defective.length === 0 && problems.length === 0;
|
|
903
982
|
out.push(clean ? style.green(style.bold("ok")) : style.red(style.bold("not ok")));
|
|
904
983
|
console.log(out.join("\n"));
|
|
905
984
|
return clean;
|
|
@@ -922,8 +1001,7 @@ Options:
|
|
|
922
1001
|
|
|
923
1002
|
Long options also accept "="-attached values, e.g. --tags=a,b.
|
|
924
1003
|
|
|
925
|
-
Exit codes: 0 clean, 1 defects or
|
|
926
|
-
(warning problems alone leave the run clean)`;
|
|
1004
|
+
Exit codes: 0 clean, 1 defects or problems found, 2 usage error`;
|
|
927
1005
|
function packageVersion() {
|
|
928
1006
|
const pkg = new URL("../package.json", import.meta.url);
|
|
929
1007
|
return JSON.parse(readFileSync(pkg, "utf8")).version;
|