normalize_rules/
loader.rs1use normalize_facts_rules_api::Diagnostic;
7
8pub fn format_diagnostic(diag: &Diagnostic, use_colors: bool) -> String {
10 use normalize_facts_rules_api::DiagnosticLevel;
11
12 let level_str = match diag.level {
13 DiagnosticLevel::Hint => {
14 if use_colors {
15 "\x1b[36mhint\x1b[0m"
16 } else {
17 "hint"
18 }
19 }
20 DiagnosticLevel::Warning => {
21 if use_colors {
22 "\x1b[33mwarning\x1b[0m"
23 } else {
24 "warning"
25 }
26 }
27 DiagnosticLevel::Error => {
28 if use_colors {
29 "\x1b[31merror\x1b[0m"
30 } else {
31 "error"
32 }
33 }
34 };
35
36 let mut out = String::new();
37
38 if let Some(ref loc) = diag.location {
40 out.push_str(&format!("{}:{}: ", loc.file, loc.line));
41 }
42
43 out.push_str(&format!("{} [{}]: ", level_str, diag.rule_id));
45
46 out.push_str(&diag.message);
48
49 for related in diag.related.iter() {
51 out.push_str(&format!("\n --> {}:{}", related.file, related.line));
52 }
53
54 if let Some(ref suggestion) = diag.suggestion {
56 out.push_str(&format!("\n suggestion: {}", suggestion));
57 }
58
59 out
60}