nu_lint/
lint.rs

1use miette::SourceSpan;
2use nu_protocol::Span;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
5pub enum Severity {
6    Error,
7    Warning,
8    Info,
9}
10
11impl std::fmt::Display for Severity {
12    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13        match self {
14            Severity::Error => write!(f, "error"),
15            Severity::Warning => write!(f, "warning"),
16            Severity::Info => write!(f, "info"),
17        }
18    }
19}
20
21#[derive(Debug, Clone)]
22pub struct Violation {
23    pub rule_id: String,
24    pub severity: Severity,
25    pub message: String,
26    pub span: Span,
27    pub suggestion: Option<String>,
28    pub fix: Option<Fix>,
29    pub file: Option<String>,
30}
31
32impl Violation {
33    #[must_use]
34    pub fn to_source_span(&self) -> SourceSpan {
35        SourceSpan::from((self.span.start, self.span.end - self.span.start))
36    }
37}
38
39#[derive(Debug, Clone)]
40pub struct Fix {
41    pub description: String,
42    pub replacements: Vec<Replacement>,
43}
44
45#[derive(Debug, Clone)]
46pub struct Replacement {
47    pub span: Span,
48    pub new_text: String,
49}