Skip to content

Commit 6be97e2

Browse files
Improve lint even more
1 parent 1fb404b commit 6be97e2

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/librustdoc/passes/url_improvements.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ pub const CHECK_URL_IMPROVEMENTS: Pass = Pass {
1919
const URL_REGEX: &str = concat!(
2020
r"https?://", // url scheme
2121
r"([-a-zA-Z0-9@:%._\+~#=]{2,256}\.)+", // one or more subdomains
22-
r"[a-zA-Z]{2,4}", // root domain
23-
r"\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)" // optional query or url fragments
22+
r"[a-zA-Z]{2,63}", // root domain
23+
r"\b([-a-zA-Z0-9@:%_\+.~#?&/=]*)" // optional query or url fragments
2424
);
2525

2626
struct UrlImprovementsLinter<'a, 'tcx> {
@@ -101,8 +101,9 @@ impl<'a, 'tcx> DocFolder for UrlImprovementsLinter<'a, 'tcx> {
101101
while let Some((event, range)) = p.next() {
102102
match event {
103103
Event::End(Tag::Link(_, url, _)) => {
104-
// NOTE: links cannot be nested, so we don't need to check `kind`
105-
if url.as_ref() == title && !ignore {
104+
// NOTE: links cannot be nested, so we don't need to
105+
// check `kind`
106+
if url.as_ref() == title && !ignore && self.regex.matches(url) {
106107
report_diag(
107108
self.cx,
108109
"unneeded long form for URL",

src/test/rustdoc-ui/url-improvements.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ pub fn c() {}
5555
/// ```
5656
/// This link should not be linted: http://example.com
5757
/// ```
58+
///
59+
/// [should_not.lint](should_not.lint)
5860
pub fn everything_is_fine_here() {}
5961

6062
#[allow(url_improvements)]

0 commit comments

Comments
 (0)