Expand description
CSV writer for FuncSpace trees.
Emits one row per space (function, class, struct, unit, etc.),
flattened depth-first from the root. Each row carries the source
path, space name and kind, line range, and every leaf metric
value. The header order is fixed by CSV_HEADER so downstream
tools (Pandas, Excel, awk) can rely on positional access.
Empty / non-finite metric values render as empty CSV cells (not
0, not NaN) — f64::NAN and f64::INFINITY mean “not
applicable for this space” in the underlying metric structs, and
we keep that signal across the format boundary.
RFC 4180 quoting (commas, double-quotes, newlines in values) is
handled by the csv crate; nothing in this module hand-rolls
escaping.
If the source path is not valid UTF-8, the writer emits the
header row only (no data rows) and warns to stderr. There is no
useful fallback for the CSV path column, mirroring the
convention established by the Checkstyle writer.
Constants§
- CSV_
EXTENSION - File extension used when writing CSV output to a file path.
- CSV_
HEADER - Fixed column order for
write_csvoutput. Asserted by tests so downstream consumers can rely on positional access. Metric column names use dotted JSON-style paths (loc.lloc,halstead.volume) so a single name addresses the metric in both JSON and CSV.
Functions§
- defang_
formula - Defang a free-text CSV cell against formula injection (CWE-1236) by
prefixing a single quote when the cell begins with a spreadsheet
formula trigger (
=,+,-,@, tab, or carriage return), the OWASP-recommended mitigation. The quote makes a spreadsheet treat the whole cell as a literal string; the RFC 4180 quoting thecsvcrate applies does not defang formulas (a quoted"=cmd"still evaluates on import). Cells that do not start with a trigger — the overwhelming majority — are returned unchanged with no allocation beyond the ownedStringthe row requires. - write_
csv - Write a CSV document for the metric tree rooted at
space. Thesource_pathis recorded in thepathcolumn of every row; if it is not valid UTF-8 the entire document is skipped (header + zero rows) and a warning is emitted to stderr — there is no useful fallback for a CSV identifier. - write_
csv_ aggregate - Write multiple metric trees into ONE CSV document under a single shared header row.