mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Don't check for URLs inside codeblocks
This commit is contained in:
parent
fce2be0ea7
commit
1fb404bebe
@ -90,33 +90,43 @@ impl<'a, 'tcx> DocFolder for UrlImprovementsLinter<'a, 'tcx> {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
let p = Parser::new_ext(&dox, opts()).into_offset_iter();
|
let mut p = Parser::new_ext(&dox, opts()).into_offset_iter();
|
||||||
|
|
||||||
let mut title = String::new();
|
while let Some((event, range)) = p.next() {
|
||||||
let mut in_link = false;
|
|
||||||
let mut ignore = false;
|
|
||||||
|
|
||||||
for (event, range) in p {
|
|
||||||
match event {
|
match event {
|
||||||
Event::Start(Tag::Link(kind, _, _)) => {
|
Event::Start(Tag::Link(kind, _, _)) => {
|
||||||
in_link = true;
|
let ignore = matches!(kind, LinkType::Autolink | LinkType::Email);
|
||||||
ignore = matches!(kind, LinkType::Autolink | LinkType::Email);
|
let mut title = String::new();
|
||||||
}
|
|
||||||
Event::End(Tag::Link(_, url, _)) => {
|
while let Some((event, range)) = p.next() {
|
||||||
in_link = false;
|
match event {
|
||||||
// NOTE: links cannot be nested, so we don't need to check `kind`
|
Event::End(Tag::Link(_, url, _)) => {
|
||||||
if url.as_ref() == title && !ignore {
|
// NOTE: links cannot be nested, so we don't need to check `kind`
|
||||||
report_diag(self.cx, "unneeded long form for URL", &url, range);
|
if url.as_ref() == title && !ignore {
|
||||||
}
|
report_diag(
|
||||||
title.clear();
|
self.cx,
|
||||||
ignore = false;
|
"unneeded long form for URL",
|
||||||
}
|
&url,
|
||||||
Event::Text(s) if in_link => {
|
range,
|
||||||
if !ignore {
|
);
|
||||||
title.push_str(&s);
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Event::Text(s) if !ignore => title.push_str(&s),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Text(s) => self.find_raw_urls(&s, range, &report_diag),
|
Event::Text(s) => self.find_raw_urls(&s, range, &report_diag),
|
||||||
|
Event::Start(Tag::CodeBlock(_)) => {
|
||||||
|
// We don't want to check the text inside the code blocks.
|
||||||
|
while let Some((event, _)) = p.next() {
|
||||||
|
match event {
|
||||||
|
Event::End(Tag::CodeBlock(_)) => break,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,10 @@ pub fn c() {}
|
|||||||
/// [b]
|
/// [b]
|
||||||
///
|
///
|
||||||
/// [b]: http://b.com
|
/// [b]: http://b.com
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// This link should not be linted: http://example.com
|
||||||
|
/// ```
|
||||||
pub fn everything_is_fine_here() {}
|
pub fn everything_is_fine_here() {}
|
||||||
|
|
||||||
#[allow(url_improvements)]
|
#[allow(url_improvements)]
|
||||||
|
@ -1,119 +1,119 @@
|
|||||||
error: unneeded long form for URL
|
error: unneeded long form for URL
|
||||||
--> $DIR/automatic-links.rs:3:5
|
--> $DIR/url-improvements.rs:3:5
|
||||||
|
|
|
|
||||||
LL | /// [http://a.com](http://a.com)
|
LL | /// [http://a.com](http://a.com)
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://a.com>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://a.com>`
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/automatic-links.rs:1:9
|
--> $DIR/url-improvements.rs:1:9
|
||||||
|
|
|
|
||||||
LL | #![deny(url_improvements)]
|
LL | #![deny(url_improvements)]
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: unneeded long form for URL
|
error: unneeded long form for URL
|
||||||
--> $DIR/automatic-links.rs:5:5
|
--> $DIR/url-improvements.rs:5:5
|
||||||
|
|
|
|
||||||
LL | /// [http://b.com]
|
LL | /// [http://b.com]
|
||||||
| ^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://b.com>`
|
| ^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://b.com>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:13:5
|
--> $DIR/url-improvements.rs:13:5
|
||||||
|
|
|
|
||||||
LL | /// https://somewhere.com
|
LL | /// https://somewhere.com
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com>`
|
| ^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:15:5
|
--> $DIR/url-improvements.rs:15:5
|
||||||
|
|
|
|
||||||
LL | /// https://somewhere.com/a
|
LL | /// https://somewhere.com/a
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:17:5
|
--> $DIR/url-improvements.rs:17:5
|
||||||
|
|
|
|
||||||
LL | /// https://www.somewhere.com
|
LL | /// https://www.somewhere.com
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://www.somewhere.com>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://www.somewhere.com>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:19:5
|
--> $DIR/url-improvements.rs:19:5
|
||||||
|
|
|
|
||||||
LL | /// https://www.somewhere.com/a
|
LL | /// https://www.somewhere.com/a
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://www.somewhere.com/a>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://www.somewhere.com/a>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:21:5
|
--> $DIR/url-improvements.rs:21:5
|
||||||
|
|
|
|
||||||
LL | /// https://subdomain.example.com
|
LL | /// https://subdomain.example.com
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://subdomain.example.com>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://subdomain.example.com>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:23:5
|
--> $DIR/url-improvements.rs:23:5
|
||||||
|
|
|
|
||||||
LL | /// https://somewhere.com?
|
LL | /// https://somewhere.com?
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?>`
|
| ^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:25:5
|
--> $DIR/url-improvements.rs:25:5
|
||||||
|
|
|
|
||||||
LL | /// https://somewhere.com/a?
|
LL | /// https://somewhere.com/a?
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:27:5
|
--> $DIR/url-improvements.rs:27:5
|
||||||
|
|
|
|
||||||
LL | /// https://somewhere.com?hello=12
|
LL | /// https://somewhere.com?hello=12
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?hello=12>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?hello=12>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:29:5
|
--> $DIR/url-improvements.rs:29:5
|
||||||
|
|
|
|
||||||
LL | /// https://somewhere.com/a?hello=12
|
LL | /// https://somewhere.com/a?hello=12
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?hello=12>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?hello=12>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:31:5
|
--> $DIR/url-improvements.rs:31:5
|
||||||
|
|
|
|
||||||
LL | /// https://example.com?hello=12#xyz
|
LL | /// https://example.com?hello=12#xyz
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com?hello=12#xyz>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com?hello=12#xyz>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:33:5
|
--> $DIR/url-improvements.rs:33:5
|
||||||
|
|
|
|
||||||
LL | /// https://example.com/a?hello=12#xyz
|
LL | /// https://example.com/a?hello=12#xyz
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com/a?hello=12#xyz>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com/a?hello=12#xyz>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:35:5
|
--> $DIR/url-improvements.rs:35:5
|
||||||
|
|
|
|
||||||
LL | /// https://example.com#xyz
|
LL | /// https://example.com#xyz
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com#xyz>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com#xyz>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:37:5
|
--> $DIR/url-improvements.rs:37:5
|
||||||
|
|
|
|
||||||
LL | /// https://example.com/a#xyz
|
LL | /// https://example.com/a#xyz
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com/a#xyz>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com/a#xyz>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:39:5
|
--> $DIR/url-improvements.rs:39:5
|
||||||
|
|
|
|
||||||
LL | /// https://somewhere.com?hello=12&bye=11
|
LL | /// https://somewhere.com?hello=12&bye=11
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?hello=12&bye=11>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?hello=12&bye=11>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:41:5
|
--> $DIR/url-improvements.rs:41:5
|
||||||
|
|
|
|
||||||
LL | /// https://somewhere.com/a?hello=12&bye=11
|
LL | /// https://somewhere.com/a?hello=12&bye=11
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?hello=12&bye=11>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?hello=12&bye=11>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:43:5
|
--> $DIR/url-improvements.rs:43:5
|
||||||
|
|
|
|
||||||
LL | /// https://somewhere.com?hello=12&bye=11#xyz
|
LL | /// https://somewhere.com?hello=12&bye=11#xyz
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?hello=12&bye=11#xyz>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?hello=12&bye=11#xyz>`
|
||||||
|
|
||||||
error: this URL is not a hyperlink
|
error: this URL is not a hyperlink
|
||||||
--> $DIR/automatic-links.rs:45:10
|
--> $DIR/url-improvements.rs:45:10
|
||||||
|
|
|
|
||||||
LL | /// hey! https://somewhere.com/a?hello=12&bye=11#xyz
|
LL | /// hey! https://somewhere.com/a?hello=12&bye=11#xyz
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?hello=12&bye=11#xyz>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?hello=12&bye=11#xyz>`
|
||||||
|
Loading…
Reference in New Issue
Block a user