use std::io::Write;
use anyhow::Result;
use crate::cli::lint_docs::{Gating, LintOutcome};
use crate::cli::render::{finding_line, write_failures, write_suggestion};
pub fn render(outcome: &LintOutcome) -> Result<()> {
render_to(&mut std::io::stdout().lock(), outcome)
}
pub fn render_to<W: Write>(out: &mut W, outcome: &LintOutcome) -> Result<()> {
for finding in &outcome.findings {
writeln!(out, "{}", finding_line(None, finding))?;
write_suggestion(out, finding)?;
}
write_failures(out, &outcome.failures, !outcome.findings.is_empty())?;
if outcome.findings.is_empty() && outcome.failures.is_empty() {
writeln!(out, "No issues found.")?;
return Ok(());
}
if !outcome.findings.is_empty() {
writeln!(out)?;
let count = outcome.findings.len();
match outcome.gating {
Gating::ReportOnly => writeln!(
out,
"{count} issue(s) found (report only; pass --strict to fail)."
)?,
Gating::NoneReached(threshold) => writeln!(
out,
"{count} issue(s) found (none at or above {}).",
threshold.as_str()
)?,
Gating::Blocked => writeln!(out, "{count} issue(s) found.")?,
}
}
Ok(())
}