use forge::signal::compactor;
pub fn compress_mypy(raw: &str) -> String {
let cleaned = compactor::normalise(raw);
let out: Vec<&str> = cleaned
.lines()
.filter(|l| {
l.contains(": error:")
|| l.contains(": note:")
|| l.contains(": warning:")
|| l.starts_with("Found")
|| l.starts_with("Success:")
})
.collect();
if out.is_empty() {
cleaned
} else {
out.join("\n")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn mypy_keeps_errors_and_summary() {
let raw = "foo.py:5: error: Incompatible types\nfoo.py:10: note: See above\nFound 1 error in 1 file (checked 3 source files)\n";
let out = compress_mypy(raw);
assert!(out.contains("Incompatible types"), "{out}");
assert!(out.contains("Found 1 error"), "{out}");
}
#[test]
fn mypy_keeps_success_line() {
let raw = "Success: no issues found in 5 source files\n";
let out = compress_mypy(raw);
assert!(out.contains("Success:"), "{out}");
}
}