use normalize_facts_rules_api::Diagnostic;
pub fn format_diagnostic(diag: &Diagnostic, use_colors: bool) -> String {
use normalize_facts_rules_api::DiagnosticLevel;
let level_str = match diag.level {
DiagnosticLevel::Hint => {
if use_colors {
"\x1b[36mhint\x1b[0m"
} else {
"hint"
}
}
DiagnosticLevel::Warning => {
if use_colors {
"\x1b[33mwarning\x1b[0m"
} else {
"warning"
}
}
DiagnosticLevel::Error => {
if use_colors {
"\x1b[31merror\x1b[0m"
} else {
"error"
}
}
};
let mut out = String::new();
if let Some(ref loc) = diag.location {
out.push_str(&format!("{}:{}: ", loc.file, loc.line));
}
out.push_str(&format!("{} [{}]: ", level_str, diag.rule_id));
out.push_str(&diag.message);
for related in diag.related.iter() {
out.push_str(&format!("\n --> {}:{}", related.file, related.line));
}
if let Some(ref suggestion) = diag.suggestion {
out.push_str(&format!("\n suggestion: {}", suggestion));
}
out
}