Skip to main content

marque_engine/
output.rs

1//! Output types returned by the engine's synchronous API surface.
2
3use marque_rules::{AppliedFix, Diagnostic};
4
5/// Result of a lint pass — diagnostics without source modification.
6#[derive(Debug, Default)]
7pub struct LintResult {
8    pub diagnostics: Vec<Diagnostic>,
9}
10
11impl LintResult {
12    pub fn is_clean(&self) -> bool {
13        self.diagnostics.is_empty()
14    }
15
16    pub fn error_count(&self) -> usize {
17        use marque_rules::Severity;
18        self.diagnostics
19            .iter()
20            .filter(|d| d.severity == Severity::Error)
21            .count()
22    }
23
24    pub fn warn_count(&self) -> usize {
25        use marque_rules::Severity;
26        self.diagnostics
27            .iter()
28            .filter(|d| d.severity == Severity::Warn)
29            .count()
30    }
31
32    /// Number of diagnostics that are configured at `Severity::Fix` AND
33    /// carry an actual `FixProposal`. A diagnostic at `Fix` severity but
34    /// with `fix: None` is not counted, since it cannot produce an
35    /// `AppliedFix` downstream.
36    pub fn fix_count(&self) -> usize {
37        use marque_rules::Severity;
38        self.diagnostics
39            .iter()
40            .filter(|d| d.severity == Severity::Fix && d.fix.is_some())
41            .count()
42    }
43}
44
45/// Result of a fix pass — modified source and audit trail.
46#[derive(Debug)]
47pub struct FixResult {
48    /// Fixed source bytes. Preserves UTF-8 validity: the input is UTF-8, and every
49    /// replacement is a valid UTF-8 `String`, so the result is always valid UTF-8.
50    pub source: Vec<u8>,
51    /// Audit records for every fix that was applied.
52    pub applied: Vec<AppliedFix>,
53    /// Diagnostics that could not be auto-fixed (below confidence threshold,
54    /// or require human judgment).
55    pub remaining_diagnostics: Vec<Diagnostic>,
56}