Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "codem8"
version = "0.7.4"
version = "0.7.5"
edition = "2021"
rust-version = "1.85"
license = "MIT"
Expand Down
6 changes: 0 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,19 +576,13 @@ mod tests {
"const value = computeValue(input);\nif (value === undefined) {\nreturn defaultValue;\n}\n",
);
let output = run_in(&project, &["--report-duplicate"]).expect("report succeeds");
let mut expected_extensions = language::supported_file_extensions();
expected_extensions.sort();
let expected_extensions = expected_extensions.join(", ");
assert_eq!(
output,
[
"Duplicate Code Report\n",
"=====================\n",
"\n",
"Number of files analyzed: 2\n",
"Analyzed extensions: ",
&expected_extensions,
"\n",
"Duplicate blocks found: 1\n",
"\n",
"#1\n",
Expand Down
40 changes: 22 additions & 18 deletions src/report/complexity_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,8 @@ pub fn render_complexity_report(report: &ComplexityReport, verbose: bool) -> Str
);
if verbose {
render_analyzed_files(&mut output, report.analyzed_file_paths.as_deref());
render_verbose_summary(&mut output, report);
}
let _ = writeln!(
output,
"Analyzed extensions: {}",
sorted_extensions(&report.analyzed_extensions).join(", ")
);
let _ = writeln!(
output,
"Max cognitive complexity: {}",
report.max_cognitive_complexity
);
let _ = writeln!(
output,
"Max cyclomatic complexity: {}",
report.max_cyclomatic_complexity
);
let _ = writeln!(
output,
"Functions exceeding limits: {}",
Expand Down Expand Up @@ -82,6 +68,24 @@ pub fn render_complexity_report(report: &ComplexityReport, verbose: bool) -> Str
output
}

fn render_verbose_summary(output: &mut String, report: &ComplexityReport) {
let _ = writeln!(
output,
"Analyzed extensions: {}",
sorted_extensions(&report.analyzed_extensions).join(", ")
);
let _ = writeln!(
output,
"Max cognitive complexity: {}",
report.max_cognitive_complexity
);
let _ = writeln!(
output,
"Max cyclomatic complexity: {}",
report.max_cyclomatic_complexity
);
}

fn render_analyzed_files(output: &mut String, analyzed_file_paths: Option<&[AnalyzedFile]>) {
if let Some(analyzed_file_paths) = analyzed_file_paths {
output.push_str("Files analyzed:\n");
Expand Down Expand Up @@ -181,9 +185,6 @@ mod tests {
=================\n\
\n\
Number of files analyzed: 0\n\
Analyzed extensions: rs\n\
Max cognitive complexity: 15\n\
Max cyclomatic complexity: 10\n\
Functions exceeding limits: 0\n"
);
}
Expand Down Expand Up @@ -233,6 +234,9 @@ mod tests {
};
let output = render_complexity_report(&report, true);
assert!(output.contains("Files analyzed:\n- src/lib.rs\n"));
assert!(output.contains("Analyzed extensions: rs\n"));
assert!(output.contains("Max cognitive complexity: 15\n"));
assert!(output.contains("Max cyclomatic complexity: 10\n"));
assert!(output.contains("- Discovery: 1.234 ms\n"));
assert!(output.contains("- Complexity analysis: 12.345 ms\n"));
}
Expand Down
21 changes: 14 additions & 7 deletions src/report/duplicate_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ fn render_report_summary(output: &mut String, report: &DuplicateReport, verbose:
output.push_str("Files analyzed:\n");
render_analyzed_files(output, analyzed_file_paths);
}
let _ = writeln!(
output,
"Analyzed extensions: {}",
sorted_extensions(&report.analyzed_extensions).join(", ")
);
if verbose {
render_verbose_summary(output, report);
}
let _ = writeln!(
output,
"Duplicate blocks found: {}",
Expand All @@ -60,6 +58,14 @@ fn render_report_summary(output: &mut String, report: &DuplicateReport, verbose:
}
}

fn render_verbose_summary(output: &mut String, report: &DuplicateReport) {
let _ = writeln!(
output,
"Analyzed extensions: {}",
sorted_extensions(&report.analyzed_extensions).join(", ")
);
}

fn render_analyzed_files(output: &mut String, analyzed_file_paths: &[AnalyzedFile]) {
for file in analyzed_file_paths {
let _ = writeln!(output, "- {}", format_analyzed_file(file));
Expand Down Expand Up @@ -190,7 +196,6 @@ mod tests {
=====================\n\
\n\
Number of files analyzed: 0\n\
Analyzed extensions: ts\n\
Duplicate blocks found: 0\n"
);
}
Expand Down Expand Up @@ -242,7 +247,9 @@ mod tests {
duplicate_blocks: Vec::new(),
};
let output = render_duplicate_report(&report, false);
assert!(output.contains("Analyzed extensions: js, rs, ts\n"));
assert!(!output.contains("Analyzed extensions:"));
let verbose_output = render_duplicate_report(&report, true);
assert!(verbose_output.contains("Analyzed extensions: js, rs, ts\n"));
}

#[test]
Expand Down
Loading