1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! JSON output emitter for all analyses.
//!
//! Most analyses emit their rows directly via [`write_json`] — a single
//! generic over any `serde::Serialize` slice. The two exceptions are
//! `revisions` (whose `(String, u32)` tuple needs a struct wrapping for
//! named-field JSON output) and `communities` (whose output is a
//! wrapper struct carrying the row array plus partition-level summary
//! statistics, not the rows alone).
//!
//! CLI dispatch calls `write_json::<HotspotRow>(&rows, &mut out)`
//! directly with a turbofished row type — the same pattern the
//! `output::ndjson::write_ndjson` emitter uses. Per-analysis wrapper
//! shims (`write_hotspots_json`, `write_code_health_json`, etc.) were
//! retired in commit b2efe20's successor: 27 shims removed, 33 call
//! sites updated to use the generic.
use crateResult;
use Write;
/// Generic JSON emitter. Serialises any `serde::Serialize` slice as a
/// pretty-printed JSON array. The pretty form matches the historic
/// shape from the pre-shim era; downstream consumers that expect
/// stream-parseable single-row-per-line semantics should use
/// `--format ndjson` instead.
///
/// # Errors
///
/// Returns [`crate::CodeLoreError::Io`] when the output sink fails mid-write
/// (e.g. a reader closed the pipe early) and [`crate::CodeLoreError::Output`]
/// on a genuine serialisation fault.
/// `revisions` emitter — the tuple `(path, n_revs)` is serialised as a
/// named-field struct so JSON consumers see `{"entity": "...",
/// "n_revs": N}` rather than `["...", N]` (which would be the default
/// tuple serialisation).
///
/// # Errors
///
/// Returns [`crate::CodeLoreError::Io`] when the output sink fails mid-write
/// (e.g. a reader closed the pipe early) and [`crate::CodeLoreError::Output`]
/// on a genuine serialisation fault.
/// `communities` emitter — emits the wrapper struct (`rows` +
/// `modularity` + `community_count`), not just the row array — the
/// partition-level summary is the headline metric and JSON consumers
/// expect it alongside the per-file mapping.
///
/// # Errors
///
/// Returns [`crate::CodeLoreError::Io`] when the output sink fails mid-write
/// (e.g. a reader closed the pipe early) and [`crate::CodeLoreError::Output`]
/// on a genuine serialisation fault.