Skip to content

Commit 1f99a38

Browse files
committed
refactor: replace CLI summary lines with structured output
Replace the single-line "Found X violation(s) in Y file(s)..." format with a structured multi-line summary that separately reports all relevant metrics: files scanned, files with findings, total findings, rules evaluated, rules with matches, and sub-second duration. This removes the ambiguity where "in Y file(s)" could mean either total files scanned or files with at least one finding, and provides both values explicitly.
1 parent b118e6e commit 1f99a38

1 file changed

Lines changed: 27 additions & 23 deletions

File tree

crates/bins/src/bin/datadog-static-analyzer.rs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -584,25 +584,27 @@ fn main() -> Result<()> {
584584

585585
let static_analysis_metadata = &execution_result.metadata;
586586

587-
let number_of_rules_used = rules_results
587+
let files_with_violations = rules_results
588588
.iter()
589-
.unique_by(|v| v.rule_name.as_str())
589+
.unique_by(|v| v.filename.as_str())
590590
.count();
591591

592-
let total_files_analyzed = rules_results
592+
let rules_with_matches = rules_results
593593
.iter()
594-
.unique_by(|v| v.filename.as_str())
594+
.unique_by(|v| v.rule_name.as_str())
595595
.count();
596596

597+
let sa_duration = static_analysis_start.elapsed().as_secs_f64();
598+
597599
all_path_metadata.extend(static_analysis_metadata.clone());
598600

599-
println!(
600-
"Found {} violation(s) in {} file(s) using {} rule(s) within {} sec(s)",
601-
nb_violations,
602-
total_files_analyzed,
603-
number_of_rules_used,
604-
static_analysis_start.elapsed().as_secs()
605-
);
601+
println!("Static Analysis Summary");
602+
println!(" Files scanned: {}", files_to_analyze.len());
603+
println!(" Files with violations: {}", files_with_violations);
604+
println!(" Total violations: {}", nb_violations);
605+
println!(" Rules evaluated: {}", configuration.rules.len());
606+
println!(" Rules with matches: {}", rules_with_matches);
607+
println!(" Duration: {:.3}s", sa_duration);
606608

607609
result.static_analysis = Some(execution_result);
608610
}
@@ -644,24 +646,26 @@ fn main() -> Result<()> {
644646
}
645647
}
646648

647-
let number_of_rules_used = secrets_rules_results
649+
let files_with_secrets = secrets_rules_results
648650
.iter()
649-
.unique_by(|v| v.rule_name.as_str())
651+
.unique_by(|v| v.filename.as_str())
650652
.count();
651653

652-
let total_files_analyzed = secrets_rules_results
654+
let rules_with_matches = secrets_rules_results
653655
.iter()
654-
.unique_by(|v| v.filename.as_str())
656+
.unique_by(|v| v.rule_name.as_str())
655657
.count();
656658

657-
println!(
658-
"Found {} secret(s) (including {} valid) in {} file(s) using {} rule(s) within {} sec(s)",
659-
nb_secrets_found,
660-
nb_secrets_validated,
661-
total_files_analyzed,
662-
number_of_rules_used,
663-
secrets_start.elapsed().as_secs()
664-
);
659+
let secrets_duration = secrets_start.elapsed().as_secs_f64();
660+
661+
println!("Secrets Summary");
662+
println!(" Files scanned: {}", secrets_files.len());
663+
println!(" Files with secrets: {}", files_with_secrets);
664+
println!(" Total secrets: {}", nb_secrets_found);
665+
println!(" Valid secrets: {}", nb_secrets_validated);
666+
println!(" Rules evaluated: {}", configuration.secrets_rules.len());
667+
println!(" Rules with matches: {}", rules_with_matches);
668+
println!(" Duration: {:.3}s", secrets_duration);
665669

666670
result.secrets = Some(execution_results);
667671
}

0 commit comments

Comments
 (0)