mod csv;
mod excel;
mod json;
mod sarif;
use super::analyze::SuppressedViolation;
use super::manifest::RuleManifest;
use super::rules::RuleViolation;
use csv::export_all_violations_to_csv;
use excel::export_all_violations_to_excel;
use json::export_all_violations_to_json;
use sarif::export_all_violations_to_sarif;
use anyhow::Result;
pub fn export_all_violations(
violations: &[RuleViolation],
suppressed: &[SuppressedViolation],
export_path: &str,
_manifest: &RuleManifest,
) -> Result<()> {
use std::path::Path;
let path = Path::new(export_path);
if export_path.ends_with(".sarif.json") {
return export_all_violations_to_sarif(violations, suppressed, export_path);
}
if let Some(extension) = path.extension() {
match extension.to_str() {
Some("xlsx") => export_all_violations_to_excel(violations, export_path, _manifest),
Some("csv") => export_all_violations_to_csv(violations, export_path, _manifest),
Some("json") => export_all_violations_to_json(violations, export_path),
Some("sarif") => export_all_violations_to_sarif(violations, suppressed, export_path),
_ => {
export_all_violations_to_excel(violations, export_path, _manifest)
}
}
} else {
export_all_violations_to_excel(violations, export_path, _manifest)
}
}