Skip to main content

garbage_code_hunter/last_words/
mod.rs

1//! Code Last Words — find and report legacy TODO/FIXME/HACK comments.
2
3pub mod display;
4pub mod scanner;
5
6use crate::common::OutputFormat;
7use anyhow::Result;
8use std::path::Path;
9
10/// Run the last-words scan on a path.
11pub fn run(path: &Path, format: &OutputFormat, with_age: bool, lang: &str) -> Result<String> {
12    let mut words = scanner::scan(path);
13
14    // Optionally try to get ages via git blame (slower)
15    if with_age {
16        for word in &mut words {
17            word.age_days = scanner::try_get_age(&word.file, word.line);
18        }
19    }
20
21    let output = match format {
22        OutputFormat::Terminal => display::format_terminal(&words, lang),
23        OutputFormat::Json => display::format_json(&words),
24    };
25
26    Ok(output)
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32
33    #[test]
34    fn test_run_on_temp_dir() {
35        let dir = std::env::temp_dir().join("gch_lw_test");
36        let _ = std::fs::create_dir_all(&dir);
37        let file = dir.join("test.rs");
38        std::fs::write(&file, "// TODO: test\nfn main() {}\n").unwrap();
39
40        let result = run(&dir, &OutputFormat::Terminal, false, "en-US");
41        assert!(result.is_ok());
42        assert!(result.unwrap().contains("TODO"));
43
44        let _ = std::fs::remove_dir_all(&dir);
45    }
46}