From e40c270d4f37662b7263ab40914105978da2dbb3 Mon Sep 17 00:00:00 2001 From: mcarton Date: Sun, 18 Jun 2017 23:00:14 +0200 Subject: [PATCH] Don't lint autolinks in `doc_markdown` --- clippy_lints/src/doc.rs | 12 +++++++++++- tests/ui/doc.rs | 5 +++++ tests/ui/doc.stderr | 8 +++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 170ca5cf0079b..0c4a2a88ae0e2 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -195,16 +195,26 @@ fn check_doc<'a, Events: Iterator)>>( 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 `` + // 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, diff --git a/tests/ui/doc.rs b/tests/ui/doc.rs index 9e7b34e3ea500..21449e526af12 100644 --- a/tests/ui/doc.rs +++ b/tests/ui/doc.rs @@ -159,3 +159,8 @@ fn issue_1469() {} *This would also be an error under a strict common mark interpretation */ fn issue_1920() {} + +/// Ok: +/// +/// Not ok: http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels +fn issue_1832() {} diff --git a/tests/ui/doc.stderr b/tests/ui/doc.stderr index c3146f17d0884..fb0d724172d12 100644 --- a/tests/ui/doc.stderr +++ b/tests/ui/doc.stderr @@ -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