Skip to main content

normalize_native_rules/
ratchet.rs

1//! Native rule integration for the ratchet system.
2//!
3//! Delegates to `normalize_ratchet::service::build_ratchet_diagnostics`.
4
5use normalize_output::OutputFormatter;
6use normalize_output::diagnostics::DiagnosticsReport;
7use serde::Serialize;
8use std::path::Path;
9
10/// Report returned by the ratchet native rule check.
11///
12/// Wraps the `DiagnosticsReport` produced by the ratchet service so that it
13/// can be formatted standalone (as text) or converted to a `DiagnosticsReport`
14/// for the rules engine.
15#[derive(Debug, Serialize, schemars::JsonSchema)]
16pub struct RatchetRulesReport(pub DiagnosticsReport);
17
18impl OutputFormatter for RatchetRulesReport {
19    fn format_text(&self) -> String {
20        self.0.format_text()
21    }
22
23    fn format_pretty(&self) -> String {
24        self.0.format_pretty()
25    }
26}
27
28impl From<RatchetRulesReport> for DiagnosticsReport {
29    fn from(report: RatchetRulesReport) -> Self {
30        report.0
31    }
32}
33
34/// Build a RatchetRulesReport from the ratchet baseline check.
35///
36/// Called by the native rules engine. Returns an empty report if no baseline
37/// exists or the check succeeds.
38pub fn build_ratchet_report(root: &Path) -> RatchetRulesReport {
39    let factory: normalize_ratchet::MetricFactory = normalize_ratchet::default_metrics;
40    RatchetRulesReport(normalize_ratchet::service::build_ratchet_report(
41        root, &factory,
42    ))
43}