flashtrace 0.7.1 → 0.8.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 CHANGED
@@ -33,6 +33,11 @@ You can then execute `npx flashtrace` to run the tracing.
33
33
  Read our [Usage Guide](docs/USAGE.md) for more details.
34
34
  Node >= 18 is required for flashtrace to work.
35
35
 
36
+ Looking for a working setup to start from? The [examples/](examples/) folder
37
+ holds four self-contained example projects, from a minimal clean trace to a
38
+ deliberately broken one showing every defect flashtrace reports. Each has a
39
+ README, and the end-to-end tests verify their exact report output on every run.
40
+
36
41
  ## About flashtrace
37
42
 
38
43
  Let's be honest: This project started when I needed it myself.
@@ -187,11 +187,11 @@ async function walk(dir, out) {
187
187
  } catch {
188
188
  return out;
189
189
  }
190
- for (const e of entries) {
191
- if (e.name === ".git" || e.name === "node_modules") continue;
192
- const p = path.join(dir, e.name);
193
- if (e.isDirectory()) await walk(p, out);
194
- else if (e.isFile()) out.push(p);
190
+ for (const entry of entries) {
191
+ if (entry.name === ".git" || entry.name === "node_modules") continue;
192
+ const entryPath = path.join(dir, entry.name);
193
+ if (entry.isDirectory()) await walk(entryPath, out);
194
+ else if (entry.isFile()) out.push(entryPath);
195
195
  }
196
196
  return out;
197
197
  }
@@ -199,9 +199,9 @@ async function collectFiles(dirs) {
199
199
  const files = /* @__PURE__ */ new Set();
200
200
  for (const dir of dirs) {
201
201
  const abs = path.resolve(dir);
202
- const st = await fs.stat(abs).catch(() => null);
203
- if (!st) throw new UsageError(`input path does not exist: ${dir}`);
204
- if (st.isFile()) {
202
+ const stats = await fs.stat(abs).catch(() => null);
203
+ if (!stats) throw new UsageError(`input path does not exist: ${dir}`);
204
+ if (stats.isFile()) {
205
205
  files.add(abs);
206
206
  continue;
207
207
  }
@@ -218,52 +218,52 @@ async function collectFiles(dirs) {
218
218
  } catch {
219
219
  list = await walk(abs, []);
220
220
  }
221
- for (const f of list) files.add(f);
221
+ for (const file of list) files.add(file);
222
222
  }
223
- return [...files].filter((f) => {
224
- const ext = path.extname(f).toLowerCase();
223
+ return [...files].filter((file) => {
224
+ const ext = path.extname(file).toLowerCase();
225
225
  return MD_EXT.has(ext) || CODE_EXT.has(ext);
226
226
  }).sort(compareStrings);
227
227
  }
228
228
 
229
229
  // src/ids.mjs
230
- var SEG_SRC = "[A-Za-z][A-Za-z0-9_.-]*";
230
+ var SEGMENT_SRC = "[A-Za-z][A-Za-z0-9_.-]*";
231
231
  var REV_SRC = String.raw`\d+(?:\.\d+){0,2}`;
232
- var WILD_SRC = String.raw`(?:\d+\.\d+\.x|\d+\.x\.y|x\.y\.z|\d+\.x|x\.y|x)`;
233
- var REVREF_SRC = `(?:${WILD_SRC}|${REV_SRC})`;
234
- var ID_SRC = String.raw`([A-Za-z]+):(?:((?:${SEG_SRC}\/)*${SEG_SRC})\/)?(${SEG_SRC})#(${REV_SRC})`;
232
+ var WILDCARD_SRC = String.raw`(?:\d+\.\d+\.x|\d+\.x\.y|x\.y\.z|\d+\.x|x\.y|x)`;
233
+ var REV_REF_SRC = `(?:${WILDCARD_SRC}|${REV_SRC})`;
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 NEED_ID_SRC = String.raw`([A-Za-z]+):(?:((?:${SEG_SRC}\/)*${SEG_SRC})\/)?(${SEG_SRC})#(${REVREF_SRC})`;
236
+ var NEED_ID_SRC = String.raw`([A-Za-z]+):(?:((?:${SEGMENT_SRC}\/)*${SEGMENT_SRC})\/)?(${SEGMENT_SRC})#(${REV_REF_SRC})`;
237
237
  var NEED_ID_RE = new RegExp(`^${NEED_ID_SRC}$`);
238
238
  var FORWARD_SRC = String.raw`\[\s*${ID_SRC}\s*-->\s*${ID_SRC}\s*\]`;
239
- var mkId = (type, group, name, rev) => `${type}:${group ? group + "/" : ""}${name}#${rev}`;
240
- var mkForward = (m, base, file, line) => ({
241
- from: mkId(m[base], m[base + 1], m[base + 2], m[base + 3]),
242
- to: mkId(m[base + 4], m[base + 5], m[base + 6], m[base + 7]),
239
+ var makeId = (type, group, name, rev) => `${type}:${group ? group + "/" : ""}${name}#${rev}`;
240
+ var makeForward = (m, base, file, line) => ({
241
+ from: makeId(m[base], m[base + 1], m[base + 2], m[base + 3]),
242
+ to: makeId(m[base + 4], m[base + 5], m[base + 6], m[base + 7]),
243
243
  file,
244
244
  line
245
245
  });
246
246
  var keyOf = (id) => id.slice(0, id.lastIndexOf("#"));
247
247
  var revOf = (id) => id.slice(id.lastIndexOf("#") + 1);
248
248
  function compareRev(a, b) {
249
- const pa = a.split(".");
250
- const pb = b.split(".");
251
- for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
252
- if (i >= pa.length) return -1;
253
- if (i >= pb.length) return 1;
254
- if (pa[i] !== pb[i]) return Number(pa[i]) - Number(pb[i]);
249
+ const partsA = a.split(".");
250
+ const partsB = b.split(".");
251
+ for (let i = 0; i < Math.max(partsA.length, partsB.length); i++) {
252
+ if (i >= partsA.length) return -1;
253
+ if (i >= partsB.length) return 1;
254
+ if (partsA[i] !== partsB[i]) return Number(partsA[i]) - Number(partsB[i]);
255
255
  }
256
256
  return 0;
257
257
  }
258
- var WILD_LAYER = /* @__PURE__ */ new Set(["x", "y", "z"]);
258
+ var WILDCARD_LAYERS = /* @__PURE__ */ new Set(["x", "y", "z"]);
259
259
  var isWildcardRev = (rev) => /[xyz]/.test(rev);
260
260
  function revMatches(pattern, concrete) {
261
- const pp = pattern.split(".");
262
- const cp = concrete.split(".");
263
- if (pp.length !== cp.length) return false;
264
- for (let i = 0; i < pp.length; i++) {
265
- if (WILD_LAYER.has(pp[i])) continue;
266
- if (pp[i] !== cp[i]) return false;
261
+ const patternParts = pattern.split(".");
262
+ const concreteParts = concrete.split(".");
263
+ if (patternParts.length !== concreteParts.length) return false;
264
+ for (let i = 0; i < patternParts.length; i++) {
265
+ if (WILDCARD_LAYERS.has(patternParts[i])) continue;
266
+ if (patternParts[i] !== concreteParts[i]) return false;
267
267
  }
268
268
  return true;
269
269
  }
@@ -271,12 +271,12 @@ var idMatches = (need, id) => keyOf(need) === keyOf(id) && revMatches(revOf(need
271
271
  function parseIdEntry(raw) {
272
272
  const cleaned = raw.replaceAll("`", "").trim();
273
273
  const m = cleaned.match(ID_RE);
274
- return m ? mkId(m[1], m[2], m[3], m[4]) : null;
274
+ return m ? makeId(m[1], m[2], m[3], m[4]) : null;
275
275
  }
276
276
  function parseNeedEntry(raw) {
277
277
  const cleaned = raw.replaceAll("`", "").trim();
278
278
  const m = cleaned.match(NEED_ID_RE);
279
- return m ? mkId(m[1], m[2], m[3], m[4]) : null;
279
+ return m ? makeId(m[1], m[2], m[3], m[4]) : null;
280
280
  }
281
281
  function newItem(id, origin, file, line) {
282
282
  return {
@@ -299,24 +299,32 @@ function newItem(id, origin, file, line) {
299
299
  }
300
300
 
301
301
  // src/parse-markdown.mjs
302
- var DEF_RE = new RegExp(String.raw`^\s*\`${ID_SRC}\`\s*$`);
302
+ var DEFINITION_RE = new RegExp(String.raw`^\s*\`${ID_SRC}\`\s*$`);
303
303
  var HEADING_RE = /^(#{1,6})\s+(\S(?:.*\S)?)\s*$/;
304
+ var SETEXT_UNDERLINE_RE = /^ {0,3}(?:=+|-+)[ \t]*$/;
304
305
  var KEYWORD_RE = /^(Needs|Covers|Tags):\s*((?:\S.*)?)$/;
305
306
  var BULLET_RE = /^\s*[-*+]\s+(\S(?:.*\S)?)\s*$/;
306
- var DELIM_CELL_RE = /^:?-+:?$/;
307
+ var DELIMITER_CELL_RE = /^:?-+:?$/;
307
308
  var FORWARD_LINE_RE = new RegExp(String.raw`^\s*(\`?)${FORWARD_SRC}\1\s*$`);
308
- var isBoundary = (l) => DEF_RE.test(l) || HEADING_RE.test(l);
309
- function takeForward(line, file, n, forwards) {
310
- const f = line.match(FORWARD_LINE_RE);
311
- if (f) forwards.push(mkForward(f, 2, file, n + 1));
312
- return !!f;
313
- }
314
- function titleAbove(lines, defIndex) {
315
- for (let k = defIndex - 1; k >= 0; k--) {
316
- const l = lines[k];
317
- if (l.trim() === "") continue;
318
- const h = l.match(HEADING_RE);
319
- return h ? h[2] : null;
309
+ var isBoundary = (line) => DEFINITION_RE.test(line) || HEADING_RE.test(line);
310
+ function takeForward(line, file, lineIndex, forwards) {
311
+ const forward = line.match(FORWARD_LINE_RE);
312
+ if (forward) forwards.push(makeForward(forward, 2, file, lineIndex + 1));
313
+ return !!forward;
314
+ }
315
+ function isParagraphLine(line) {
316
+ return line.trim() !== "" && !HEADING_RE.test(line) && !DEFINITION_RE.test(line) && !BULLET_RE.test(line) && !SETEXT_UNDERLINE_RE.test(line);
317
+ }
318
+ function titleAbove(lines, definitionIndex) {
319
+ for (let k = definitionIndex - 1; k >= 0; k--) {
320
+ const line = lines[k];
321
+ if (line.trim() === "") continue;
322
+ const heading = line.match(HEADING_RE);
323
+ if (heading) return heading[2];
324
+ if (SETEXT_UNDERLINE_RE.test(line) && k > 0 && isParagraphLine(lines[k - 1])) {
325
+ return lines[k - 1].trim();
326
+ }
327
+ return null;
320
328
  }
321
329
  return null;
322
330
  }
@@ -326,19 +334,19 @@ function keywordEntries(lines, j, inline) {
326
334
  }
327
335
  const entries = [];
328
336
  while (j + 1 < lines.length) {
329
- const b = lines[j + 1].match(BULLET_RE);
330
- if (!b) break;
331
- entries.push(b[1].trim());
337
+ const bullet = lines[j + 1].match(BULLET_RE);
338
+ if (!bullet) break;
339
+ entries.push(bullet[1].trim());
332
340
  j++;
333
341
  }
334
342
  return { entries, j };
335
343
  }
336
344
  function rowCells(line) {
337
- let s = line.trim();
338
- if (!s.includes("|")) return null;
339
- if (s.startsWith("|")) s = s.slice(1);
340
- if (s.endsWith("|")) s = s.slice(0, -1);
341
- return s.split("|").map((c) => c.trim());
345
+ let row = line.trim();
346
+ if (!row.includes("|")) return null;
347
+ if (row.startsWith("|")) row = row.slice(1);
348
+ if (row.endsWith("|")) row = row.slice(0, -1);
349
+ return row.split("|").map((cell) => cell.trim());
342
350
  }
343
351
  function takeKeywordTable(lines, j, item, file, problems) {
344
352
  const header = rowCells(lines[j]);
@@ -348,8 +356,8 @@ function takeKeywordTable(lines, j, item, file, problems) {
348
356
  if (cell === "Needs" || cell === "Covers" || cell === "Tags") columns.push([col, cell]);
349
357
  });
350
358
  if (columns.length === 0) return null;
351
- const delim = j + 1 < lines.length ? rowCells(lines[j + 1]) : null;
352
- if (delim?.length !== header.length || !delim.every((c) => DELIM_CELL_RE.test(c))) 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;
353
361
  j++;
354
362
  while (j + 1 < lines.length && !isBoundary(lines[j + 1])) {
355
363
  const cells = rowCells(lines[j + 1]);
@@ -361,46 +369,47 @@ function takeKeywordTable(lines, j, item, file, problems) {
361
369
  }
362
370
  return j;
363
371
  }
364
- function applyKeyword(item, keyword, entries, file, kwLine, problems) {
372
+ function applyKeyword(item, keyword, entries, file, keywordLine, problems) {
365
373
  if (keyword === "Tags") {
366
374
  item.tags.push(...entries);
367
375
  return;
368
376
  }
369
377
  const target = keyword === "Needs" ? "needs" : "covers";
370
378
  const parse = keyword === "Needs" ? parseNeedEntry : parseIdEntry;
371
- for (const e of entries) {
372
- const id = parse(e);
379
+ for (const entry of entries) {
380
+ const id = parse(entry);
373
381
  if (id) item[target].push(id);
374
382
  else
375
383
  problems.push({
384
+ severity: "error",
376
385
  file,
377
- line: kwLine,
378
- message: `invalid ID "${e}" in ${keyword}: list of ${item.id}`
386
+ line: keywordLine,
387
+ message: `invalid ID "${entry}" in ${keyword}: list of ${item.id}`
379
388
  });
380
389
  }
381
390
  }
382
391
  function parseItemBody(lines, start, item, file, problems, forwards) {
383
392
  let j = start;
384
- let descDone = false;
393
+ let descriptionDone = false;
385
394
  while (j < lines.length && !isBoundary(lines[j])) {
386
395
  const line = lines[j];
387
396
  if (takeForward(line, file, j, forwards)) {
388
397
  j++;
389
398
  continue;
390
399
  }
391
- const kw = line.match(KEYWORD_RE);
392
- const tableEnd = kw ? null : takeKeywordTable(lines, j, item, file, problems);
393
- if (kw) {
394
- descDone = true;
395
- const collected = keywordEntries(lines, j, kw[2]);
396
- applyKeyword(item, kw[1], collected.entries, file, j + 1, problems);
400
+ const keywordMatch = line.match(KEYWORD_RE);
401
+ const tableEnd = keywordMatch ? null : takeKeywordTable(lines, j, item, file, problems);
402
+ if (keywordMatch) {
403
+ descriptionDone = true;
404
+ const collected = keywordEntries(lines, j, keywordMatch[2]);
405
+ applyKeyword(item, keywordMatch[1], collected.entries, file, j + 1, problems);
397
406
  j = collected.j;
398
407
  } else if (tableEnd !== null) {
399
- descDone = true;
408
+ descriptionDone = true;
400
409
  j = tableEnd;
401
410
  } else if (line.trim() === "") {
402
- if (item.description.length > 0) descDone = true;
403
- } else if (!descDone) {
411
+ if (item.description.length > 0) descriptionDone = true;
412
+ } else if (!descriptionDone) {
404
413
  item.description.push(line.trim());
405
414
  }
406
415
  j++;
@@ -416,12 +425,12 @@ function parseMarkdown(file, text, problems, forwards = []) {
416
425
  i++;
417
426
  continue;
418
427
  }
419
- const def = lines[i].match(DEF_RE);
420
- if (!def) {
428
+ const definition = lines[i].match(DEFINITION_RE);
429
+ if (!definition) {
421
430
  i++;
422
431
  continue;
423
432
  }
424
- const item = newItem(mkId(def[1], def[2], def[3], def[4]), "markdown", file, i + 1);
433
+ const item = newItem(makeId(definition[1], definition[2], definition[3], definition[4]), "markdown", file, i + 1);
425
434
  item.title = titleAbove(lines, i);
426
435
  i = parseItemBody(lines, i + 1, item, file, problems, forwards);
427
436
  items.push(item);
@@ -440,39 +449,39 @@ function activeLeaf(grammar, state) {
440
449
  if (state.region) return state.region.grammar;
441
450
  return grammar.regions ? grammar.default : grammar;
442
451
  }
443
- function matchAt(re, s, pos) {
452
+ function matchAt(re, line, pos) {
444
453
  re.lastIndex = pos;
445
- return re.exec(s);
454
+ return re.exec(line);
446
455
  }
447
- function* regionEvents(s, pos, grammar, state) {
456
+ function* regionEvents(line, pos, grammar, state) {
448
457
  if (!grammar.regions) return;
449
458
  if (state.region) {
450
- const m = matchAt(state.region.exit, s, pos);
459
+ const m = matchAt(state.region.exit, line, pos);
451
460
  if (m) yield { idx: m.index, kind: "exit", len: m[0].length };
452
461
  return;
453
462
  }
454
- for (const r of grammar.regions) {
455
- const m = matchAt(r.enter, s, pos);
463
+ for (const region of grammar.regions) {
464
+ const m = matchAt(region.enter, line, pos);
456
465
  if (m) {
457
- const leaf = typeof r.grammar === "function" ? r.grammar(m[0]) : r.grammar;
458
- yield { idx: m.index, kind: "enter", len: m[0].length, region: { exit: r.exit, grammar: leaf } };
466
+ const leaf = typeof region.grammar === "function" ? region.grammar(m[0]) : region.grammar;
467
+ yield { idx: m.index, kind: "enter", len: m[0].length, region: { exit: region.exit, grammar: leaf } };
459
468
  }
460
469
  }
461
470
  }
462
- function nextEvent(s, pos, grammar, state) {
471
+ function nextEvent(line, pos, grammar, state) {
463
472
  const leaf = activeLeaf(grammar, state);
464
473
  let best = null;
465
- const consider = (idx, ev) => {
474
+ const consider = (idx, event) => {
466
475
  if (idx === -1) return;
467
- if (best === null || idx < best.idx || idx === best.idx && ev.len > best.len) {
468
- best = { ...ev, idx };
476
+ if (best === null || idx < best.idx || idx === best.idx && event.len > best.len) {
477
+ best = { ...event, idx };
469
478
  }
470
479
  };
471
480
  for (const marker of leaf.line) {
472
- consider(s.indexOf(marker, pos), { kind: "line", len: marker.length });
481
+ consider(line.indexOf(marker, pos), { kind: "line", len: marker.length });
473
482
  }
474
483
  for (const [open, close, nestable] of leaf.block) {
475
- consider(s.indexOf(open, pos), {
484
+ consider(line.indexOf(open, pos), {
476
485
  kind: "block",
477
486
  len: open.length,
478
487
  open,
@@ -480,16 +489,16 @@ function nextEvent(s, pos, grammar, state) {
480
489
  nestable: Boolean(nestable)
481
490
  });
482
491
  }
483
- for (const ev of regionEvents(s, pos, grammar, state)) consider(ev.idx, ev);
492
+ for (const event of regionEvents(line, pos, grammar, state)) consider(event.idx, event);
484
493
  return best;
485
494
  }
486
- function readBlockRest(s, pos, block, limit = s.length) {
495
+ function readBlockRest(line, pos, block, limit = line.length) {
487
496
  const { open, close, nestable } = block;
488
497
  const within = (idx) => idx !== -1 && idx < limit ? idx : -1;
489
498
  let i = pos;
490
499
  while (i < limit) {
491
- const closeIdx = within(s.indexOf(close, i));
492
- const openIdx = within(nestable ? s.indexOf(open, i) : -1);
500
+ const closeIdx = within(line.indexOf(close, i));
501
+ const openIdx = within(nestable ? line.indexOf(open, i) : -1);
493
502
  if (closeIdx === -1 && openIdx === -1) break;
494
503
  if (openIdx !== -1 && (closeIdx === -1 || openIdx < closeIdx)) {
495
504
  block.depth++;
@@ -498,16 +507,16 @@ function readBlockRest(s, pos, block, limit = s.length) {
498
507
  }
499
508
  block.depth--;
500
509
  i = closeIdx + close.length;
501
- if (block.depth === 0) return { text: s.slice(pos, closeIdx) + " ", pos: i, closed: true };
510
+ if (block.depth === 0) return { text: line.slice(pos, closeIdx) + " ", pos: i, closed: true };
502
511
  }
503
- return { text: s.slice(pos, limit) + " ", pos: limit, closed: false };
512
+ return { text: line.slice(pos, limit) + " ", pos: limit, closed: false };
504
513
  }
505
- function regionExitAt(s, pos, region) {
506
- const m = matchAt(region.exit, s, pos);
514
+ function regionExitAt(line, pos, region) {
515
+ const m = matchAt(region.exit, line, pos);
507
516
  return m ? { idx: m.index, len: m[0].length } : null;
508
517
  }
509
- function consumeBlock(s, pos, state, exit) {
510
- const rest = readBlockRest(s, pos, state.block, exit ? exit.idx : s.length);
518
+ function consumeBlock(line, pos, state, exit) {
519
+ const rest = readBlockRest(line, pos, state.block, exit ? exit.idx : line.length);
511
520
  if (rest.closed) {
512
521
  state.block = null;
513
522
  return { text: rest.text, pos: rest.pos };
@@ -519,36 +528,36 @@ function consumeBlock(s, pos, state, exit) {
519
528
  }
520
529
  return { text: rest.text, pos: rest.pos };
521
530
  }
522
- function consumeLine(s, pos, state, exit) {
531
+ function consumeLine(line, pos, state, exit) {
523
532
  if (exit) {
524
533
  state.region = null;
525
- return { text: s.slice(pos, exit.idx) + " ", pos: exit.idx + exit.len, done: false };
534
+ return { text: line.slice(pos, exit.idx) + " ", pos: exit.idx + exit.len, done: false };
526
535
  }
527
- return { text: s.slice(pos) + " ", pos: s.length, done: true };
536
+ return { text: line.slice(pos) + " ", pos: line.length, done: true };
528
537
  }
529
- function commentText(s, state, grammar) {
538
+ function commentText(line, state, grammar) {
530
539
  let comment = "";
531
540
  let pos = 0;
532
- while (pos < s.length) {
533
- const exit = state.region ? regionExitAt(s, pos, state.region) : null;
541
+ while (pos < line.length) {
542
+ const exit = state.region ? regionExitAt(line, pos, state.region) : null;
534
543
  if (state.block) {
535
- const r = consumeBlock(s, pos, state, exit);
536
- comment += r.text;
537
- pos = r.pos;
544
+ const consumed = consumeBlock(line, pos, state, exit);
545
+ comment += consumed.text;
546
+ pos = consumed.pos;
538
547
  continue;
539
548
  }
540
- const ev = nextEvent(s, pos, grammar, state);
541
- if (!ev) break;
542
- pos = ev.idx + ev.len;
543
- if (ev.kind === "line") {
544
- const r = consumeLine(s, pos, state, exit);
545
- comment += r.text;
546
- pos = r.pos;
547
- if (r.done) break;
548
- } else if (ev.kind === "block") {
549
- state.block = { open: ev.open, close: ev.close, nestable: ev.nestable, depth: 1 };
550
- } else if (ev.kind === "enter") {
551
- state.region = ev.region;
549
+ const event = nextEvent(line, pos, grammar, state);
550
+ if (!event) break;
551
+ pos = event.idx + event.len;
552
+ if (event.kind === "line") {
553
+ const consumed = consumeLine(line, pos, state, exit);
554
+ comment += consumed.text;
555
+ pos = consumed.pos;
556
+ if (consumed.done) break;
557
+ } else if (event.kind === "block") {
558
+ state.block = { open: event.open, close: event.close, nestable: event.nestable, depth: 1 };
559
+ } else if (event.kind === "enter") {
560
+ state.region = event.region;
552
561
  } else {
553
562
  state.region = null;
554
563
  }
@@ -558,29 +567,31 @@ function commentText(s, state, grammar) {
558
567
  function collectTags(comment, file, line, state, items, problems) {
559
568
  for (const m of comment.matchAll(TAG_RE)) {
560
569
  if (m[9]) {
561
- const item = newItem(mkId(m[9], m[10], m[11], m[12]), "code", file, line);
562
- state.last = item;
570
+ const item = newItem(makeId(m[9], m[10], m[11], m[12]), "code", file, line);
571
+ state.lastItem = item;
563
572
  state.byId.set(item.id, item);
564
573
  items.push(item);
565
574
  continue;
566
575
  }
567
- const id = mkId(m[5], m[6], m[7], m[8]);
576
+ const id = makeId(m[5], m[6], m[7], m[8]);
568
577
  if (m[1]) {
569
- const source = mkId(m[1], m[2], m[3], m[4]);
578
+ const source = makeId(m[1], m[2], m[3], m[4]);
570
579
  const anchor = state.byId.get(source);
571
580
  if (anchor) {
572
581
  anchor.needs.push(id);
573
582
  } else {
574
583
  problems.push({
584
+ severity: "error",
575
585
  file,
576
586
  line,
577
587
  message: `need tag [${source} >> ${id}] has no preceding item tag [${source}] in this file`
578
588
  });
579
589
  }
580
- } else if (state.last) {
581
- state.last.needs.push(id);
590
+ } else if (state.lastItem) {
591
+ state.lastItem.needs.push(id);
582
592
  } else {
583
593
  problems.push({
594
+ severity: "error",
584
595
  file,
585
596
  line,
586
597
  message: `need tag [>>${id}] has no preceding item tag in this file`
@@ -593,11 +604,11 @@ function parseCode(file, text, problems, forwards = []) {
593
604
  const grammar = grammarFor(ext) ?? cLike;
594
605
  const lines = text.split(/\r?\n/);
595
606
  const items = [];
596
- const state = { last: null, byId: /* @__PURE__ */ new Map(), block: null, region: null };
607
+ const state = { lastItem: null, byId: /* @__PURE__ */ new Map(), block: null, region: null };
597
608
  for (let i = 0; i < lines.length; i++) {
598
609
  const comment = commentText(lines[i], state, grammar);
599
610
  for (const m of comment.matchAll(FORWARD_RE)) {
600
- forwards.push(mkForward(m, 1, file, i + 1));
611
+ forwards.push(makeForward(m, 1, file, i + 1));
601
612
  }
602
613
  collectTags(comment, file, i + 1, state, items, problems);
603
614
  }
@@ -605,82 +616,83 @@ function parseCode(file, text, problems, forwards = []) {
605
616
  }
606
617
 
607
618
  // src/analyze.mjs
608
- function checkItemReferences(it, byId, matchesOf, isNeeded, revHint, fwdTarget) {
609
- const fwd = fwdTarget.get(it.id);
610
- if (fwd !== void 0) {
611
- if (!byId.has(fwd))
612
- it.defects.push(`uncovered: forwards to ${fwd}, which does not exist${revHint(fwd)}`);
619
+ function checkItemReferences(item, byId, matchesOf, isNeeded, revHint, forwardTargets) {
620
+ const forwardTarget = forwardTargets.get(item.id);
621
+ if (forwardTarget !== void 0) {
622
+ if (!byId.has(forwardTarget))
623
+ item.defects.push(`uncovered: forwards to ${forwardTarget}, which does not exist${revHint(forwardTarget)}`);
613
624
  } else {
614
- for (const n of it.needs) {
615
- if (matchesOf(n).length === 0)
616
- it.defects.push(`uncovered: needs ${n}, which does not exist${revHint(n)}`);
625
+ for (const need of item.needs) {
626
+ if (matchesOf(need).length === 0)
627
+ item.defects.push(`uncovered: needs ${need}, which does not exist${revHint(need)}`);
617
628
  }
618
629
  }
619
- for (const c of it.covers) {
620
- const targets = byId.get(c);
630
+ for (const coverId of item.covers) {
631
+ const targets = byId.get(coverId);
621
632
  if (!targets) {
622
- it.defects.push(`orphaned: covers ${c}, which does not exist${revHint(c)}`);
623
- } else if (!targets.some((t) => t.needs.some((n) => idMatches(n, it.id)))) {
624
- it.defects.push(`unwanted: covers ${c}, but ${c} does not need ${it.id}`);
633
+ item.defects.push(`orphaned: covers ${coverId}, which does not exist${revHint(coverId)}`);
634
+ } else if (!targets.some((target) => target.needs.some((need) => idMatches(need, item.id)))) {
635
+ item.defects.push(`unwanted: covers ${coverId}, but ${coverId} does not need ${item.id}`);
625
636
  }
626
637
  }
627
- if (it.origin === "code" && !isNeeded(it.id)) {
628
- it.defects.push(`unwanted: no item needs ${it.id}`);
638
+ if (item.origin === "code" && !isNeeded(item.id)) {
639
+ item.defects.push(`unwanted: no item needs ${item.id}`);
629
640
  }
630
641
  }
631
- function dropCyclicForwards(fwdTarget, declBySource, problems) {
642
+ function dropCyclicForwards(forwardTargets, declarationBySource, problems) {
632
643
  const done = /* @__PURE__ */ new Set();
633
- for (const start of fwdTarget.keys()) {
644
+ for (const start of forwardTargets.keys()) {
634
645
  if (done.has(start)) continue;
635
646
  const seen = /* @__PURE__ */ new Map();
636
647
  const path5 = [];
637
- let cur = start;
638
- while (fwdTarget.has(cur) && !done.has(cur) && !seen.has(cur)) {
639
- seen.set(cur, path5.length);
640
- path5.push(cur);
641
- cur = fwdTarget.get(cur);
648
+ let current = start;
649
+ while (forwardTargets.has(current) && !done.has(current) && !seen.has(current)) {
650
+ seen.set(current, path5.length);
651
+ path5.push(current);
652
+ current = forwardTargets.get(current);
642
653
  }
643
- if (seen.has(cur)) {
644
- const cycle = path5.slice(seen.get(cur));
645
- const chain = [...cycle, cur].join(" --> ");
654
+ if (seen.has(current)) {
655
+ const cycle = path5.slice(seen.get(current));
656
+ const chain = [...cycle, current].join(" --> ");
646
657
  for (const id of cycle) {
647
- const f = declBySource.get(id);
648
- problems.push({ file: f.file, line: f.line, message: `cyclic forwarding: ${chain}` });
649
- fwdTarget.delete(id);
658
+ const declaration = declarationBySource.get(id);
659
+ problems.push({ severity: "error", file: declaration.file, line: declaration.line, message: `cyclic forwarding: ${chain}` });
660
+ forwardTargets.delete(id);
650
661
  }
651
662
  }
652
663
  for (const id of path5) done.add(id);
653
664
  }
654
665
  }
655
666
  function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
656
- const fwdTarget = /* @__PURE__ */ new Map();
657
- const declBySource = /* @__PURE__ */ new Map();
658
- const fwdBySource = /* @__PURE__ */ new Map();
659
- for (const f of forwards) {
660
- (fwdBySource.get(f.from) ?? fwdBySource.set(f.from, []).get(f.from)).push(f);
667
+ const forwardTargets = /* @__PURE__ */ new Map();
668
+ const declarationBySource = /* @__PURE__ */ new Map();
669
+ const forwardsBySource = /* @__PURE__ */ new Map();
670
+ for (const forward of forwards) {
671
+ (forwardsBySource.get(forward.from) ?? forwardsBySource.set(forward.from, []).get(forward.from)).push(forward);
661
672
  }
662
- for (const [from, group] of fwdBySource) {
673
+ for (const [from, group] of forwardsBySource) {
663
674
  const sources = byId.get(from);
664
675
  if (!sources) {
665
- for (const f of group)
676
+ for (const forward of group)
666
677
  problems.push({
667
- file: f.file,
668
- line: f.line,
678
+ severity: "error",
679
+ file: forward.file,
680
+ line: forward.line,
669
681
  message: `forwarding from ${from}, which does not exist${revHint(from)}`
670
682
  });
671
683
  continue;
672
684
  }
673
685
  if (group.length > 1)
674
- for (const it of sources)
675
- it.defects.push(`duplicate: forwarding for ${from} is declared ${group.length} times`);
676
- fwdTarget.set(from, group[0].to);
677
- declBySource.set(from, group[0]);
686
+ for (const item of sources)
687
+ item.defects.push(`duplicate: forwarding for ${from} is declared ${group.length} times`);
688
+ forwardTargets.set(from, group[0].to);
689
+ declarationBySource.set(from, group[0]);
678
690
  }
679
- dropCyclicForwards(fwdTarget, declBySource, problems);
680
- for (const to of fwdTarget.values()) neededIds.add(to);
681
- return fwdTarget;
691
+ dropCyclicForwards(forwardTargets, declarationBySource, problems);
692
+ for (const to of forwardTargets.values()) neededIds.add(to);
693
+ return forwardTargets;
682
694
  }
683
- function markDeepCoverage(items, byId, matchesOf, fwdTarget) {
695
+ function markDeepCoverage(items, byId, matchesOf, forwardTargets) {
684
696
  const memo = /* @__PURE__ */ new Map();
685
697
  const deep = (id) => {
686
698
  if (memo.has(id)) return memo.get(id);
@@ -690,18 +702,18 @@ function markDeepCoverage(items, byId, matchesOf, fwdTarget) {
690
702
  memo.set(id, false);
691
703
  return false;
692
704
  }
693
- const fwd = fwdTarget.get(id);
705
+ const forwardTarget = forwardTargets.get(id);
694
706
  let ok = true;
695
- if (fwd !== void 0) {
696
- ok = deep(fwd);
707
+ if (forwardTarget !== void 0) {
708
+ ok = deep(forwardTarget);
697
709
  } else {
698
- for (const it of group) for (const n of it.needs) if (!needDeep(n)) ok = false;
710
+ for (const item of group) for (const need of item.needs) if (!needDeep(need)) ok = false;
699
711
  }
700
712
  memo.set(id, ok);
701
713
  return ok;
702
714
  };
703
- const needDeep = (n) => matchesOf(n).some((id) => deep(id));
704
- for (const it of items) it.deepCovered = deep(it.id);
715
+ const needDeep = (need) => matchesOf(need).some((id) => deep(id));
716
+ for (const item of items) item.deepCovered = deep(item.id);
705
717
  }
706
718
  function groupIdsByKey(byId) {
707
719
  const idsByKey = /* @__PURE__ */ new Map();
@@ -711,7 +723,7 @@ function groupIdsByKey(byId) {
711
723
  }
712
724
  function buildResolver(items) {
713
725
  const byId = /* @__PURE__ */ new Map();
714
- for (const it of items) (byId.get(it.id) ?? byId.set(it.id, []).get(it.id)).push(it);
726
+ for (const item of items) (byId.get(item.id) ?? byId.set(item.id, []).get(item.id)).push(item);
715
727
  const idsByKey = groupIdsByKey(byId);
716
728
  const matchesOf = (ref) => (idsByKey.get(keyOf(ref)) ?? []).filter((id) => idMatches(ref, id));
717
729
  return { byId, matchesOf };
@@ -719,34 +731,34 @@ function buildResolver(items) {
719
731
  function splitNeeds(items) {
720
732
  const exact = /* @__PURE__ */ new Set();
721
733
  const wildcard = [];
722
- for (const it of items)
723
- for (const n of it.needs) {
724
- if (isWildcardRev(revOf(n))) wildcard.push(n);
725
- else exact.add(n);
734
+ for (const item of items)
735
+ for (const need of item.needs) {
736
+ if (isWildcardRev(revOf(need))) wildcard.push(need);
737
+ else exact.add(need);
726
738
  }
727
739
  return { exact, wildcard };
728
740
  }
729
741
  function analyze(items, forwards = [], problems = []) {
730
742
  const { byId, matchesOf } = buildResolver(items);
731
743
  const revsByKey = /* @__PURE__ */ new Map();
732
- for (const it of items)
733
- (revsByKey.get(it.key) ?? revsByKey.set(it.key, /* @__PURE__ */ new Set()).get(it.key)).add(it.revision);
744
+ for (const item of items)
745
+ (revsByKey.get(item.key) ?? revsByKey.set(item.key, /* @__PURE__ */ new Set()).get(item.key)).add(item.revision);
734
746
  const { exact: exactNeeds, wildcard: wildcardNeeds } = splitNeeds(items);
735
- const isNeeded = (id) => exactNeeds.has(id) || wildcardNeeds.some((w) => idMatches(w, id));
747
+ const isNeeded = (id) => exactNeeds.has(id) || wildcardNeeds.some((wildcard) => idMatches(wildcard, id));
736
748
  for (const [id, group] of byId) {
737
749
  if (group.length > 1)
738
- for (const it of group) it.defects.push(`duplicate: ID ${id} is defined ${group.length} times`);
750
+ for (const item of group) item.defects.push(`duplicate: ID ${id} is defined ${group.length} times`);
739
751
  }
740
752
  const revHint = (id) => {
741
753
  const revs = revsByKey.get(keyOf(id));
742
754
  return revs ? ` (revision mismatch: existing revision(s) of ${keyOf(id)}: ${[...revs].sort(compareRev).join(", ")})` : "";
743
755
  };
744
- const fwdTarget = buildForwardMap(forwards, byId, exactNeeds, revHint, problems);
745
- for (const it of items) {
746
- it.forwardsTo = fwdTarget.get(it.id) ?? null;
747
- checkItemReferences(it, byId, matchesOf, isNeeded, revHint, fwdTarget);
756
+ const forwardTargets = buildForwardMap(forwards, byId, exactNeeds, revHint, problems);
757
+ for (const item of items) {
758
+ item.forwardsTo = forwardTargets.get(item.id) ?? null;
759
+ checkItemReferences(item, byId, matchesOf, isNeeded, revHint, forwardTargets);
748
760
  }
749
- markDeepCoverage(items, byId, matchesOf, fwdTarget);
761
+ markDeepCoverage(items, byId, matchesOf, forwardTargets);
750
762
  }
751
763
 
752
764
  // src/report.mjs
@@ -754,9 +766,10 @@ import path3 from "node:path";
754
766
  import process2 from "node:process";
755
767
  function makeStyler() {
756
768
  const on = process2.stdout.isTTY && !process2.env.NO_COLOR;
757
- const wrap = (code) => (s) => on ? `\x1B[${code}m${s}\x1B[0m` : s;
769
+ const wrap = (code) => (text) => on ? `\x1B[${code}m${text}\x1B[0m` : text;
758
770
  return {
759
771
  red: wrap("31"),
772
+ brightRed: wrap("91"),
760
773
  green: wrap("32"),
761
774
  yellow: wrap("33"),
762
775
  cyan: wrap("36"),
@@ -764,124 +777,130 @@ function makeStyler() {
764
777
  bold: wrap("1")
765
778
  };
766
779
  }
767
- function statusOf(it, c) {
768
- if (it.defects.length > 0) return { mark: c.red("\u2718"), tag: c.red("[defective]") };
769
- if (!it.deepCovered) return { mark: c.yellow("~"), tag: c.yellow("[shallow-covered]") };
770
- return { mark: c.green("\u2714"), tag: c.green("[deep-covered]") };
780
+ function statusOf(item, style) {
781
+ if (item.defects.length > 0) return { mark: style.red("\u2718"), tag: style.red("[defective]") };
782
+ if (!item.deepCovered) return { mark: style.yellow("~"), tag: style.yellow("[shallow-covered]") };
783
+ return { mark: style.green("\u2714"), tag: style.green("[deep-covered]") };
771
784
  }
772
785
  function buildWantedBy(items, byId, matchesOf) {
773
786
  const wantedBy = /* @__PURE__ */ new Map();
774
- for (const it of items)
775
- for (const n of it.needs)
776
- for (const id of matchesOf(n))
777
- for (const m of byId.get(id))
778
- (wantedBy.get(m) ?? wantedBy.set(m, /* @__PURE__ */ new Set()).get(m)).add(it);
787
+ for (const item of items)
788
+ for (const need of item.needs)
789
+ for (const id of matchesOf(need))
790
+ for (const provider of byId.get(id))
791
+ (wantedBy.get(provider) ?? wantedBy.set(provider, /* @__PURE__ */ new Set()).get(provider)).add(item);
779
792
  return wantedBy;
780
793
  }
781
794
  function byFileLine(a, b) {
782
795
  if (a.file !== b.file) return a.file < b.file ? -1 : 1;
783
796
  return a.line - b.line;
784
797
  }
785
- function forwardEdge(it, byId, c, dimLoc) {
786
- const target = byId.get(it.forwardsTo)?.[0];
787
- if (!target) return ` ${c.cyan("\u2192")} ${it.forwardsTo} ${c.red("\u2718 missing")}`;
788
- return ` ${c.cyan("\u2192")} ${it.forwardsTo} ${statusOf(target, c).mark} ${dimLoc(target.file, target.line)}`;
798
+ function forwardEdge(item, byId, style, dimLocation) {
799
+ const target = byId.get(item.forwardsTo)?.[0];
800
+ if (!target) return ` ${style.cyan("\u2192")} ${item.forwardsTo} ${style.red("\u2718 missing")}`;
801
+ return ` ${style.cyan("\u2192")} ${item.forwardsTo} ${statusOf(target, style).mark} ${dimLocation(target.file, target.line)}`;
789
802
  }
790
- function needEdges(it, byId, matchesOf, c, dimLoc) {
803
+ function needEdges(item, byId, matchesOf, style, dimLocation) {
791
804
  const lines = [];
792
- for (const n of it.needs) {
793
- const ids = matchesOf(n);
805
+ for (const need of item.needs) {
806
+ const ids = matchesOf(need);
794
807
  if (ids.length === 0) {
795
- lines.push(` ${c.dim("needs")} ${n} ${c.red("\u2718 missing")}`);
808
+ lines.push(` ${style.dim("needs")} ${need} ${style.red("\u2718 missing")}`);
796
809
  continue;
797
810
  }
798
- const wild = isWildcardRev(revOf(n));
811
+ const wildcard = isWildcardRev(revOf(need));
799
812
  for (const id of ids) {
800
- const m = byId.get(id)[0];
801
- const arrow = c.dim(`(\u2192 ${id})`);
802
- const ref = wild ? `${n} ${arrow}` : n;
803
- lines.push(` ${c.dim("needs")} ${ref} ${statusOf(m, c).mark} ${dimLoc(m.file, m.line)}`);
813
+ const covering = byId.get(id)[0];
814
+ const arrow = style.dim(`(\u2192 ${id})`);
815
+ const ref = wildcard ? `${need} ${arrow}` : need;
816
+ lines.push(` ${style.dim("needs")} ${ref} ${statusOf(covering, style).mark} ${dimLocation(covering.file, covering.line)}`);
804
817
  }
805
818
  }
806
819
  return lines;
807
820
  }
808
- function coverEdges(it, byId, c, dimLoc) {
821
+ function coverEdges(item, byId, style, dimLocation) {
809
822
  const lines = [];
810
- for (const cv of it.covers) {
811
- const target = byId.get(cv)?.[0];
812
- if (!target) lines.push(` ${c.dim("covers")} ${cv} ${c.red("\u2718 missing")}`);
813
- else lines.push(` ${c.dim("covers")} ${cv} ${c.green("\u2714")} ${dimLoc(target.file, target.line)}`);
823
+ for (const coverId of item.covers) {
824
+ const target = byId.get(coverId)?.[0];
825
+ if (!target) lines.push(` ${style.dim("covers")} ${coverId} ${style.red("\u2718 missing")}`);
826
+ else lines.push(` ${style.dim("covers")} ${coverId} ${style.green("\u2714")} ${dimLocation(target.file, target.line)}`);
814
827
  }
815
828
  return lines;
816
829
  }
817
- function edgeLines(it, byId, matchesOf, wantedBy, c, dimLoc) {
830
+ function edgeLines(item, byId, matchesOf, wantedBy, style, dimLocation) {
818
831
  const lines = [];
819
- if (it.forwardsTo !== null) lines.push(forwardEdge(it, byId, c, dimLoc));
820
- else if (it.origin === "markdown") lines.push(...needEdges(it, byId, matchesOf, c, dimLoc));
821
- lines.push(...coverEdges(it, byId, c, dimLoc));
822
- for (const w of wantedBy.get(it) ?? [])
823
- lines.push(` ${c.dim("wanted by")} ${w.id} ${dimLoc(w.file, w.line)}`);
832
+ if (item.forwardsTo !== null) lines.push(forwardEdge(item, byId, style, dimLocation));
833
+ else if (item.origin === "markdown") lines.push(...needEdges(item, byId, matchesOf, style, dimLocation));
834
+ lines.push(...coverEdges(item, byId, style, dimLocation));
835
+ for (const wanting of wantedBy.get(item) ?? [])
836
+ lines.push(` ${style.dim("wanted by")} ${wanting.id} ${dimLocation(wanting.file, wanting.line)}`);
824
837
  return lines;
825
838
  }
826
- function renderVerbose(items, out, c, dimLoc) {
839
+ function renderVerbose(items, out, style, dimLocation) {
827
840
  const { byId, matchesOf } = buildResolver(items);
828
841
  const wantedBy = buildWantedBy(items, byId, matchesOf);
829
842
  const sorted = [...items].sort(byFileLine);
830
843
  let prevFile = null;
831
- for (const it of sorted) {
832
- if (prevFile !== null && it.file !== prevFile) out.push("");
833
- prevFile = it.file;
834
- const { mark, tag } = statusOf(it, c);
835
- const title = it.title ? " " + c.dim(`"${it.title}"`) : "";
844
+ for (const item of sorted) {
845
+ if (prevFile !== null && item.file !== prevFile) out.push("");
846
+ prevFile = item.file;
847
+ const { mark, tag } = statusOf(item, style);
848
+ const title = item.title ? " " + style.dim(`"${item.title}"`) : "";
836
849
  out.push(
837
- `${mark} ${c.bold(it.id)}${title} ${dimLoc(it.file, it.line)} ${tag}`,
838
- ...edgeLines(it, byId, matchesOf, wantedBy, c, dimLoc)
850
+ `${mark} ${style.bold(item.id)}${title} ${dimLocation(item.file, item.line)} ${tag}`,
851
+ ...edgeLines(item, byId, matchesOf, wantedBy, style, dimLocation)
839
852
  );
840
- for (const d of it.defects) out.push(` ${c.red("\u2022")} ${d}`);
853
+ for (const defect of item.defects) out.push(` ${style.red("\u2022")} ${defect}`);
841
854
  }
842
855
  if (sorted.length) out.push("");
843
856
  }
844
- function renderDefective(defective, out, c, dimLoc) {
845
- for (const it of defective) {
846
- const title = it.title ? " " + c.dim(`"${it.title}"`) : "";
857
+ function renderDefective(defective, out, style, dimLocation) {
858
+ for (const item of defective) {
859
+ const title = item.title ? " " + style.dim(`"${item.title}"`) : "";
847
860
  out.push(
848
- `${statusOf(it, c).mark} ${c.bold(it.id)}${title} ${dimLoc(it.file, it.line)}`
861
+ `${statusOf(item, style).mark} ${style.bold(item.id)}${title} ${dimLocation(item.file, item.line)}`
849
862
  );
850
- for (const d of it.defects) out.push(` ${c.red("\u2022")} ${d}`);
863
+ for (const defect of item.defects) out.push(` ${style.red("\u2022")} ${defect}`);
851
864
  out.push("");
852
865
  }
853
866
  }
854
- function renderSummary(items, defective, problems, out, c) {
867
+ function renderSummary(items, defective, errorCount, warningCount, out, style) {
855
868
  const okCount = items.length - defective.length;
856
- const notDeep = items.filter((it) => it.defects.length === 0 && !it.deepCovered).length;
857
- const md = items.filter((i) => i.origin === "markdown").length;
858
- const originBreakdown = c.dim(`(${md} from markdown, ${items.length - md} from code)`);
869
+ const shallowCount = items.filter((item) => item.defects.length === 0 && !item.deepCovered).length;
870
+ const markdownCount = items.filter((item) => item.origin === "markdown").length;
871
+ const originBreakdown = style.dim(`(${markdownCount} from markdown, ${items.length - markdownCount} from code)`);
859
872
  out.push(
860
- c.bold("Summary"),
873
+ style.bold("Summary"),
861
874
  ` items ${items.length} ${originBreakdown}`,
862
- ` ok ${c.green(String(okCount))}`,
863
- ` defective ${defective.length ? c.red(String(defective.length)) : "0"}`
875
+ ` ok ${style.green(String(okCount))}`,
876
+ ` defective ${defective.length ? style.red(String(defective.length)) : "0"}`
864
877
  );
865
- if (notDeep) out.push(" " + c.dim(`of the ok items, ${notDeep} are only shallow-covered (an item further down the tracing chain is defective)`));
866
- if (problems.length) out.push(` problems ${c.yellow(String(problems.length))}`);
878
+ 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 (errorCount) out.push(` errors ${style.brightRed(String(errorCount))}`);
880
+ if (warningCount) out.push(` warnings ${style.yellow(String(warningCount))}`);
867
881
  out.push("");
868
882
  }
883
+ function problemMark(problem, style) {
884
+ return problem.severity === "warning" ? style.yellow("\u26A0") : style.brightRed("\u25B2");
885
+ }
869
886
  function report(items, problems, cwd, opts = {}) {
870
887
  const { verbose = false } = opts;
871
- const c = makeStyler();
872
- const rel = (f) => path3.relative(cwd, f) || f;
873
- const dimLoc = (file, line) => c.dim(`${rel(file)}:${line}`);
874
- const defective = items.filter((it) => it.defects.length > 0);
888
+ const style = makeStyler();
889
+ const relativePath = (file) => path3.relative(cwd, file) || file;
890
+ const dimLocation = (file, line) => style.dim(`${relativePath(file)}:${line}`);
891
+ 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;
875
894
  const out = [];
876
- if (verbose) renderVerbose(items, out, c, dimLoc);
877
- else renderDefective(defective, out, c, dimLoc);
878
- for (const p of problems) {
879
- out.push(`${c.yellow("\u26A0")} ${p.message} ${dimLoc(p.file, p.line)}`);
895
+ if (verbose) renderVerbose(items, out, style, dimLocation);
896
+ else renderDefective(defective, out, style, dimLocation);
897
+ for (const problem of problems) {
898
+ out.push(`${problemMark(problem, style)} ${problem.message} ${dimLocation(problem.file, problem.line)}`);
880
899
  }
881
900
  if (problems.length) out.push("");
882
- renderSummary(items, defective, problems, out, c);
883
- const clean = defective.length === 0 && problems.length === 0;
884
- out.push(clean ? c.green(c.bold("ok")) : c.red(c.bold("not ok")));
901
+ renderSummary(items, defective, errorCount, warningCount, out, style);
902
+ const clean = defective.length === 0 && errorCount === 0;
903
+ out.push(clean ? style.green(style.bold("ok")) : style.red(style.bold("not ok")));
885
904
  console.log(out.join("\n"));
886
905
  return clean;
887
906
  }
@@ -901,31 +920,44 @@ Options:
901
920
  -V, --version print the version number
902
921
  -h, --help show this help
903
922
 
904
- Exit codes: 0 clean, 1 defects or problems found, 2 usage error`;
923
+ Long options also accept "="-attached values, e.g. --tags=a,b.
924
+
925
+ Exit codes: 0 clean, 1 defects or errors found, 2 usage error
926
+ (warning problems alone leave the run clean)`;
905
927
  function packageVersion() {
906
928
  const pkg = new URL("../package.json", import.meta.url);
907
929
  return JSON.parse(readFileSync(pkg, "utf8")).version;
908
930
  }
931
+ function splitLongOption(token) {
932
+ const eqIndex = token.startsWith("--") ? token.indexOf("=") : -1;
933
+ return eqIndex === -1 ? [token, null] : [token.slice(0, eqIndex), token.slice(eqIndex + 1)];
934
+ }
935
+ function rejectValue(name, inline) {
936
+ if (inline !== null) throw new UsageError(`option ${name} does not take a value`);
937
+ }
909
938
  function parseArgs(argv) {
910
939
  const opts = { dirs: [], tags: null, verbose: false };
911
940
  for (let i = 0; i < argv.length; i++) {
912
- const a = argv[i];
913
- if (a === "-h" || a === "--help") {
941
+ const [name, inline] = splitLongOption(argv[i]);
942
+ if (name === "-h" || name === "--help") {
943
+ rejectValue(name, inline);
914
944
  console.log(HELP);
915
945
  process3.exit(0);
916
- } else if (a === "-v" || a === "--verbose") {
946
+ } else if (name === "-v" || name === "--verbose") {
947
+ rejectValue(name, inline);
917
948
  opts.verbose = true;
918
- } else if (a === "-V" || a === "--version") {
949
+ } else if (name === "-V" || name === "--version") {
950
+ rejectValue(name, inline);
919
951
  console.log(packageVersion());
920
952
  process3.exit(0);
921
- } else if (a === "-t" || a === "--tags") {
922
- const v = argv[++i];
923
- if (!v) throw new UsageError(`missing value for ${a}`);
924
- opts.tags = v.split(",").map((s) => s.trim()).filter(Boolean);
925
- } else if (a.startsWith("-")) {
926
- throw new UsageError(`unknown option: ${a}`);
953
+ } else if (name === "-t" || name === "--tags") {
954
+ const value = inline ?? argv[++i];
955
+ if (!value) throw new UsageError(`missing value for ${name}`);
956
+ opts.tags = value.split(",").map((s) => s.trim()).filter(Boolean);
957
+ } else if (name.startsWith("-")) {
958
+ throw new UsageError(`unknown option: ${name}`);
927
959
  } else {
928
- opts.dirs.push(a);
960
+ opts.dirs.push(name);
929
961
  }
930
962
  }
931
963
  if (opts.dirs.length === 0) opts.dirs.push(".");
@@ -947,7 +979,7 @@ async function main() {
947
979
  if (opts.tags) {
948
980
  const wantUntagged = opts.tags.includes("_");
949
981
  items = items.filter(
950
- (it) => it.origin === "code" || it.tags.some((t) => opts.tags.includes(t)) || wantUntagged && it.tags.length === 0
982
+ (item) => item.origin === "code" || item.tags.some((tag) => opts.tags.includes(tag)) || wantUntagged && item.tags.length === 0
951
983
  );
952
984
  }
953
985
  analyze(items, forwards, problems);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flashtrace",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Lightning-fast, reference-based requirement tracing that works anywhere.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {