use crate::node::Span;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Property {
Fidelity,
Resilience,
Precision,
}
impl Property {
pub const fn as_str(self) -> &'static str {
match self {
Property::Fidelity => "fidelity",
Property::Resilience => "resilience",
Property::Precision => "precision",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct RuleId(&'static str);
impl RuleId {
pub const fn new(name: &'static str) -> Self {
RuleId(name)
}
pub const fn as_str(self) -> &'static str {
self.0
}
}
impl std::fmt::Display for RuleId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.0)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Citation {
pub title: &'static str,
pub url: &'static str,
pub date: &'static str,
}
#[derive(Debug, Clone, Copy)]
pub struct Rule {
pub id: RuleId,
pub property: Property,
pub summary: &'static str,
pub instruction: &'static str,
pub citation: Citation,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EvidenceStep {
pub span: Span,
pub message: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Finding {
pub rule: RuleId,
pub property: Property,
pub span: Span,
pub message: String,
pub help: Option<String>,
pub evidence: Vec<EvidenceStep>,
}
impl Finding {
pub fn new(rule: &Rule, span: Span, message: impl Into<String>) -> Self {
Finding {
rule: rule.id,
property: rule.property,
span,
message: message.into(),
help: None,
evidence: Vec::new(),
}
}
pub fn with_help(mut self, help: impl Into<String>) -> Self {
self.help = Some(help.into());
self
}
}