//! JSONL output: one JSON object per line, one line per finding. //! //! This is the linter's only output format. oxlint ships ten //! (`default`, `agent`, `json`, `github`, `gitlab`, `unix`, `checkstyle`, //! `junit`, `sarif`, `stylish`) and none of them is JSONL, so this is a //! deliberate divergence rather than an unfinished part of the parity work. //! `doc/planning/rust-linter-oxlint-parity.md` records it under the known //! parity holes. /// Imports the serialization trait the record types derive. use serde::Serialize; /// Imports the finding record the renderer reads. use crate::diagnostic::Diagnostic; // What: `#[derive(Serialize)]` generates the code that turns this type into // JSON, the mirror of the `Deserialize` the config types derive. // Why: A typed record rather than an ad-hoc map. The field names ARE the // output format, so declaring them once as a struct means the shape // cannot drift between the renderer and whatever documents it, and // the compiler catches a renamed field instead of a consumer doing so // at run time. // // In TS you'd write (pseudocode): // ```ts // type Record = { message: string; code: string; /* ... */ }; // ``` /// One JSONL record, carrying oxlint's diagnostic field set. #[derive(Serialize)] struct Record<'a> { /// Human-readable explanation of the finding. message: &'a str, /// Reported code in oxlint's `plugin(rule)` form. code: String, /// Severity label, `error` or `warn`. severity: &'static str, // What: `causes: [&'a str; 0]` is a fixed-size array of length zero. // Why: oxlint emits `"causes": []` on every diagnostic, and a // zero-length array serializes to exactly that without allocating // a `Vec` per record just to be empty. /// Always empty; present because oxlint's shape carries it. causes: [&'a str; 0], /// File the finding is in. filename: &'a str, /// Source spans this finding points at. labels: Vec