-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
89 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::fs::File; | ||
|
||
use chrono::Utc; | ||
use itertools::chain; | ||
|
||
use crate::packs::bin_locater; | ||
|
||
use super::checker::CheckAllResult; | ||
|
||
pub fn write_csv(result: &CheckAllResult) -> anyhow::Result<()> { | ||
if !&result.reportable_violations.is_empty() | ||
|| !&result.strict_mode_violations.is_empty() | ||
{ | ||
let utc = Utc::now().naive_utc().to_string().replace(' ', ""); | ||
let reportable_file = format!("{}-violations.csv", utc); | ||
let file = File::create(&reportable_file)?; | ||
let mut wtr = csv::Writer::from_writer(file); | ||
|
||
let all = chain!( | ||
&result.reportable_violations, | ||
&result.strict_mode_violations | ||
); | ||
wtr.write_record([ | ||
"Violation", | ||
"Strict?", | ||
"File", | ||
"Constant", | ||
"Referencing Pack", | ||
"Defining Pack", | ||
"Message", | ||
])?; | ||
for violation in all { | ||
let identifier = &violation.identifier; | ||
wtr.serialize(( | ||
&identifier.violation_type, | ||
&identifier.strict, | ||
&identifier.file, | ||
&identifier.constant_name, | ||
&identifier.referencing_pack_name, | ||
&identifier.defining_pack_name, | ||
&violation.message, | ||
))?; | ||
} | ||
wtr.flush()?; | ||
|
||
println!("Violations written to '{}'", &reportable_file); | ||
} | ||
|
||
if !&result.stale_violations.is_empty() { | ||
println!( | ||
"There were stale violations found, please run `{} update`", | ||
bin_locater::packs_bin_name(), | ||
); | ||
} | ||
Ok(()) | ||
} |