use crate::parse::SourceLocation;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Severity {
Error,
Warning,
LintAtPlan,
}
impl std::fmt::Display for Severity {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::Error => "error",
Self::Warning => "warning",
Self::LintAtPlan => "lint-at-plan",
})
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Finding {
pub severity: Severity,
pub rule: &'static str,
pub message: String,
pub location: Option<SourceLocation>,
}
impl Finding {
pub fn error(rule: &'static str, message: impl Into<String>) -> Self {
Self {
severity: Severity::Error,
rule,
message: message.into(),
location: None,
}
}
pub fn warning(rule: &'static str, message: impl Into<String>) -> Self {
Self {
severity: Severity::Warning,
rule,
message: message.into(),
location: None,
}
}
pub fn lint_at_plan(rule: &'static str, message: impl Into<String>) -> Self {
Self {
severity: Severity::LintAtPlan,
rule,
message: message.into(),
location: None,
}
}
#[must_use]
pub fn at(mut self, loc: SourceLocation) -> Self {
self.location = Some(loc);
self
}
}