MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / write_report

Function write_report

scripts/documentation-verify.py:831–863  ·  view source on GitHub ↗

Group findings by kind, then by file, and write `.doc-report`. Removes any stale report when there are no findings.

(report_path: Path, findings: list[Finding])

Source from the content-addressed store, hash-verified

829
830
831def write_report(report_path: Path, findings: list[Finding]) -> None:
832 """Group findings by kind, then by file, and write `.doc-report`.
833 Removes any stale report when there are no findings."""
834 if not findings:
835 if report_path.exists():
836 report_path.unlink()
837 return
838
839 by_kind: dict[str, list[Finding]] = {}
840 for f in findings:
841 by_kind.setdefault(f.kind, []).append(f)
842
843 out: list[str] = [_REPORT_HEADER]
844 out.append(f"\n_Total findings: {len(findings)}_\n")
845
846 for kind in sorted(by_kind):
847 entries = by_kind[kind]
848 out.append(f"\n### `{kind}` ({len(entries)})\n\n")
849 # Group by file within each kind for readability.
850 by_file: dict[Path, list[Finding]] = {}
851 for f in entries:
852 by_file.setdefault(f.path, []).append(f)
853 for fpath in sorted(by_file):
854 out.append(f"**`{fpath}`**\n\n")
855 for f in by_file[fpath]:
856 excerpt = f.excerpt.replace("`", "'")
857 out.append(f"- L{f.line}:{f.col} -- {f.message}\n")
858 if excerpt:
859 out.append(f" > {excerpt}\n")
860 out.append("\n")
861
862 out.append("\n---\n")
863 report_path.write_text("".join(out), encoding="utf-8", newline="\n")
864
865
866# ---------------------------------------------------------------------------

Callers 1

mainFunction · 0.85

Calls 2

existsMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected