flashtrace 0.12.0 → 0.12.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 +12 -0
- package/dist/flashtrace.mjs +202 -169
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -56,6 +56,18 @@
|
|
|
56
56
|
<a href="https://sonarcloud.io/component_measures?metric=vulnerabilities&id=flashtrace_flashtrace">
|
|
57
57
|
<img src="https://sonarcloud.io/api/project_badges/measure?project=flashtrace_flashtrace&metric=vulnerabilities" alt="SonarCloud amount of vulnerabilities." />
|
|
58
58
|
</a>
|
|
59
|
+
<!--
|
|
60
|
+
The coverage and tests badges read from the orphan `badges` branch,
|
|
61
|
+
which CI rewrites on every push to main. They therefore always show
|
|
62
|
+
main's last published numbers - never the numbers of the branch this
|
|
63
|
+
README is viewed on.
|
|
64
|
+
-->
|
|
65
|
+
<a href="https://github.com/flashtrace/flashtrace/actions/workflows/ci.yml">
|
|
66
|
+
<img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fflashtrace%2Fflashtrace%2Fbadges%2Fcoverage.json" alt="Line coverage of src/, measured by node --test." />
|
|
67
|
+
</a>
|
|
68
|
+
<a href="https://github.com/flashtrace/flashtrace/actions/workflows/ci.yml">
|
|
69
|
+
<img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fflashtrace%2Fflashtrace%2Fbadges%2Ftests.json" alt="Number of tests run by node --test." />
|
|
70
|
+
</a>
|
|
59
71
|
</p>
|
|
60
72
|
|
|
61
73
|
## Getting Started
|
package/dist/flashtrace.mjs
CHANGED
|
@@ -177,70 +177,6 @@ var BY_EXT = {
|
|
|
177
177
|
var CODE_EXT = new Set(Object.keys(BY_EXT));
|
|
178
178
|
var grammarFor = (ext) => BY_EXT[ext] ?? null;
|
|
179
179
|
|
|
180
|
-
// src/files.mjs
|
|
181
|
-
var SPEC_EXT = /* @__PURE__ */ new Set([".md", ".markdown"]);
|
|
182
|
-
var GIT_LOCATIONS = process.platform === "win32" ? [
|
|
183
|
-
String.raw`C:\Program Files\Git\cmd\git.exe`,
|
|
184
|
-
String.raw`C:\Program Files (x86)\Git\cmd\git.exe`
|
|
185
|
-
] : ["/usr/bin/git", "/bin/git"];
|
|
186
|
-
var gitBin;
|
|
187
|
-
function findGit() {
|
|
188
|
-
if (gitBin === void 0) {
|
|
189
|
-
gitBin = GIT_LOCATIONS.find((p) => existsSync(p)) ?? null;
|
|
190
|
-
}
|
|
191
|
-
return gitBin;
|
|
192
|
-
}
|
|
193
|
-
function compareStrings(a, b) {
|
|
194
|
-
if (a < b) return -1;
|
|
195
|
-
if (a > b) return 1;
|
|
196
|
-
return 0;
|
|
197
|
-
}
|
|
198
|
-
async function walk(dir, out) {
|
|
199
|
-
let entries;
|
|
200
|
-
try {
|
|
201
|
-
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
202
|
-
} catch {
|
|
203
|
-
return out;
|
|
204
|
-
}
|
|
205
|
-
for (const entry of entries) {
|
|
206
|
-
if (entry.name === ".git" || entry.name === "node_modules") continue;
|
|
207
|
-
const entryPath = path.join(dir, entry.name);
|
|
208
|
-
if (entry.isDirectory()) await walk(entryPath, out);
|
|
209
|
-
else if (entry.isFile()) out.push(entryPath);
|
|
210
|
-
}
|
|
211
|
-
return out;
|
|
212
|
-
}
|
|
213
|
-
async function collectFiles(dirs) {
|
|
214
|
-
const files = /* @__PURE__ */ new Set();
|
|
215
|
-
for (const dir of dirs) {
|
|
216
|
-
const abs = path.resolve(dir);
|
|
217
|
-
const stats = await fs.stat(abs).catch(() => null);
|
|
218
|
-
if (!stats) throw new UsageError(`input path does not exist: ${dir}`);
|
|
219
|
-
if (stats.isFile()) {
|
|
220
|
-
files.add(abs);
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
let list = null;
|
|
224
|
-
const git = findGit();
|
|
225
|
-
try {
|
|
226
|
-
if (!git) throw new Error("git not found");
|
|
227
|
-
const out = execFileSync(
|
|
228
|
-
git,
|
|
229
|
-
["-C", abs, "ls-files", "-z", "--cached", "--others", "--exclude-standard"],
|
|
230
|
-
{ encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }
|
|
231
|
-
);
|
|
232
|
-
list = out.split("\0").filter(Boolean).map((f) => path.join(abs, f));
|
|
233
|
-
} catch {
|
|
234
|
-
list = await walk(abs, []);
|
|
235
|
-
}
|
|
236
|
-
for (const file of list) files.add(file);
|
|
237
|
-
}
|
|
238
|
-
return [...files].filter((file) => {
|
|
239
|
-
const ext = path.extname(file).toLowerCase();
|
|
240
|
-
return SPEC_EXT.has(ext) || CODE_EXT.has(ext);
|
|
241
|
-
}).sort(compareStrings);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
180
|
// src/ids.mjs
|
|
245
181
|
var SEGMENT_SRC = "[A-Za-z][A-Za-z0-9_.-]*";
|
|
246
182
|
var REV_SRC = String.raw`\d+(?:\.\d+){0,2}`;
|
|
@@ -326,12 +262,102 @@ function newItem(id, origin, file, line, character) {
|
|
|
326
262
|
};
|
|
327
263
|
}
|
|
328
264
|
|
|
265
|
+
// src/defects.mjs
|
|
266
|
+
var DEFECT_KINDS = Object.freeze([
|
|
267
|
+
"invalid-reference",
|
|
268
|
+
"uncovered-need",
|
|
269
|
+
"uncovered-forward",
|
|
270
|
+
"orphaned-cover",
|
|
271
|
+
"unwanted-cover",
|
|
272
|
+
"unwanted-item",
|
|
273
|
+
"duplicate-id",
|
|
274
|
+
"duplicate-forwarding",
|
|
275
|
+
"cyclic-forwarding"
|
|
276
|
+
]);
|
|
277
|
+
var invalidReference = (value, source, { file, line, character }) => ({
|
|
278
|
+
kind: "invalid-reference",
|
|
279
|
+
ref: value,
|
|
280
|
+
file,
|
|
281
|
+
line,
|
|
282
|
+
character,
|
|
283
|
+
message: `invalid: "${value}" in ${source} is not a valid ID and is ignored`
|
|
284
|
+
});
|
|
285
|
+
var uncoveredNeed = (need) => ({
|
|
286
|
+
kind: "uncovered-need",
|
|
287
|
+
ref: need,
|
|
288
|
+
message: `uncovered: needs ${need}, which does not exist`
|
|
289
|
+
});
|
|
290
|
+
var uncoveredForward = (target) => ({
|
|
291
|
+
kind: "uncovered-forward",
|
|
292
|
+
ref: target,
|
|
293
|
+
message: `uncovered: forwards to ${target}, which does not exist`
|
|
294
|
+
});
|
|
295
|
+
var orphanedCover = (coverId) => ({
|
|
296
|
+
kind: "orphaned-cover",
|
|
297
|
+
ref: coverId,
|
|
298
|
+
message: `orphaned: covers ${coverId}, which does not exist`
|
|
299
|
+
});
|
|
300
|
+
var unwantedCover = (coverId, itemId) => ({
|
|
301
|
+
kind: "unwanted-cover",
|
|
302
|
+
ref: coverId,
|
|
303
|
+
message: `unwanted: covers ${coverId}, but ${coverId} does not need ${itemId}`
|
|
304
|
+
});
|
|
305
|
+
var unwantedItem = (itemId) => ({
|
|
306
|
+
kind: "unwanted-item",
|
|
307
|
+
ref: itemId,
|
|
308
|
+
message: `unwanted: no item needs ${itemId}`
|
|
309
|
+
});
|
|
310
|
+
var duplicateId = (id, count) => ({
|
|
311
|
+
kind: "duplicate-id",
|
|
312
|
+
ref: id,
|
|
313
|
+
message: `duplicate: ID ${id} is defined ${count} times`
|
|
314
|
+
});
|
|
315
|
+
var duplicateForwarding = (from, count, { file, line, character }) => ({
|
|
316
|
+
kind: "duplicate-forwarding",
|
|
317
|
+
ref: from,
|
|
318
|
+
file,
|
|
319
|
+
line,
|
|
320
|
+
character,
|
|
321
|
+
message: `duplicate: forwarding for ${from} is declared ${count} times`
|
|
322
|
+
});
|
|
323
|
+
var cyclicForwarding = (target, chain, { file, line, character }) => ({
|
|
324
|
+
kind: "cyclic-forwarding",
|
|
325
|
+
ref: target,
|
|
326
|
+
file,
|
|
327
|
+
line,
|
|
328
|
+
character,
|
|
329
|
+
message: `cyclic: forwards to ${target}, closing the cycle ${chain}, so the forwarding has no effect`
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// src/spec-items.mjs
|
|
333
|
+
var KEYWORDS = ["Needs", "Covers", "Tags"];
|
|
334
|
+
var isKeyword = (text) => KEYWORDS.includes(text);
|
|
335
|
+
var parseVerbatimKeyword = (raw) => raw;
|
|
336
|
+
var KEYWORD_HANDLERS = {
|
|
337
|
+
Needs: { target: "needs", parse: parseNeedEntry },
|
|
338
|
+
Covers: { target: "covers", parse: parseCoverEntry },
|
|
339
|
+
Tags: { target: "tags", parse: parseVerbatimKeyword }
|
|
340
|
+
};
|
|
341
|
+
function applyKeyword(item, keyword, entries, file, source) {
|
|
342
|
+
const handler = KEYWORD_HANDLERS[keyword];
|
|
343
|
+
if (!handler) throw new Error(`applyKeyword: no handling for keyword "${keyword}"`);
|
|
344
|
+
const { target, parse } = handler;
|
|
345
|
+
for (const entry of entries) {
|
|
346
|
+
const value = parse(entry.value, item.id);
|
|
347
|
+
if (value) item[target].push(value);
|
|
348
|
+
else
|
|
349
|
+
item.defects.push(
|
|
350
|
+
invalidReference(entry.value, source, { file, line: entry.line, character: entry.character })
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
329
355
|
// src/parse-markdown.mjs
|
|
330
356
|
var DEFINITION_RE = new RegExp(String.raw`^\s*\`${ID_SRC}\`\s*$`);
|
|
331
357
|
var HEADING_RE = /^(#{1,6})\s+(\S(?:.*\S)?)\s*$/;
|
|
332
358
|
var SETEXT_UNDERLINE_RE = /^ {0,3}(?:=+|-+)[ \t]*$/;
|
|
333
359
|
var THEMATIC_BREAK_RE = /^ {0,3}-{3,}[ \t]*$/;
|
|
334
|
-
var KEYWORD_RE =
|
|
360
|
+
var KEYWORD_RE = new RegExp(String.raw`^(${KEYWORDS.join("|")}):\s*((?:\S.*)?)$`);
|
|
335
361
|
var BULLET_RE = /^\s*[-*+]\s+(\S(?:.*\S)?)\s*$/;
|
|
336
362
|
var DELIMITER_CELL_RE = /^:?-+:?$/;
|
|
337
363
|
var FORWARD_LINE_RE = new RegExp(String.raw`^\s*(\`?)${FORWARD_SRC}\1\s*$`);
|
|
@@ -444,7 +470,6 @@ function tableStartsAt(lines, j) {
|
|
|
444
470
|
}
|
|
445
471
|
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));
|
|
446
472
|
var rowCellsInTable = (line) => rowCells(line) ?? [line.trim()];
|
|
447
|
-
var isKeywordCell = (cell) => cell === "Needs" || cell === "Covers" || cell === "Tags";
|
|
448
473
|
function scanTables(lines, file, problems) {
|
|
449
474
|
const inTable = new Array(lines.length).fill(false);
|
|
450
475
|
let j = 0;
|
|
@@ -455,7 +480,7 @@ function scanTables(lines, file, problems) {
|
|
|
455
480
|
}
|
|
456
481
|
const keywordColumns = /* @__PURE__ */ new Set();
|
|
457
482
|
rowCells(lines[j]).forEach((cell, col) => {
|
|
458
|
-
if (
|
|
483
|
+
if (isKeyword(cell)) keywordColumns.add(col);
|
|
459
484
|
});
|
|
460
485
|
const start = j;
|
|
461
486
|
let end = j + 1;
|
|
@@ -479,11 +504,11 @@ function scanTables(lines, file, problems) {
|
|
|
479
504
|
}
|
|
480
505
|
return inTable;
|
|
481
506
|
}
|
|
482
|
-
function takeKeywordTable(lines, inTable, j, item, file
|
|
507
|
+
function takeKeywordTable(lines, inTable, j, item, file) {
|
|
483
508
|
if (!inTable[j] || j > 0 && inTable[j - 1]) return null;
|
|
484
509
|
const columns = [];
|
|
485
510
|
rowCells(lines[j]).forEach((cell, col) => {
|
|
486
|
-
if (
|
|
511
|
+
if (isKeyword(cell)) columns.push([col, cell]);
|
|
487
512
|
});
|
|
488
513
|
if (columns.length === 0) return null;
|
|
489
514
|
j++;
|
|
@@ -498,33 +523,13 @@ function takeKeywordTable(lines, inTable, j, item, file, problems) {
|
|
|
498
523
|
keyword,
|
|
499
524
|
[{ value: cells[col], line: j + 1, character: cellColumns[col] }],
|
|
500
525
|
file,
|
|
501
|
-
problems,
|
|
502
526
|
`the ${keyword} column of ${item.id}`
|
|
503
527
|
);
|
|
504
528
|
}
|
|
505
529
|
}
|
|
506
530
|
return j;
|
|
507
531
|
}
|
|
508
|
-
function
|
|
509
|
-
if (keyword === "Tags") {
|
|
510
|
-
for (const entry of entries) item.tags.push(entry.value);
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
|
-
const target = keyword === "Needs" ? "needs" : "covers";
|
|
514
|
-
const parse = keyword === "Needs" ? parseNeedEntry : parseCoverEntry;
|
|
515
|
-
for (const entry of entries) {
|
|
516
|
-
const id = parse(entry.value, item.id);
|
|
517
|
-
if (id) item[target].push(id);
|
|
518
|
-
else
|
|
519
|
-
problems.push({
|
|
520
|
-
file,
|
|
521
|
-
line: entry.line,
|
|
522
|
-
character: entry.character,
|
|
523
|
-
message: `invalid ID "${entry.value}" in ${source}`
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
function parseItemBody(lines, boundary, start, item, file, problems, forwards) {
|
|
532
|
+
function parseItemBody(lines, boundary, start, item, file, forwards) {
|
|
528
533
|
const { inTable, opensHeading } = boundary;
|
|
529
534
|
let j = start;
|
|
530
535
|
let descriptionDone = false;
|
|
@@ -535,7 +540,7 @@ function parseItemBody(lines, boundary, start, item, file, problems, forwards) {
|
|
|
535
540
|
continue;
|
|
536
541
|
}
|
|
537
542
|
const keywordMatch = line.match(KEYWORD_RE);
|
|
538
|
-
const tableEnd = keywordMatch ? null : takeKeywordTable(lines, inTable, j, item, file
|
|
543
|
+
const tableEnd = keywordMatch ? null : takeKeywordTable(lines, inTable, j, item, file);
|
|
539
544
|
if (keywordMatch) {
|
|
540
545
|
descriptionDone = true;
|
|
541
546
|
const collected = keywordEntries(lines, j, keywordMatch[2]);
|
|
@@ -544,8 +549,7 @@ function parseItemBody(lines, boundary, start, item, file, problems, forwards) {
|
|
|
544
549
|
keywordMatch[1],
|
|
545
550
|
collected.entries,
|
|
546
551
|
file,
|
|
547
|
-
|
|
548
|
-
`${keywordMatch[1]}: list of ${item.id}`
|
|
552
|
+
`the ${keywordMatch[1]} list of ${item.id}`
|
|
549
553
|
);
|
|
550
554
|
j = collected.j;
|
|
551
555
|
} else if (tableEnd !== null) {
|
|
@@ -590,12 +594,83 @@ function parseMarkdown(file, text, problems, forwards = []) {
|
|
|
590
594
|
}
|
|
591
595
|
const item = newItem(makeId(definition[1], definition[2], definition[3], definition[4]), "spec", file, i + 1, firstNonBlankColumn(lines[i]));
|
|
592
596
|
item.title = titleAbove(lines, inTable, i);
|
|
593
|
-
i = parseItemBody(lines, boundary, i + 1, item, file,
|
|
597
|
+
i = parseItemBody(lines, boundary, i + 1, item, file, forwards);
|
|
594
598
|
items.push(item);
|
|
595
599
|
}
|
|
596
600
|
return items;
|
|
597
601
|
}
|
|
598
602
|
|
|
603
|
+
// src/parse-spec.mjs
|
|
604
|
+
var BY_EXT2 = {
|
|
605
|
+
".md": parseMarkdown,
|
|
606
|
+
".markdown": parseMarkdown
|
|
607
|
+
};
|
|
608
|
+
var SPEC_EXT = new Set(Object.keys(BY_EXT2));
|
|
609
|
+
var specParserFor = (ext) => BY_EXT2[ext] ?? null;
|
|
610
|
+
|
|
611
|
+
// src/files.mjs
|
|
612
|
+
var GIT_LOCATIONS = process.platform === "win32" ? [
|
|
613
|
+
String.raw`C:\Program Files\Git\cmd\git.exe`,
|
|
614
|
+
String.raw`C:\Program Files (x86)\Git\cmd\git.exe`
|
|
615
|
+
] : ["/usr/bin/git", "/bin/git"];
|
|
616
|
+
var gitBin;
|
|
617
|
+
function findGit() {
|
|
618
|
+
if (gitBin === void 0) {
|
|
619
|
+
gitBin = GIT_LOCATIONS.find((p) => existsSync(p)) ?? null;
|
|
620
|
+
}
|
|
621
|
+
return gitBin;
|
|
622
|
+
}
|
|
623
|
+
function compareStrings(a, b) {
|
|
624
|
+
if (a < b) return -1;
|
|
625
|
+
if (a > b) return 1;
|
|
626
|
+
return 0;
|
|
627
|
+
}
|
|
628
|
+
async function walk(dir, out) {
|
|
629
|
+
let entries;
|
|
630
|
+
try {
|
|
631
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
632
|
+
} catch {
|
|
633
|
+
return out;
|
|
634
|
+
}
|
|
635
|
+
for (const entry of entries) {
|
|
636
|
+
if (entry.name === ".git" || entry.name === "node_modules") continue;
|
|
637
|
+
const entryPath = path.join(dir, entry.name);
|
|
638
|
+
if (entry.isDirectory()) await walk(entryPath, out);
|
|
639
|
+
else if (entry.isFile()) out.push(entryPath);
|
|
640
|
+
}
|
|
641
|
+
return out;
|
|
642
|
+
}
|
|
643
|
+
async function collectFiles(dirs) {
|
|
644
|
+
const files = /* @__PURE__ */ new Set();
|
|
645
|
+
for (const dir of dirs) {
|
|
646
|
+
const abs = path.resolve(dir);
|
|
647
|
+
const stats = await fs.stat(abs).catch(() => null);
|
|
648
|
+
if (!stats) throw new UsageError(`input path does not exist: ${dir}`);
|
|
649
|
+
if (stats.isFile()) {
|
|
650
|
+
files.add(abs);
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
let list = null;
|
|
654
|
+
const git = findGit();
|
|
655
|
+
try {
|
|
656
|
+
if (!git) throw new Error("git not found");
|
|
657
|
+
const out = execFileSync(
|
|
658
|
+
git,
|
|
659
|
+
["-C", abs, "ls-files", "-z", "--cached", "--others", "--exclude-standard"],
|
|
660
|
+
{ encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }
|
|
661
|
+
);
|
|
662
|
+
list = out.split("\0").filter(Boolean).map((f) => path.join(abs, f));
|
|
663
|
+
} catch {
|
|
664
|
+
list = await walk(abs, []);
|
|
665
|
+
}
|
|
666
|
+
for (const file of list) files.add(file);
|
|
667
|
+
}
|
|
668
|
+
return [...files].filter((file) => {
|
|
669
|
+
const ext = path.extname(file).toLowerCase();
|
|
670
|
+
return SPEC_EXT.has(ext) || CODE_EXT.has(ext);
|
|
671
|
+
}).sort(compareStrings);
|
|
672
|
+
}
|
|
673
|
+
|
|
599
674
|
// src/parse-code.mjs
|
|
600
675
|
import path2 from "node:path";
|
|
601
676
|
var TAG_RE = new RegExp(
|
|
@@ -783,52 +858,6 @@ function parseCode(file, text, problems, forwards = []) {
|
|
|
783
858
|
return items;
|
|
784
859
|
}
|
|
785
860
|
|
|
786
|
-
// src/defects.mjs
|
|
787
|
-
var DEFECT_KINDS = Object.freeze([
|
|
788
|
-
"uncovered-need",
|
|
789
|
-
"uncovered-forward",
|
|
790
|
-
"orphaned-cover",
|
|
791
|
-
"unwanted-cover",
|
|
792
|
-
"unwanted-item",
|
|
793
|
-
"duplicate-id",
|
|
794
|
-
"duplicate-forwarding"
|
|
795
|
-
]);
|
|
796
|
-
var uncoveredNeed = (need) => ({
|
|
797
|
-
kind: "uncovered-need",
|
|
798
|
-
ref: need,
|
|
799
|
-
message: `uncovered: needs ${need}, which does not exist`
|
|
800
|
-
});
|
|
801
|
-
var uncoveredForward = (target) => ({
|
|
802
|
-
kind: "uncovered-forward",
|
|
803
|
-
ref: target,
|
|
804
|
-
message: `uncovered: forwards to ${target}, which does not exist`
|
|
805
|
-
});
|
|
806
|
-
var orphanedCover = (coverId) => ({
|
|
807
|
-
kind: "orphaned-cover",
|
|
808
|
-
ref: coverId,
|
|
809
|
-
message: `orphaned: covers ${coverId}, which does not exist`
|
|
810
|
-
});
|
|
811
|
-
var unwantedCover = (coverId, itemId) => ({
|
|
812
|
-
kind: "unwanted-cover",
|
|
813
|
-
ref: coverId,
|
|
814
|
-
message: `unwanted: covers ${coverId}, but ${coverId} does not need ${itemId}`
|
|
815
|
-
});
|
|
816
|
-
var unwantedItem = (itemId) => ({
|
|
817
|
-
kind: "unwanted-item",
|
|
818
|
-
ref: itemId,
|
|
819
|
-
message: `unwanted: no item needs ${itemId}`
|
|
820
|
-
});
|
|
821
|
-
var duplicateId = (id, count) => ({
|
|
822
|
-
kind: "duplicate-id",
|
|
823
|
-
ref: id,
|
|
824
|
-
message: `duplicate: ID ${id} is defined ${count} times`
|
|
825
|
-
});
|
|
826
|
-
var duplicateForwarding = (from, count) => ({
|
|
827
|
-
kind: "duplicate-forwarding",
|
|
828
|
-
ref: from,
|
|
829
|
-
message: `duplicate: forwarding for ${from} is declared ${count} times`
|
|
830
|
-
});
|
|
831
|
-
|
|
832
861
|
// src/analyze.mjs
|
|
833
862
|
function checkItemReferences(item, byId, matchesOf, isNeeded, withRevisions, forwardTargets) {
|
|
834
863
|
const forwardTarget = forwardTargets.get(item.canonicalId);
|
|
@@ -854,7 +883,16 @@ function checkItemReferences(item, byId, matchesOf, isNeeded, withRevisions, for
|
|
|
854
883
|
}
|
|
855
884
|
}
|
|
856
885
|
var displayedDuplicateId = (writtenIds, canonical) => writtenIds.every((id) => id === writtenIds[0]) ? writtenIds[0] : canonical;
|
|
857
|
-
function
|
|
886
|
+
function voidForwardingCycle(cycle, chain, forwardTargets, declarationBySource, byId) {
|
|
887
|
+
for (const id of cycle) {
|
|
888
|
+
const declaration = declarationBySource.get(id);
|
|
889
|
+
declaration.effective = false;
|
|
890
|
+
declaration.voidedBy = "cycle";
|
|
891
|
+
for (const item of byId.get(id)) item.defects.push(cyclicForwarding(declaration.to, chain, declaration));
|
|
892
|
+
forwardTargets.delete(id);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
function dropCyclicForwards(forwardTargets, declarationBySource, byId) {
|
|
858
896
|
const done = /* @__PURE__ */ new Set();
|
|
859
897
|
for (const start of forwardTargets.keys()) {
|
|
860
898
|
if (done.has(start)) continue;
|
|
@@ -869,18 +907,7 @@ function dropCyclicForwards(forwardTargets, declarationBySource, problems) {
|
|
|
869
907
|
if (seen.has(current)) {
|
|
870
908
|
const cycle = path6.slice(seen.get(current));
|
|
871
909
|
const chain = [...cycle, current].map((id) => declarationBySource.get(id).from).join(" --> ");
|
|
872
|
-
|
|
873
|
-
const declaration = declarationBySource.get(id);
|
|
874
|
-
declaration.effective = false;
|
|
875
|
-
declaration.voidedBy = "cycle";
|
|
876
|
-
problems.push({
|
|
877
|
-
file: declaration.file,
|
|
878
|
-
line: declaration.line,
|
|
879
|
-
character: declaration.character,
|
|
880
|
-
message: `cyclic forwarding: ${chain}`
|
|
881
|
-
});
|
|
882
|
-
forwardTargets.delete(id);
|
|
883
|
-
}
|
|
910
|
+
voidForwardingCycle(cycle, chain, forwardTargets, declarationBySource, byId);
|
|
884
911
|
}
|
|
885
912
|
for (const id of path6) done.add(id);
|
|
886
913
|
}
|
|
@@ -910,7 +937,7 @@ function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
|
|
|
910
937
|
}
|
|
911
938
|
if (group.length > 1) {
|
|
912
939
|
const shown = displayedDuplicateId(group.map((forward) => forward.from), from);
|
|
913
|
-
for (const item of sources) item.defects.push(duplicateForwarding(shown, group.length));
|
|
940
|
+
for (const item of sources) item.defects.push(duplicateForwarding(shown, group.length, group[0]));
|
|
914
941
|
}
|
|
915
942
|
group[0].effective = true;
|
|
916
943
|
for (let i = 1; i < group.length; i++) {
|
|
@@ -920,7 +947,7 @@ function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
|
|
|
920
947
|
forwardTargets.set(from, group[0].to);
|
|
921
948
|
declarationBySource.set(from, group[0]);
|
|
922
949
|
}
|
|
923
|
-
dropCyclicForwards(forwardTargets, declarationBySource,
|
|
950
|
+
dropCyclicForwards(forwardTargets, declarationBySource, byId);
|
|
924
951
|
for (const to of forwardTargets.values()) neededIds.add(canonicalId(to));
|
|
925
952
|
return forwardTargets;
|
|
926
953
|
}
|
|
@@ -1102,6 +1129,12 @@ function coverEdges(item, byId, style, dimLocation) {
|
|
|
1102
1129
|
}
|
|
1103
1130
|
return lines;
|
|
1104
1131
|
}
|
|
1132
|
+
function defectLines(item, style, dimLocation) {
|
|
1133
|
+
return item.defects.map((defect) => {
|
|
1134
|
+
const location = defect.file ? ` ${dimLocation(defect.file, defect.line)}` : "";
|
|
1135
|
+
return ` ${style.red("\u2022")} ${defect.message}${location}`;
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1105
1138
|
function edgeLines(item, byId, matchesOf, wantedBy, style, dimLocation) {
|
|
1106
1139
|
const lines = [];
|
|
1107
1140
|
if (item.forwardsTo !== null) lines.push(forwardEdge(item, byId, style, dimLocation));
|
|
@@ -1122,9 +1155,9 @@ function renderVerbose(items, out, style, dimLocation) {
|
|
|
1122
1155
|
const title = item.title ? " " + style.dim(`"${item.title}"`) : "";
|
|
1123
1156
|
out.push(
|
|
1124
1157
|
`${mark} ${style.bold(item.id)}${title} ${dimLocation(item.file, item.line)} ${tag}`,
|
|
1125
|
-
...edgeLines(item, byId, matchesOf, wantedBy, style, dimLocation)
|
|
1158
|
+
...edgeLines(item, byId, matchesOf, wantedBy, style, dimLocation),
|
|
1159
|
+
...defectLines(item, style, dimLocation)
|
|
1126
1160
|
);
|
|
1127
|
-
for (const defect of item.defects) out.push(` ${style.red("\u2022")} ${defect.message}`);
|
|
1128
1161
|
}
|
|
1129
1162
|
if (sorted.length) out.push("");
|
|
1130
1163
|
}
|
|
@@ -1132,10 +1165,10 @@ function renderDefective(defective, out, style, dimLocation) {
|
|
|
1132
1165
|
for (const item of defective) {
|
|
1133
1166
|
const title = item.title ? " " + style.dim(`"${item.title}"`) : "";
|
|
1134
1167
|
out.push(
|
|
1135
|
-
`${styledStatus(item, style).mark} ${style.bold(item.id)}${title} ${dimLocation(item.file, item.line)}
|
|
1168
|
+
`${styledStatus(item, style).mark} ${style.bold(item.id)}${title} ${dimLocation(item.file, item.line)}`,
|
|
1169
|
+
...defectLines(item, style, dimLocation),
|
|
1170
|
+
""
|
|
1136
1171
|
);
|
|
1137
|
-
for (const defect of item.defects) out.push(` ${style.red("\u2022")} ${defect.message}`);
|
|
1138
|
-
out.push("");
|
|
1139
1172
|
}
|
|
1140
1173
|
}
|
|
1141
1174
|
function renderSummary(summary, out, style) {
|
|
@@ -1192,12 +1225,6 @@ function buildForwardedFrom(items, byId) {
|
|
|
1192
1225
|
}
|
|
1193
1226
|
return forwardedFrom;
|
|
1194
1227
|
}
|
|
1195
|
-
function defectDocument(defect) {
|
|
1196
|
-
const out = { kind: defect.kind, ref: defect.ref };
|
|
1197
|
-
if (defect.existingRevisions) out.existingRevisions = defect.existingRevisions;
|
|
1198
|
-
out.message = defect.message;
|
|
1199
|
-
return out;
|
|
1200
|
-
}
|
|
1201
1228
|
function buildReportDocument(items, forwards, problems, cwd, opts = {}) {
|
|
1202
1229
|
const { version } = opts;
|
|
1203
1230
|
if (typeof version !== "string")
|
|
@@ -1217,6 +1244,13 @@ function buildReportDocument(items, forwards, problems, cwd, opts = {}) {
|
|
|
1217
1244
|
)
|
|
1218
1245
|
];
|
|
1219
1246
|
const itemRefs = (related) => [...related].map((other) => ({ id: other.id, ...location(other) })).sort(byLocation);
|
|
1247
|
+
const defectDocument = (defect) => {
|
|
1248
|
+
const out = { kind: defect.kind, ref: defect.ref };
|
|
1249
|
+
if (defect.file) Object.assign(out, location(defect));
|
|
1250
|
+
if (defect.existingRevisions) out.existingRevisions = defect.existingRevisions;
|
|
1251
|
+
out.message = defect.message;
|
|
1252
|
+
return out;
|
|
1253
|
+
};
|
|
1220
1254
|
const itemDocument = (item) => {
|
|
1221
1255
|
const coverStatus = coverStatusOf(item);
|
|
1222
1256
|
return {
|
|
@@ -1379,9 +1413,8 @@ async function main() {
|
|
|
1379
1413
|
for (const file of files) {
|
|
1380
1414
|
const text = await fs2.readFile(file, "utf8");
|
|
1381
1415
|
const ext = path5.extname(file).toLowerCase();
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
);
|
|
1416
|
+
const parse = specParserFor(ext) ?? parseCode;
|
|
1417
|
+
items.push(...parse(file, text, problems, forwards));
|
|
1385
1418
|
}
|
|
1386
1419
|
if (opts.tags) {
|
|
1387
1420
|
const wantUntagged = opts.tags.includes("_");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flashtrace",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "Lightning-fast, reference-based requirement tracing that works anywhere.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -32,7 +32,9 @@
|
|
|
32
32
|
"build": "esbuild src/main.mjs --bundle --format=esm --platform=node --outfile=dist/flashtrace.mjs",
|
|
33
33
|
"prepack": "pnpm run build",
|
|
34
34
|
"pretest": "pnpm run build",
|
|
35
|
-
"test": "node --test"
|
|
35
|
+
"test": "node --test",
|
|
36
|
+
"pretest:coverage": "pnpm run build && node .github/scripts/prepare-coverage.mjs",
|
|
37
|
+
"test:coverage": "node --test --experimental-test-coverage --test-coverage-include=src/** --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test-reporter=junit --test-reporter-destination=coverage/junit.xml"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
38
40
|
"esbuild": "^0.28.1"
|