Skip to content

Commit aca6c1e

Browse files
committed
Have a separate message for raw URLs in doc
1 parent b10610c commit aca6c1e

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

clippy_lints/src/doc.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use syntax::ast;
55
use syntax::codemap::{BytePos, Span};
66
use syntax_pos::Pos;
77
use utils::span_lint;
8+
use url::Url;
89

910
/// **What it does:** Checks for the presence of `_`, `::` or camel-case words
1011
/// outside ticks in documentation.
@@ -280,6 +281,18 @@ fn check_word(cx: &EarlyContext, word: &str, span: Span) {
280281
s != "_" && !s.contains("\\_") && s.contains('_')
281282
}
282283

284+
if let Ok(url) = Url::parse(word) {
285+
// try to get around the fact that `foo::bar` parses as a valid URL
286+
if !url.cannot_be_a_base() {
287+
span_lint(cx,
288+
DOC_MARKDOWN,
289+
span,
290+
"you should put bare URLs between `<`/`>` or make a proper Markdown link");
291+
292+
return;
293+
}
294+
}
295+
283296
if has_underscore(word) || word.contains("::") || is_camel_case(word) {
284297
span_lint(
285298
cx,

tests/ui/doc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,8 @@ fn issue_1920() {}
162162

163163
/// Ok: <http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels>
164164
///
165+
/// Not ok: http://www.unicode.org
166+
/// Not ok: https://www.unicode.org
167+
/// Not ok: http://www.unicode.org/
165168
/// Not ok: http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels
166169
fn issue_1832() {}

tests/ui/doc.stderr

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,29 @@ error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the doc
156156
138 | /// be_sure_we_got_to_the_end_of_it
157157
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
158158

159-
error: you should put `http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels` between ticks in the documentation
159+
error: you should put bare URLs between `<`/`>` or make a proper Markdown link
160160
--> $DIR/doc.rs:165:13
161161
|
162-
165 | /// Not ok: http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels
162+
165 | /// Not ok: http://www.unicode.org
163+
| ^^^^^^^^^^^^^^^^^^^^^^
164+
165+
error: you should put bare URLs between `<`/`>` or make a proper Markdown link
166+
--> $DIR/doc.rs:166:13
167+
|
168+
166 | /// Not ok: https://www.unicode.org
169+
| ^^^^^^^^^^^^^^^^^^^^^^^
170+
171+
error: you should put bare URLs between `<`/`>` or make a proper Markdown link
172+
--> $DIR/doc.rs:167:13
173+
|
174+
167 | /// Not ok: http://www.unicode.org/
175+
| ^^^^^^^^^^^^^^^^^^^^^^
176+
177+
error: you should put bare URLs between `<`/`>` or make a proper Markdown link
178+
--> $DIR/doc.rs:168:13
179+
|
180+
168 | /// Not ok: http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels
163181
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
164182

165-
error: aborting due to 27 previous errors
183+
error: aborting due to 30 previous errors
166184

0 commit comments

Comments
 (0)