-
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.
* adding csv support
- Loading branch information
Showing
6 changed files
with
122 additions
and
10 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,50 @@ | ||
use itertools::chain; | ||
|
||
use super::checker::{build_strict_violation_message, CheckAllResult}; | ||
|
||
pub fn write_csv<W: std::io::Write>( | ||
result: &CheckAllResult, | ||
writer: W, | ||
) -> anyhow::Result<()> { | ||
let mut wtr = csv::Writer::from_writer(writer); | ||
wtr.write_record([ | ||
"Violation", | ||
"Strict?", | ||
"File", | ||
"Constant", | ||
"Referencing Pack", | ||
"Defining Pack", | ||
"Message", | ||
])?; | ||
|
||
if !&result.reportable_violations.is_empty() | ||
|| !&result.strict_mode_violations.is_empty() | ||
{ | ||
let all = chain!( | ||
&result.reportable_violations, | ||
&result.strict_mode_violations | ||
); | ||
|
||
for violation in all { | ||
let identifier = &violation.identifier; | ||
let message = if violation.identifier.strict { | ||
build_strict_violation_message(&violation.identifier) | ||
} else { | ||
violation.message.to_string() | ||
}; | ||
wtr.serialize(( | ||
&identifier.violation_type, | ||
&identifier.strict, | ||
&identifier.file, | ||
&identifier.constant_name, | ||
&identifier.referencing_pack_name, | ||
&identifier.defining_pack_name, | ||
&message, | ||
))?; | ||
} | ||
} else { | ||
wtr.serialize(("No violations detected!", "", "", "", "", "", ""))?; | ||
} | ||
wtr.flush()?; | ||
Ok(()) | ||
} |
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