Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add lint serverity #1412

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use crate::control_flow::ControlFlow;
use crate::diagnostic::{
LintDiagnostic, LintDiagnosticDetails, LintDiagnosticRange, LintFix,
LintDiagnostic, LintDiagnosticDetails, LintDiagnosticRange,
LintDiagnosticSeverity, LintFix,
};
use crate::ignore_directives::{
parse_line_ignore_directives, CodeStatus, FileIgnoreDirective,
Expand Down Expand Up @@ -298,6 +299,7 @@ impl<'a> Context<'a> {
None,
Vec::new(),
),
LintDiagnosticSeverity::default(),
);
diagnostics.push(d);
}
Expand All @@ -319,6 +321,7 @@ impl<'a> Context<'a> {
None,
Vec::new(),
),
LintDiagnosticSeverity::default(),
);
diagnostics.push(d);
}
Expand Down Expand Up @@ -351,6 +354,7 @@ impl<'a> Context<'a> {
None,
Vec::new(),
),
LintDiagnosticSeverity::default(),
);
diagnostics.push(d);
}
Expand All @@ -370,6 +374,7 @@ impl<'a> Context<'a> {
None,
Vec::new(),
),
LintDiagnosticSeverity::default(),
);
diagnostics.push(d);
}
Expand Down Expand Up @@ -407,6 +412,8 @@ impl<'a> Context<'a> {
None,
Vec::new(),
),
// Todo: support custom severity for each rule or custom configuration
LintDiagnosticSeverity::default(),
);
}

Expand All @@ -425,6 +432,8 @@ impl<'a> Context<'a> {
Some(hint.to_string()),
Vec::new(),
),
// Todo: support custom severity for each rule or custom configuration
LintDiagnosticSeverity::default(),
);
}

Expand All @@ -439,17 +448,21 @@ impl<'a> Context<'a> {
self.add_diagnostic_details(
Some(self.create_diagnostic_range(range)),
self.create_diagnostic_details(code, message, hint, fixes),
LintDiagnosticSeverity::default(),
);
}

pub fn add_diagnostic_details(
&mut self,
maybe_range: Option<LintDiagnosticRange>,
details: LintDiagnosticDetails,
severity: LintDiagnosticSeverity,
) {
self
.diagnostics
.push(self.create_diagnostic(maybe_range, details));
self.diagnostics.push(self.create_diagnostic(
maybe_range,
details,
severity,
));
}

/// Add fully constructed diagnostics.
Expand All @@ -464,11 +477,13 @@ impl<'a> Context<'a> {
&self,
maybe_range: Option<LintDiagnosticRange>,
details: LintDiagnosticDetails,
severity: LintDiagnosticSeverity,
) -> LintDiagnostic {
LintDiagnostic {
specifier: self.specifier().clone(),
range: maybe_range,
details,
severity,
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ pub struct LintDiagnosticDetails {
pub info: Vec<Cow<'static, str>>,
}

#[derive(Debug, Default, Clone, Copy)]
pub enum LintDiagnosticSeverity {
#[default]
Error,
Warning,
}

#[derive(Clone)]
pub struct LintDiagnostic {
pub specifier: ModuleSpecifier,
Expand All @@ -62,11 +69,15 @@ pub struct LintDiagnostic {
/// the whole file.
pub range: Option<LintDiagnosticRange>,
pub details: LintDiagnosticDetails,
pub severity: LintDiagnosticSeverity,
}

impl Diagnostic for LintDiagnostic {
fn level(&self) -> DiagnosticLevel {
DiagnosticLevel::Error
match self.severity {
LintDiagnosticSeverity::Error => DiagnosticLevel::Error,
LintDiagnosticSeverity::Warning => DiagnosticLevel::Warning,
}
}

fn code(&self) -> Cow<'_, str> {
Expand Down