Auto merge of #12836 - hamirmahal:feat/quick-fix-for-bare-urls, r=y21

feat: `Quick Fix` for `bare URLs`

closes #12835.

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: [`clippy::doc_markdown`]: `Quick Fix` for `bare URLs`
This commit is contained in:
bors 2024-05-24 21:51:45 +00:00
commit 674c641ecf
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 clippy_utils::source::snippet_with_applicability;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{Applicability, SuggestionStyle}; use rustc_errors::{Applicability, SuggestionStyle};
@ -92,13 +92,15 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span, code_level: isize, b
if let Ok(url) = Url::parse(word) { if let Ok(url) = Url::parse(word) {
// try to get around the fact that `foo::bar` parses as a valid URL // try to get around the fact that `foo::bar` parses as a valid URL
if !url.cannot_be_a_base() { if !url.cannot_be_a_base() {
span_lint( span_lint_and_sugg(
cx, cx,
DOC_MARKDOWN, DOC_MARKDOWN,
span, span,
"you should put bare URLs between `<`/`>` or make a proper Markdown link", "you should put bare URLs between `<`/`>` or make a proper Markdown link",
"try",
format!("<{word}>"),
Applicability::MachineApplicable,
); );
return; return;
} }
} }

View file

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

View file

@ -240,3 +240,6 @@ extern {
/// foo() /// foo()
fn in_extern(); 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()` 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