Skip to content
Merged
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
5 changes: 3 additions & 2 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, LintDocsUrl,
LintFix,
};
use crate::ignore_directives::{
parse_line_ignore_directives, CodeStatus, FileIgnoreDirective,
Expand Down Expand Up @@ -484,7 +485,7 @@ impl<'a> Context<'a> {
code: code.to_string(),
hint: maybe_hint,
fixes,
custom_docs_url: None,
custom_docs_url: LintDocsUrl::Default,
info: vec![],
}
}
Expand Down
20 changes: 14 additions & 6 deletions src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ pub struct LintDiagnosticRange {
pub description: Option<String>,
}

#[derive(Clone, Default)]
pub enum LintDocsUrl {
#[default]
Default,
None,
Custom(String),
}

#[derive(Clone)]
pub struct LintDiagnosticDetails {
pub message: String,
Expand All @@ -48,7 +56,7 @@ pub struct LintDiagnosticDetails {
pub fixes: Vec<LintFix>,
/// URL to the lint rule documentation. By default, the url uses the
/// code to link to lint.deno.land
pub custom_docs_url: Option<String>,
pub custom_docs_url: LintDocsUrl,
/// Displays additional information at the end of a diagnostic.
pub info: Vec<Cow<'static, str>>,
}
Expand Down Expand Up @@ -122,13 +130,13 @@ impl Diagnostic for LintDiagnostic {
}

fn docs_url(&self) -> Option<Cow<'_, str>> {
if let Some(custom_docs_url) = &self.details.custom_docs_url {
Some(Cow::Borrowed(custom_docs_url))
} else {
Some(Cow::Owned(format!(
match &self.details.custom_docs_url {
LintDocsUrl::Default => Some(Cow::Owned(format!(
"https://docs.deno.com/lint/rules/{}",
&self.details.code
)))
))),
LintDocsUrl::Custom(url) => Some(Cow::Borrowed(url)),
LintDocsUrl::None => None,
}
}
}