feat: auto-fix for bare URLs in doc comments

This commit is contained in:
Hamir Mahal 2024-05-24 14:30:42 -07:00
parent f16317e9cc
commit 17cc0a3a7d
No known key found for this signature in database
4 changed files with 18 additions and 4 deletions

View File

@ -1,4 +1,4 @@
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
use clippy_utils::source::snippet_with_applicability;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{Applicability, SuggestionStyle};
@ -92,13 +92,15 @@ fn has_hyphen(s: &str) -> bool {
if let Ok(url) = Url::parse(word) {
// try to get around the fact that `foo::bar` parses as a valid URL
if !url.cannot_be_a_base() {
span_lint(
span_lint_and_sugg(
cx,
DOC_MARKDOWN,
span,
"you should put bare URLs between `<`/`>` or make a proper Markdown link",
"try",
format!("<{word}>"),
Applicability::MachineApplicable,
);
return;
}
}

View File

@ -240,3 +240,6 @@ extern {
/// `foo()`
fn in_extern();
}
/// <https://github.com/rust-lang/rust-clippy/pull/12836>
fn check_autofix_for_base_urls() {}

View File

@ -240,3 +240,6 @@ fn plural_acronym_test() {}
/// foo()
fn in_extern();
}
/// https://github.com/rust-lang/rust-clippy/pull/12836
fn check_autofix_for_base_urls() {}

View File

@ -363,5 +363,11 @@ help: try
LL | /// `foo()`
| ~~~~~~~
error: aborting due to 33 previous errors
error: you should put bare URLs between `<`/`>` or make a proper Markdown link
--> tests/ui/doc/doc-fixable.rs:244:5
|
LL | /// https://github.com/rust-lang/rust-clippy/pull/12836
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `<https://github.com/rust-lang/rust-clippy/pull/12836>`
error: aborting due to 34 previous errors