lean_ctx/core/patterns/
prettier.rs1pub fn compress(output: &str) -> Option<String> {
2 let trimmed = output.trim();
3 if trimmed.is_empty() {
4 return Some("ok (formatted)".to_string());
5 }
6
7 if trimmed.contains("All matched files use Prettier code style") {
8 return Some("ok (all formatted)".to_string());
9 }
10
11 let unformatted: Vec<&str> = trimmed
12 .lines()
13 .filter(|l| {
14 let t = l.trim();
15 !t.is_empty()
16 && !t.starts_with("Checking")
17 && !t.starts_with("All matched")
18 && !t.contains("[warn]")
19 && !t.contains("[error]")
20 && t.contains('.')
21 })
22 .collect();
23
24 let warnings: Vec<&str> = trimmed.lines().filter(|l| l.contains("[warn]")).collect();
25
26 if !unformatted.is_empty() {
27 let files: Vec<String> = unformatted.iter().map(|l| l.trim().to_string()).collect();
28 return Some(format!(
29 "{} files need formatting:\n{}",
30 files.len(),
31 files.join("\n")
32 ));
33 }
34
35 if !warnings.is_empty() {
36 return Some(format!("{} warnings", warnings.len()));
37 }
38
39 if trimmed.lines().count() <= 5 {
40 return Some(trimmed.to_string());
41 }
42
43 let lines: Vec<&str> = trimmed.lines().collect();
44 Some(format!(
45 "{}\n... ({} more lines)",
46 lines[..5].join("\n"),
47 lines.len() - 5
48 ))
49}