Skip to content

Commit d8774e9

Browse files
committed
Fix DOC_MARKDOWN requiring backticks on links to external websites
1 parent 86fb33a commit d8774e9

File tree

4 files changed

+11
-26
lines changed

4 files changed

+11
-26
lines changed

clippy_lints/src/doc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,13 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
660660
check_link_quotes(cx, in_link.is_some(), trimmed_text, span, &range, begin, text.len());
661661
// Adjust for the beginning of the current `Event`
662662
let span = span.with_lo(span.lo() + BytePos::from_usize(range.start - begin));
663+
if let Some(link) = in_link.as_ref()
664+
&& let Ok(url) = Url::parse(&link)
665+
&& (url.scheme() == "https" || url.scheme() == "http") {
666+
// Don't check the text associated with HTTPS URLs
667+
continue;
668+
// dbg!(&text, &span, &in_link, &Url);
669+
}
663670
text_to_check.push((text, span));
664671
}
665672
},

tests/ui/doc/doc-fixable.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn test_allowed() {
7878
/// This test has [a `link_with_underscores`][chunked-example] inside it. See #823.
7979
/// See also [the issue tracker](https://github.com/rust-lang/rust-clippy/search?q=clippy::doc_markdown&type=Issues)
8080
/// on GitHub (which is a camel-cased word, but is OK). And here is another [inline link][inline_link].
81-
/// It can also be [`inline_link2`].
81+
/// It can also be [inline_link2]. A link to [StackOverflow](https://stackoverflow.com) is also acceptable.
8282
///
8383
/// [chunked-example]: https://en.wikipedia.org/wiki/Chunked_transfer_encoding#Example
8484
/// [inline_link]: https://foobar

tests/ui/doc/doc-fixable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ fn test_units() {
7575
fn test_allowed() {
7676
}
7777

78-
/// This test has [a link_with_underscores][chunked-example] inside it. See #823.
78+
/// This test has [a `link_with_underscores`][chunked-example] inside it. See #823.
7979
/// See also [the issue tracker](https://github.com/rust-lang/rust-clippy/search?q=clippy::doc_markdown&type=Issues)
8080
/// on GitHub (which is a camel-cased word, but is OK). And here is another [inline link][inline_link].
81-
/// It can also be [inline_link2].
81+
/// It can also be [inline_link2]. A link to [StackOverflow](https://stackoverflow.com) is also acceptable.
8282
///
8383
/// [chunked-example]: https://en.wikipedia.org/wiki/Chunked_transfer_encoding#Example
8484
/// [inline_link]: https://foobar

tests/ui/doc/doc-fixable.stderr

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,28 +142,6 @@ help: try
142142
LL | /// `be_sure_we_got_to_the_end_of_it`
143143
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144144

145-
error: item in documentation is missing backticks
146-
--> $DIR/doc-fixable.rs:78:22
147-
|
148-
LL | /// This test has [a link_with_underscores][chunked-example] inside it. See #823.
149-
| ^^^^^^^^^^^^^^^^^^^^^
150-
|
151-
help: try
152-
|
153-
LL | /// This test has [a `link_with_underscores`][chunked-example] inside it. See #823.
154-
| ~~~~~~~~~~~~~~~~~~~~~~~
155-
156-
error: item in documentation is missing backticks
157-
--> $DIR/doc-fixable.rs:81:21
158-
|
159-
LL | /// It can also be [inline_link2].
160-
| ^^^^^^^^^^^^
161-
|
162-
help: try
163-
|
164-
LL | /// It can also be [`inline_link2`].
165-
| ~~~~~~~~~~~~~~
166-
167145
error: item in documentation is missing backticks
168146
--> $DIR/doc-fixable.rs:91:5
169147
|
@@ -329,5 +307,5 @@ help: try
329307
LL | /// An iterator over `mycrate::Collection`'s values.
330308
| ~~~~~~~~~~~~~~~~~~~~~
331309

332-
error: aborting due to 30 previous errors
310+
error: aborting due to 28 previous errors
333311

0 commit comments

Comments
 (0)