-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use super::{DOC_BROKEN_LINK, Fragments}; | ||
use clippy_utils::diagnostics::span_lint; | ||
use rustc_lint::LateContext; | ||
use std::ops::Range; | ||
|
||
// Check broken links in code docs. | ||
pub fn check(cx: &LateContext<'_>, _trimmed_text: &str, range: Range<usize>, fragments: Fragments<'_>, link: &str) { | ||
if let Some(span) = fragments.span(cx, range) { | ||
// Broken links are replaced with "fake" value by `fake_broken_link_callback` at `doc/mod.rs`. | ||
if link == "fake" { | ||
span_lint(cx, DOC_BROKEN_LINK, span, "possible broken doc link"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#![warn(clippy::doc_broken_link)] | ||
|
||
fn main() { | ||
doc_valid_link(); | ||
doc_valid_link_broken_title(); | ||
doc_valid_link_broken_url_tag(); | ||
doc_invalid_link_broken_url_scheme_part(); | ||
doc_invalid_link_broken_url_host_part(); | ||
} | ||
|
||
/// Test valid link, whole link single line. | ||
/// [doc valid link](https://test.fake/doc_valid_link) | ||
pub fn doc_valid_link() {} | ||
|
||
/// Test valid link, title tag broken across multiple lines. | ||
/// [doc invalid link broken | ||
/// title](https://test.fake/doc_valid_link_broken_title) | ||
pub fn doc_valid_link_broken_title() {} | ||
|
||
/// Test valid link, url tag broken across multiple lines, but | ||
/// the whole url part in a single line. | ||
/// [doc valid link broken url tag]( | ||
/// https://test.fake/doc_valid_link_broken_url_tag) | ||
pub fn doc_valid_link_broken_url_tag() {} | ||
|
||
/// Test invalid link, url part broken across multiple lines. | ||
/// [doc invalid link broken url scheme part part](https:// | ||
/// test.fake/doc_invalid_link_broken_url_scheme_part) | ||
//~^^ ERROR: possible broken doc link | ||
pub fn doc_invalid_link_broken_url_scheme_part() {} | ||
|
||
/// Test invalid link, url part broken across multiple lines. | ||
/// [doc invalid link broken url host part](https://test | ||
/// .fake/doc_invalid_link_broken_url_host_part) | ||
//~^^ ERROR: possible broken doc link | ||
pub fn doc_invalid_link_broken_url_host_part() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error: possible broken doc link | ||
--> tests/ui/doc_broken_link.rs:27:6 | ||
| | ||
LL | /// [doc invalid link broken url scheme part part](https:// | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::doc-broken-link` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::doc_broken_link)]` | ||
|
||
error: possible broken doc link | ||
--> tests/ui/doc_broken_link.rs:33:6 | ||
| | ||
LL | /// [doc invalid link broken url host part](https://test | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|