Skip to content

Commit 674c641

Browse files
committed
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`
2 parents f16317e + 17cc0a3 commit 674c641

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

clippy_lints/src/doc/markdown.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
1+
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
22
use clippy_utils::source::snippet_with_applicability;
33
use rustc_data_structures::fx::FxHashSet;
44
use rustc_errors::{Applicability, SuggestionStyle};
@@ -92,13 +92,15 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span, code_level: isize, b
9292
if let Ok(url) = Url::parse(word) {
9393
// try to get around the fact that `foo::bar` parses as a valid URL
9494
if !url.cannot_be_a_base() {
95-
span_lint(
95+
span_lint_and_sugg(
9696
cx,
9797
DOC_MARKDOWN,
9898
span,
9999
"you should put bare URLs between `<`/`>` or make a proper Markdown link",
100+
"try",
101+
format!("<{word}>"),
102+
Applicability::MachineApplicable,
100103
);
101-
102104
return;
103105
}
104106
}

tests/ui/doc/doc-fixable.fixed

+3
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,6 @@ extern {
240240
/// `foo()`
241241
fn in_extern();
242242
}
243+
244+
/// <https://github.com/rust-lang/rust-clippy/pull/12836>
245+
fn check_autofix_for_base_urls() {}

tests/ui/doc/doc-fixable.rs

+3
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,6 @@ extern {
240240
/// foo()
241241
fn in_extern();
242242
}
243+
244+
/// https://github.com/rust-lang/rust-clippy/pull/12836
245+
fn check_autofix_for_base_urls() {}

tests/ui/doc/doc-fixable.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -363,5 +363,11 @@ help: try
363363
LL | /// `foo()`
364364
| ~~~~~~~
365365

366-
error: aborting due to 33 previous errors
366+
error: you should put bare URLs between `<`/`>` or make a proper Markdown link
367+
--> tests/ui/doc/doc-fixable.rs:244:5
368+
|
369+
LL | /// https://github.com/rust-lang/rust-clippy/pull/12836
370+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `<https://github.com/rust-lang/rust-clippy/pull/12836>`
371+
372+
error: aborting due to 34 previous errors
367373

0 commit comments

Comments
 (0)