Skip to content

Commit 28c49a5

Browse files
refactor(audit): reduce complexity of render_console in console.rs (#1053)
Replace 19 repetitive `if let Some(section) = ...; sections.push(section)` blocks with a single `sections.extend([...].into_iter().flatten())` call. Cognitive complexity: 20 → below 15 (zero Clippy warnings at threshold=15). Behaviour is identical — optional sections are still omitted when their render helper returns `None`. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c752f81 commit 28c49a5

1 file changed

Lines changed: 25 additions & 59 deletions

File tree

src/audit/render/console.rs

Lines changed: 25 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,65 +21,31 @@ pub fn render_console(audit: &crate::audit::model::AuditData) -> String {
2121
render_metrics_section(&audit.metrics, audit.performance_metrics.as_ref()),
2222
];
2323

24-
if let Some(section) = render_key_findings_section(&audit.key_findings) {
25-
sections.push(section);
26-
}
27-
if let Some(section) = render_recommendations_section(&audit.recommendations) {
28-
sections.push(section);
29-
}
30-
if let Some(section) = render_safe_output_summary_section(audit.safe_output_summary.as_ref()) {
31-
sections.push(section);
32-
}
33-
if let Some(section) =
34-
render_rejected_safe_outputs_section(audit.rejected_safe_outputs.as_ref())
35-
{
36-
sections.push(section);
37-
}
38-
if let Some(section) = render_mcp_server_health_section(audit.mcp_server_health.as_ref()) {
39-
sections.push(section);
40-
}
41-
if let Some(section) = render_firewall_analysis_section(audit.firewall_analysis.as_ref()) {
42-
sections.push(section);
43-
}
44-
if let Some(section) = render_policy_analysis_section(audit.policy_analysis.as_ref()) {
45-
sections.push(section);
46-
}
47-
if let Some(section) = render_detection_analysis_section(audit.detection_analysis.as_ref()) {
48-
sections.push(section);
49-
}
50-
if let Some(section) = render_jobs_section(&audit.jobs) {
51-
sections.push(section);
52-
}
53-
if let Some(section) = render_downloaded_files_section(&audit.downloaded_files) {
54-
sections.push(section);
55-
}
56-
if let Some(section) = render_missing_tools_section(&audit.missing_tools) {
57-
sections.push(section);
58-
}
59-
if let Some(section) = render_missing_data_section(&audit.missing_data) {
60-
sections.push(section);
61-
}
62-
if let Some(section) = render_noops_section(&audit.noops) {
63-
sections.push(section);
64-
}
65-
if let Some(section) = render_mcp_failures_section(&audit.mcp_failures) {
66-
sections.push(section);
67-
}
68-
if let Some(section) = render_errors_section(&audit.errors) {
69-
sections.push(section);
70-
}
71-
if let Some(section) = render_warnings_section(&audit.warnings) {
72-
sections.push(section);
73-
}
74-
if let Some(section) = render_tool_usage_section(&audit.tool_usage) {
75-
sections.push(section);
76-
}
77-
if let Some(section) = render_mcp_tool_usage_section(audit.mcp_tool_usage.as_ref()) {
78-
sections.push(section);
79-
}
80-
if let Some(section) = render_created_items_section(&audit.created_items) {
81-
sections.push(section);
82-
}
24+
sections.extend(
25+
[
26+
render_key_findings_section(&audit.key_findings),
27+
render_recommendations_section(&audit.recommendations),
28+
render_safe_output_summary_section(audit.safe_output_summary.as_ref()),
29+
render_rejected_safe_outputs_section(audit.rejected_safe_outputs.as_ref()),
30+
render_mcp_server_health_section(audit.mcp_server_health.as_ref()),
31+
render_firewall_analysis_section(audit.firewall_analysis.as_ref()),
32+
render_policy_analysis_section(audit.policy_analysis.as_ref()),
33+
render_detection_analysis_section(audit.detection_analysis.as_ref()),
34+
render_jobs_section(&audit.jobs),
35+
render_downloaded_files_section(&audit.downloaded_files),
36+
render_missing_tools_section(&audit.missing_tools),
37+
render_missing_data_section(&audit.missing_data),
38+
render_noops_section(&audit.noops),
39+
render_mcp_failures_section(&audit.mcp_failures),
40+
render_errors_section(&audit.errors),
41+
render_warnings_section(&audit.warnings),
42+
render_tool_usage_section(&audit.tool_usage),
43+
render_mcp_tool_usage_section(audit.mcp_tool_usage.as_ref()),
44+
render_created_items_section(&audit.created_items),
45+
]
46+
.into_iter()
47+
.flatten(),
48+
);
8349

8450
let mut out = sections.join("\n\n");
8551
out.push('\n');

0 commit comments

Comments
 (0)