Skip to content

Commit

Permalink
Don't lint autolinks in doc_markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarton committed Sep 30, 2017
1 parent 06280e8 commit e40c270
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
12 changes: 11 additions & 1 deletion clippy_lints/src/doc.rs
Expand Up @@ -195,16 +195,26 @@ fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
use pulldown_cmark::Tag::*;

let mut in_code = false;
let mut in_link = None;

for (offset, event) in docs {
match event {
Start(CodeBlock(_)) | Start(Code) => in_code = true,
End(CodeBlock(_)) | End(Code) => in_code = false,
Start(_tag) | End(_tag) => (), // We don't care about other tags
Start(Link(link, _)) => in_link = Some(link),
End(Link(_, _)) => in_link = None,
Start(_tag) | End(_tag) => (), // We don't care about other tags
Html(_html) | InlineHtml(_html) => (), // HTML is weird, just ignore it
SoftBreak => (),
HardBreak => (),
FootnoteReference(text) | Text(text) => {
if Some(&text) == in_link.as_ref() {
// Probably a link of the form `<http://example.com>`
// Which are represented as a link to "http://example.com" with
// text "http://example.com" by pulldown-cmark
continue;
}

if !in_code {
let index = match spans.binary_search_by(|c| c.0.cmp(&offset)) {
Ok(o) => o,
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/doc.rs
Expand Up @@ -159,3 +159,8 @@ fn issue_1469() {}
*This would also be an error under a strict common mark interpretation
*/
fn issue_1920() {}

/// Ok: <http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels>
///
/// Not ok: http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels
fn issue_1832() {}
8 changes: 7 additions & 1 deletion tests/ui/doc.stderr
Expand Up @@ -156,5 +156,11 @@ error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the doc
138 | /// be_sure_we_got_to_the_end_of_it
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 26 previous errors
error: you should put `http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels` between ticks in the documentation
--> $DIR/doc.rs:165:13
|
165 | /// Not ok: http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 27 previous errors

0 comments on commit e40c270

Please sign in to comment.