Skip to content

Commit 3a32e51

Browse files
authored
[fix] hide report metadata outside verbose mode (#12)
1 parent 163b78c commit 3a32e51

5 files changed

Lines changed: 38 additions & 33 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "codem8"
3-
version = "0.7.4"
3+
version = "0.7.5"
44
edition = "2021"
55
rust-version = "1.85"
66
license = "MIT"

‎src/lib.rs‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -576,19 +576,13 @@ mod tests {
576576
"const value = computeValue(input);\nif (value === undefined) {\nreturn defaultValue;\n}\n",
577577
);
578578
let output = run_in(&project, &["--report-duplicate"]).expect("report succeeds");
579-
let mut expected_extensions = language::supported_file_extensions();
580-
expected_extensions.sort();
581-
let expected_extensions = expected_extensions.join(", ");
582579
assert_eq!(
583580
output,
584581
[
585582
"Duplicate Code Report\n",
586583
"=====================\n",
587584
"\n",
588585
"Number of files analyzed: 2\n",
589-
"Analyzed extensions: ",
590-
&expected_extensions,
591-
"\n",
592586
"Duplicate blocks found: 1\n",
593587
"\n",
594588
"#1\n",

‎src/report/complexity_renderer.rs‎

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,8 @@ pub fn render_complexity_report(report: &ComplexityReport, verbose: bool) -> Str
3333
);
3434
if verbose {
3535
render_analyzed_files(&mut output, report.analyzed_file_paths.as_deref());
36+
render_verbose_summary(&mut output, report);
3637
}
37-
let _ = writeln!(
38-
output,
39-
"Analyzed extensions: {}",
40-
sorted_extensions(&report.analyzed_extensions).join(", ")
41-
);
42-
let _ = writeln!(
43-
output,
44-
"Max cognitive complexity: {}",
45-
report.max_cognitive_complexity
46-
);
47-
let _ = writeln!(
48-
output,
49-
"Max cyclomatic complexity: {}",
50-
report.max_cyclomatic_complexity
51-
);
5238
let _ = writeln!(
5339
output,
5440
"Functions exceeding limits: {}",
@@ -82,6 +68,24 @@ pub fn render_complexity_report(report: &ComplexityReport, verbose: bool) -> Str
8268
output
8369
}
8470

71+
fn render_verbose_summary(output: &mut String, report: &ComplexityReport) {
72+
let _ = writeln!(
73+
output,
74+
"Analyzed extensions: {}",
75+
sorted_extensions(&report.analyzed_extensions).join(", ")
76+
);
77+
let _ = writeln!(
78+
output,
79+
"Max cognitive complexity: {}",
80+
report.max_cognitive_complexity
81+
);
82+
let _ = writeln!(
83+
output,
84+
"Max cyclomatic complexity: {}",
85+
report.max_cyclomatic_complexity
86+
);
87+
}
88+
8589
fn render_analyzed_files(output: &mut String, analyzed_file_paths: Option<&[AnalyzedFile]>) {
8690
if let Some(analyzed_file_paths) = analyzed_file_paths {
8791
output.push_str("Files analyzed:\n");
@@ -181,9 +185,6 @@ mod tests {
181185
=================\n\
182186
\n\
183187
Number of files analyzed: 0\n\
184-
Analyzed extensions: rs\n\
185-
Max cognitive complexity: 15\n\
186-
Max cyclomatic complexity: 10\n\
187188
Functions exceeding limits: 0\n"
188189
);
189190
}
@@ -233,6 +234,9 @@ mod tests {
233234
};
234235
let output = render_complexity_report(&report, true);
235236
assert!(output.contains("Files analyzed:\n- src/lib.rs\n"));
237+
assert!(output.contains("Analyzed extensions: rs\n"));
238+
assert!(output.contains("Max cognitive complexity: 15\n"));
239+
assert!(output.contains("Max cyclomatic complexity: 10\n"));
236240
assert!(output.contains("- Discovery: 1.234 ms\n"));
237241
assert!(output.contains("- Complexity analysis: 12.345 ms\n"));
238242
}

‎src/report/duplicate_renderer.rs‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ fn render_report_summary(output: &mut String, report: &DuplicateReport, verbose:
4545
output.push_str("Files analyzed:\n");
4646
render_analyzed_files(output, analyzed_file_paths);
4747
}
48-
let _ = writeln!(
49-
output,
50-
"Analyzed extensions: {}",
51-
sorted_extensions(&report.analyzed_extensions).join(", ")
52-
);
48+
if verbose {
49+
render_verbose_summary(output, report);
50+
}
5351
let _ = writeln!(
5452
output,
5553
"Duplicate blocks found: {}",
@@ -60,6 +58,14 @@ fn render_report_summary(output: &mut String, report: &DuplicateReport, verbose:
6058
}
6159
}
6260

61+
fn render_verbose_summary(output: &mut String, report: &DuplicateReport) {
62+
let _ = writeln!(
63+
output,
64+
"Analyzed extensions: {}",
65+
sorted_extensions(&report.analyzed_extensions).join(", ")
66+
);
67+
}
68+
6369
fn render_analyzed_files(output: &mut String, analyzed_file_paths: &[AnalyzedFile]) {
6470
for file in analyzed_file_paths {
6571
let _ = writeln!(output, "- {}", format_analyzed_file(file));
@@ -190,7 +196,6 @@ mod tests {
190196
=====================\n\
191197
\n\
192198
Number of files analyzed: 0\n\
193-
Analyzed extensions: ts\n\
194199
Duplicate blocks found: 0\n"
195200
);
196201
}
@@ -242,7 +247,9 @@ mod tests {
242247
duplicate_blocks: Vec::new(),
243248
};
244249
let output = render_duplicate_report(&report, false);
245-
assert!(output.contains("Analyzed extensions: js, rs, ts\n"));
250+
assert!(!output.contains("Analyzed extensions:"));
251+
let verbose_output = render_duplicate_report(&report, true);
252+
assert!(verbose_output.contains("Analyzed extensions: js, rs, ts\n"));
246253
}
247254

248255
#[test]

0 commit comments

Comments
 (0)