Skip to content

Commit

Permalink
feat: ability to provide a custom docs url (#1297)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Jul 24, 2024
1 parent 28b0a25 commit 5299ecf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl<'a> Context<'a> {
) {
let diagnostic = self.create_diagnostic(
range,
code.to_string(),
code,
message.to_string(),
None,
Vec::new(),
Expand Down Expand Up @@ -441,6 +441,7 @@ impl<'a> Context<'a> {
code: code.to_string(),
hint: maybe_hint,
fixes,
custom_docs_url: None,
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub struct LintDiagnostic {
/// only the first fix will be used for the `--fix` flag, but
/// multiple will be shown in the LSP.
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>,
}

impl Diagnostic for LintDiagnostic {
Expand Down Expand Up @@ -92,9 +95,13 @@ impl Diagnostic for LintDiagnostic {
}

fn docs_url(&self) -> Option<Cow<'_, str>> {
Some(Cow::Owned(format!(
"https://lint.deno.land/rules/{}",
&self.code
)))
if let Some(custom_docs_url) = &self.custom_docs_url {
Some(Cow::Borrowed(custom_docs_url))
} else {
Some(Cow::Owned(format!(
"https://lint.deno.land/rules/{}",
&self.code
)))
}
}
}

0 comments on commit 5299ecf

Please sign in to comment.