use std::{collections::HashMap, path::PathBuf};
use ec4rs::property;
use itertools::Itertools;
use snafu::Snafu;
#[derive(Debug, Snafu)]
#[snafu(visibility(pub))]
pub enum CheckErrorType {
#[snafu(display("charset {actual_charset} instead of {expected_charset}"))]
CharsetError {
actual_charset: String,
expected_charset: property::Charset,
},
#[snafu(display(
"{} instead of only using end of line '{expected_end_of_line}'",
wrong_end_of_lines
.iter()
.map(|(end_of_line, count)| format!("end of line '{end_of_line}' occurres {count} time(s)"))
.join(" and ")
))]
EndOfLineError {
expected_end_of_line: property::EndOfLine,
wrong_end_of_lines: HashMap<property::EndOfLine, usize>,
},
}
#[derive(Debug, Snafu)]
#[snafu(display("{}: {error_type}", path.display()), visibility(pub))]
pub struct CheckError {
path: PathBuf,
error_type: CheckErrorType,
}
impl CheckError {
pub fn path(&self) -> &PathBuf {
&self.path
}
pub fn error_type(&self) -> &CheckErrorType {
&self.error_type
}
}
#[derive(Debug, Snafu)]
#[snafu(display("Check failed with {} errors", errors.len()), visibility(pub))]
pub struct CheckErrorList {
errors: Vec<CheckError>,
}
impl CheckErrorList {
pub fn errors(&self) -> &Vec<CheckError> {
&self.errors
}
}
impl<'a> IntoIterator for &'a CheckErrorList {
type Item = &'a CheckError;
type IntoIter = std::slice::Iter<'a, CheckError>;
fn into_iter(self) -> Self::IntoIter {
self.errors.iter()
}
}