From d43978817f0b18936d29eeead3d39c3dc9d22a93 Mon Sep 17 00:00:00 2001 From: b4prog Date: Sat, 27 Jun 2026 15:53:56 +0200 Subject: [PATCH 1/2] [chore] bump CodeM8 version to 0.7.2 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e0b0d7c..b26e7af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -113,7 +113,7 @@ checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" [[package]] name = "codem8" -version = "0.7.1" +version = "0.7.2" dependencies = [ "clap", "ignore", diff --git a/Cargo.toml b/Cargo.toml index ae70ba3..93b14b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "codem8" -version = "0.7.1" +version = "0.7.2" edition = "2021" rust-version = "1.85" license = "MIT" From 7cb022b9d1c6fb80f46985a295522364610e7ac4 Mon Sep 17 00:00:00 2001 From: b4prog Date: Sat, 27 Jun 2026 16:24:01 +0200 Subject: [PATCH 2/2] [fix] report duplicate files considered for branch scope --- src/lib.rs | 28 +++++++++++----------- src/report/duplicate_renderer.rs | 40 ++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 91e5f35..f06425c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ where .write_all(cli::help_text().as_bytes()) .map_err(|error| CodeM8Error::new(format!("could not write help output: {error}")))?, cli::CliCommand::ReportDuplicate(config) => { - let should_report_scanned_files = config.git_branch || config.files.is_some(); + let should_report_analyzed_files = config.git_branch || config.files.is_some(); let git_branch_files = if config.git_branch { Some(discovery::changed_files_against_origin(current_dir)?) } else { @@ -61,12 +61,12 @@ where report::detect_duplicate_blocks(&duplicate_source_files) }); let report = report::DuplicateReport { - analyzed_files: source_files.len(), + analyzed_files: duplicate_source_files.len(), analyzed_extensions: config.file_extensions, - scanned_files: should_report_scanned_files.then(|| { - source_files + analyzed_file_paths: should_report_analyzed_files.then(|| { + duplicate_source_files .iter() - .map(|source_file| source_file.display_path.clone()) + .map(|processed_file| processed_file.source.display_path.clone()) .collect() }), timings: match ( @@ -272,7 +272,7 @@ mod tests { "Duplicate Code Report\n", "=====================\n", "\n", - "Number of files scanned: 2\n", + "Number of files analyzed: 2\n", "Analyzed extensions: ", &expected_extensions, "\n", @@ -320,26 +320,26 @@ mod tests { project.write("src/b.ts", "const value = one;\n"); let output = run_in(&project, &["--report-duplicate", "-files=src/a.ts"]).expect("report succeeds"); - assert!(output.contains("Number of files scanned: 1")); + assert!(output.contains("Number of files analyzed: 1")); assert!(output.contains("Duplicate blocks found: 0")); } #[test] - fn verbose_explicit_files_report_lists_scanned_files() { + fn verbose_explicit_files_report_lists_analyzed_files() { let project = TempProject::new("verbose-explicit-files"); project.write("src/a.ts", "const value = one;\n"); project.write("src/b.ts", "const value = one;\n"); let quiet_output = run_in(&project, &["--report-duplicate", "-files=src/a.ts"]).expect("report succeeds"); - assert!(!quiet_output.contains("Files scanned:")); + assert!(!quiet_output.contains("Files analyzed:")); let verbose_output = run_in( &project, &["--report-duplicate", "-verbose", "-files=src/a.ts"], ) .expect("report succeeds"); assert!(verbose_output.contains( - "Number of files scanned: 1\n\ - Files scanned:\n\ + "Number of files analyzed: 1\n\ + Files analyzed:\n\ - src/a.ts\n\ Analyzed extensions:" )); @@ -351,11 +351,11 @@ mod tests { project.write("src/a.js", "const value = one;\n"); project.write("src/b.js", "const value = one;\n"); let default_output = run_in(&project, &["--report-duplicate"]).expect("report succeeds"); - assert!(default_output.contains("Number of files scanned: 2")); + assert!(default_output.contains("Number of files analyzed: 2")); assert!(default_output.contains("Duplicate blocks found: 1")); let js_output = run_in(&project, &["--report-duplicate", "-file-extension=js"]) .expect("report succeeds"); - assert!(js_output.contains("Number of files scanned: 2")); + assert!(js_output.contains("Number of files analyzed: 2")); assert!(js_output.contains("Duplicate blocks found: 1")); } @@ -374,7 +374,7 @@ mod tests { project.write("src/a.ts", "const shared = 1;\n"); let output = run_in(&project, &["--report-duplicate", "-git-branch"]).expect("report succeeds"); - assert!(output.contains("Number of files scanned: 2")); + assert!(output.contains("Number of files analyzed: 1")); assert!(output.contains("Duplicate blocks found: 0")); } diff --git a/src/report/duplicate_renderer.rs b/src/report/duplicate_renderer.rs index 06d8901..acb9d37 100644 --- a/src/report/duplicate_renderer.rs +++ b/src/report/duplicate_renderer.rs @@ -9,7 +9,7 @@ use crate::paths::format_path; pub struct DuplicateReport { pub analyzed_files: usize, pub analyzed_extensions: Vec, - pub scanned_files: Option>, + pub analyzed_file_paths: Option>, pub timings: Option, pub duplicate_blocks: Vec, } @@ -26,15 +26,19 @@ pub fn render_duplicate_report(report: &DuplicateReport, verbose: bool) -> Strin let mut output = String::new(); output.push_str("Duplicate Code Report\n"); output.push_str("=====================\n\n"); - let _ = writeln!(output, "Number of files scanned: {}", report.analyzed_files); - let scanned_files = if verbose { - report.scanned_files.as_ref() + let _ = writeln!( + output, + "Number of files analyzed: {}", + report.analyzed_files + ); + let analyzed_file_paths = if verbose { + report.analyzed_file_paths.as_ref() } else { None }; - if let Some(scanned_files) = scanned_files { - output.push_str("Files scanned:\n"); - for file in scanned_files { + if let Some(analyzed_file_paths) = analyzed_file_paths { + output.push_str("Files analyzed:\n"); + for file in analyzed_file_paths { let _ = writeln!(output, "- {}", format_path(file)); } } @@ -124,7 +128,7 @@ mod tests { let report = DuplicateReport { analyzed_files: 0, analyzed_extensions: vec!["ts".to_string()], - scanned_files: None, + analyzed_file_paths: None, timings: None, duplicate_blocks: Vec::new(), }; @@ -133,7 +137,7 @@ mod tests { "Duplicate Code Report\n\ =====================\n\ \n\ - Number of files scanned: 0\n\ + Number of files analyzed: 0\n\ Analyzed extensions: ts\n\ Duplicate blocks found: 0\n" ); @@ -144,7 +148,7 @@ mod tests { let report = DuplicateReport { analyzed_files: 2, analyzed_extensions: vec!["ts".to_string(), "js".to_string()], - scanned_files: None, + analyzed_file_paths: None, timings: None, duplicate_blocks: vec![DuplicateBlock { normalized_lines: vec!["return value;".to_string()], @@ -181,7 +185,7 @@ mod tests { let report = DuplicateReport { analyzed_files: 0, analyzed_extensions: vec!["ts".to_string(), "js".to_string(), "rs".to_string()], - scanned_files: None, + analyzed_file_paths: None, timings: None, duplicate_blocks: Vec::new(), }; @@ -194,7 +198,7 @@ mod tests { let report = DuplicateReport { analyzed_files: 2, analyzed_extensions: vec!["ts".to_string()], - scanned_files: None, + analyzed_file_paths: None, timings: None, duplicate_blocks: vec![DuplicateBlock { normalized_lines: vec!["return value;".to_string()], @@ -224,11 +228,11 @@ mod tests { } #[test] - fn renders_scanned_file_list_only_in_verbose_mode() { + fn renders_analyzed_file_list_only_in_verbose_mode() { let report = DuplicateReport { analyzed_files: 2, analyzed_extensions: vec!["ts".to_string()], - scanned_files: Some(vec![ + analyzed_file_paths: Some(vec![ PathBuf::from("src/a.ts"), PathBuf::from("src/nested/b.ts"), ]), @@ -236,11 +240,11 @@ mod tests { duplicate_blocks: Vec::new(), }; let quiet_output = render_duplicate_report(&report, false); - assert!(!quiet_output.contains("Files scanned:")); + assert!(!quiet_output.contains("Files analyzed:")); let verbose_output = render_duplicate_report(&report, true); assert!(verbose_output.contains( - "Number of files scanned: 2\n\ - Files scanned:\n\ + "Number of files analyzed: 2\n\ + Files analyzed:\n\ - src/a.ts\n\ - src/nested/b.ts\n\ Analyzed extensions: ts" @@ -252,7 +256,7 @@ mod tests { let report = DuplicateReport { analyzed_files: 1, analyzed_extensions: vec!["ts".to_string()], - scanned_files: None, + analyzed_file_paths: None, timings: Some(DuplicateReportTimings { discovery: Duration::from_micros(1_234), file_processing: Duration::from_micros(12_345),