Skip to content

Commit

Permalink
Auto merge of rust-lang#12836 - hamirmahal:feat/quick-fix-for-bare-ur…
Browse files Browse the repository at this point in the history
…ls, r=y21

feat: `Quick Fix` for `bare URLs`

closes rust-lang#12835.

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

changelog: [`clippy::doc_markdown`]: `Quick Fix` for `bare URLs`
  • Loading branch information
bors committed May 24, 2024
2 parents f16317e + 17cc0a3 commit 674c641
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
8 changes: 5 additions & 3 deletions clippy_lints/src/doc/markdown.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -92,13 +92,15 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span, code_level: isize, b
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;
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/doc/doc-fixable.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,6 @@ extern {
/// `foo()`
fn in_extern();
}

/// <https://github.com/rust-lang/rust-clippy/pull/12836>
fn check_autofix_for_base_urls() {}
3 changes: 3 additions & 0 deletions tests/ui/doc/doc-fixable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,6 @@ extern {
/// foo()
fn in_extern();
}

/// https://github.com/rust-lang/rust-clippy/pull/12836
fn check_autofix_for_base_urls() {}
8 changes: 7 additions & 1 deletion tests/ui/doc/doc-fixable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 674c641

Please sign in to comment.