flashtrace 0.8.0 → 0.9.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
@@ -1,24 +1,61 @@
1
- <p align="center">
2
- <a href="https://github.com/flashtrace">
3
- <img src="https://github.com/flashtrace.png" alt="flashtrace logo" width="120">
4
- </a>
5
- </p>
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
- <h3 align="center">flashtrace</h3>
30
+ ---
31
+ ---
8
32
 
9
- <p align="center">
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://github.com/flashtrace/flashtrace/blob/main/docs/index.md">
15
- <img src="https://img.shields.io/badge/Spec-Driven-8e4d13.svg?labelColor=1e1e1e" alt="Spec-driven documentation." />
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://github.com/flashtrace/flashtrace/blob/main/CLAUDE.md">
18
- <img src="https://img.shields.io/badge/Agent-Native-d97d0e.svg?labelColor=1e1e1e" alt="This repository was created agent-native." />
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://github.com/flashtrace/flashtrace/blob/main/LICENSE">
21
- <img src="https://img.shields.io/badge/License-Apache_2.0-f9c21d.svg?labelColor=1e1e1e" alt="Released under the Apache 2.0 license." />
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
 
@@ -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) && !DEFINITION_RE.test(line) && !BULLET_RE.test(line) && !SETEXT_UNDERLINE_RE.test(line);
316
+ return line.trim() !== "" && !HEADING_RE.test(line) && !BULLET_RE.test(line) && !SETEXT_UNDERLINE_RE.test(line);
317
317
  }
318
- function titleAbove(lines, definitionIndex) {
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 (SETEXT_UNDERLINE_RE.test(line) && k > 0 && isParagraphLine(lines[k - 1])) {
325
- return lines[k - 1].trim();
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 takeKeywordTable(lines, j, item, file, problems) {
370
+ function tableStartsAt(lines, j) {
352
371
  const header = rowCells(lines[j]);
353
- if (!header) return null;
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
- header.forEach((cell, col) => {
356
- if (cell === "Needs" || cell === "Covers" || cell === "Tags") columns.push([col, 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 && !isBoundary(lines[j + 1])) {
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]) applyKeyword(item, keyword, [cells[col]], file, j + 1, problems);
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 ${keyword}: list of ${item.id}`
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[j])) {
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(item, keywordMatch[1], collected.entries, file, j + 1, problems);
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
- if (takeForward(lines[i], file, i, forwards)) {
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;
@@ -581,7 +656,6 @@ function collectTags(comment, file, line, state, items, problems) {
581
656
  anchor.needs.push(id);
582
657
  } else {
583
658
  problems.push({
584
- severity: "error",
585
659
  file,
586
660
  line,
587
661
  message: `need tag [${source} >> ${id}] has no preceding item tag [${source}] in this file`
@@ -591,7 +665,6 @@ function collectTags(comment, file, line, state, items, problems) {
591
665
  state.lastItem.needs.push(id);
592
666
  } else {
593
667
  problems.push({
594
- severity: "error",
595
668
  file,
596
669
  line,
597
670
  message: `need tag [>>${id}] has no preceding item tag in this file`
@@ -656,7 +729,7 @@ function dropCyclicForwards(forwardTargets, declarationBySource, problems) {
656
729
  const chain = [...cycle, current].join(" --> ");
657
730
  for (const id of cycle) {
658
731
  const declaration = declarationBySource.get(id);
659
- problems.push({ severity: "error", file: declaration.file, line: declaration.line, message: `cyclic forwarding: ${chain}` });
732
+ problems.push({ file: declaration.file, line: declaration.line, message: `cyclic forwarding: ${chain}` });
660
733
  forwardTargets.delete(id);
661
734
  }
662
735
  }
@@ -675,7 +748,6 @@ function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
675
748
  if (!sources) {
676
749
  for (const forward of group)
677
750
  problems.push({
678
- severity: "error",
679
751
  file: forward.file,
680
752
  line: forward.line,
681
753
  message: `forwarding from ${from}, which does not exist${revHint(from)}`
@@ -769,7 +841,6 @@ function makeStyler() {
769
841
  const wrap = (code) => (text) => on ? `\x1B[${code}m${text}\x1B[0m` : text;
770
842
  return {
771
843
  red: wrap("31"),
772
- brightRed: wrap("91"),
773
844
  green: wrap("32"),
774
845
  yellow: wrap("33"),
775
846
  cyan: wrap("36"),
@@ -864,7 +935,7 @@ function renderDefective(defective, out, style, dimLocation) {
864
935
  out.push("");
865
936
  }
866
937
  }
867
- function renderSummary(items, defective, errorCount, warningCount, out, style) {
938
+ function renderSummary(items, defective, problems, out, style) {
868
939
  const okCount = items.length - defective.length;
869
940
  const shallowCount = items.filter((item) => item.defects.length === 0 && !item.deepCovered).length;
870
941
  const markdownCount = items.filter((item) => item.origin === "markdown").length;
@@ -876,30 +947,24 @@ function renderSummary(items, defective, errorCount, warningCount, out, style) {
876
947
  ` defective ${defective.length ? style.red(String(defective.length)) : "0"}`
877
948
  );
878
949
  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))}`);
950
+ if (problems.length) out.push(` problems ${style.yellow(String(problems.length))}`);
881
951
  out.push("");
882
952
  }
883
- function problemMark(problem, style) {
884
- return problem.severity === "warning" ? style.yellow("\u26A0") : style.brightRed("\u25B2");
885
- }
886
953
  function report(items, problems, cwd, opts = {}) {
887
954
  const { verbose = false } = opts;
888
955
  const style = makeStyler();
889
956
  const relativePath = (file) => path3.relative(cwd, file) || file;
890
957
  const dimLocation = (file, line) => style.dim(`${relativePath(file)}:${line}`);
891
958
  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
959
  const out = [];
895
960
  if (verbose) renderVerbose(items, out, style, dimLocation);
896
961
  else renderDefective(defective, out, style, dimLocation);
897
962
  for (const problem of problems) {
898
- out.push(`${problemMark(problem, style)} ${problem.message} ${dimLocation(problem.file, problem.line)}`);
963
+ out.push(`${style.yellow("\u26A0")} ${problem.message} ${dimLocation(problem.file, problem.line)}`);
899
964
  }
900
965
  if (problems.length) out.push("");
901
- renderSummary(items, defective, errorCount, warningCount, out, style);
902
- const clean = defective.length === 0 && errorCount === 0;
966
+ renderSummary(items, defective, problems, out, style);
967
+ const clean = defective.length === 0 && problems.length === 0;
903
968
  out.push(clean ? style.green(style.bold("ok")) : style.red(style.bold("not ok")));
904
969
  console.log(out.join("\n"));
905
970
  return clean;
@@ -922,8 +987,7 @@ Options:
922
987
 
923
988
  Long options also accept "="-attached values, e.g. --tags=a,b.
924
989
 
925
- Exit codes: 0 clean, 1 defects or errors found, 2 usage error
926
- (warning problems alone leave the run clean)`;
990
+ Exit codes: 0 clean, 1 defects or problems found, 2 usage error`;
927
991
  function packageVersion() {
928
992
  const pkg = new URL("../package.json", import.meta.url);
929
993
  return JSON.parse(readFileSync(pkg, "utf8")).version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flashtrace",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Lightning-fast, reference-based requirement tracing that works anywhere.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {