#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Span {
pub line: usize,
pub file: Option<String>,
}
impl Span {
pub fn new(line: usize) -> Self {
Self { line, file: None }
}
pub fn with_file(line: usize, file: impl Into<String>) -> Self {
Self {
line,
file: Some(file.into()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LineKind {
Empty,
Comment(String),
Directive { key: String, value: String },
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Line {
pub kind: LineKind,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Item {
Comment { text: String, span: Span },
Directive {
key: String,
value: String,
span: Span,
},
HostBlock {
patterns: Vec<String>,
span: Span,
items: Vec<Item>,
},
MatchBlock {
criteria: String,
span: Span,
items: Vec<Item>,
},
Include { patterns: Vec<String>, span: Span },
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Config {
pub items: Vec<Item>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Severity {
Info,
Warning,
Error,
}
impl std::fmt::Display for Severity {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Severity::Info => write!(f, "info"),
Severity::Warning => write!(f, "warning"),
Severity::Error => write!(f, "error"),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Finding {
pub severity: Severity,
pub code: &'static str,
pub message: String,
pub hint: Option<String>,
pub span: Span,
pub rule: String,
}
impl Finding {
pub fn new(
severity: Severity,
rule: impl Into<String>,
code: &'static str,
message: impl Into<String>,
span: Span,
) -> Self {
Self {
severity,
code,
message: message.into(),
hint: None,
span,
rule: rule.into(),
}
}
pub fn with_hint(mut self, hint: impl Into<String>) -> Self {
self.hint = Some(hint.into());
self
}
}