Skip to main content

Module csv

Module csv 

Source
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_csv output. 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§

write_csv
Write a CSV document for the metric tree rooted at space. The source_path is recorded in the path column 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.