use crate::reporting::offence::Offence;
pub struct ColumnWidths {
pub file: usize,
pub line: usize,
pub rule: usize,
pub description: usize,
}
impl ColumnWidths {
pub fn of(offences: &[Offence]) -> Self {
Self {
file: Self::widest(offences.iter().map(|offence| offence.file.len()), "file"),
line: Self::widest(
offences
.iter()
.map(|offence| offence.line.to_string().len()),
"line",
),
rule: Self::widest(offences.iter().map(|offence| offence.rule.len()), "rule"),
description: Self::widest(
offences.iter().map(|offence| offence.description.len()),
"offence",
),
}
}
fn widest<I: Iterator<Item = usize>>(lengths: I, heading: &str) -> usize {
lengths.max().unwrap_or(0).max(heading.len())
}
}