pgevolve_core/lint/
finding.rs1use crate::parse::SourceLocation;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub enum Severity {
9 Error,
11 Warning,
13 LintAtPlan,
19}
20
21impl std::fmt::Display for Severity {
22 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23 f.write_str(match self {
24 Self::Error => "error",
25 Self::Warning => "warning",
26 Self::LintAtPlan => "lint-at-plan",
27 })
28 }
29}
30
31#[derive(Debug, Clone, PartialEq, Eq)]
33pub struct Finding {
34 pub severity: Severity,
36 pub rule: &'static str,
38 pub message: String,
40 pub location: Option<SourceLocation>,
42}
43
44impl Finding {
45 pub fn error(rule: &'static str, message: impl Into<String>) -> Self {
47 Self {
48 severity: Severity::Error,
49 rule,
50 message: message.into(),
51 location: None,
52 }
53 }
54
55 pub fn warning(rule: &'static str, message: impl Into<String>) -> Self {
57 Self {
58 severity: Severity::Warning,
59 rule,
60 message: message.into(),
61 location: None,
62 }
63 }
64
65 pub fn lint_at_plan(rule: &'static str, message: impl Into<String>) -> Self {
67 Self {
68 severity: Severity::LintAtPlan,
69 rule,
70 message: message.into(),
71 location: None,
72 }
73 }
74
75 #[must_use]
77 pub fn at(mut self, loc: SourceLocation) -> Self {
78 self.location = Some(loc);
79 self
80 }
81}