doc_link_code: add check for text[adjacent] style links
This is the lint described at https://github.com/rust-lang/rust/pull/136308#issuecomment-2625485331 that recommends using HTML to nest links inside code.
This commit is contained in:
parent
f51e18de30
commit
045e36d6a7
6 changed files with 292 additions and 0 deletions
52
tests/ui/doc/link_adjacent.fixed
Normal file
52
tests/ui/doc/link_adjacent.fixed
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#![warn(clippy::doc_link_code)]
|
||||
|
||||
//! Test case for code links that are adjacent to code text.
|
||||
//!
|
||||
//! This is not an example: `first``second`
|
||||
//!
|
||||
//! Neither is this: [`first`](x)
|
||||
//!
|
||||
//! Neither is this: [`first`](x) `second`
|
||||
//!
|
||||
//! Neither is this: [first](x)`second`
|
||||
//!
|
||||
//! This is: <code>[first](x)second</code>
|
||||
//~^ ERROR: adjacent
|
||||
//!
|
||||
//! So is this <code>first[second](x)</code>
|
||||
//~^ ERROR: adjacent
|
||||
//!
|
||||
//! So is this <code>[first](x)[second](x)</code>
|
||||
//~^ ERROR: adjacent
|
||||
//!
|
||||
//! So is this <code>[first](x)[second](x)[third](x)</code>
|
||||
//~^ ERROR: adjacent
|
||||
//!
|
||||
//! So is this <code>[first](x)second[third](x)</code>
|
||||
//~^ ERROR: adjacent
|
||||
|
||||
/// Test case for code links that are adjacent to code text.
|
||||
///
|
||||
/// This is not an example: `first``second` arst
|
||||
///
|
||||
/// Neither is this: [`first`](x) arst
|
||||
///
|
||||
/// Neither is this: [`first`](x) `second` arst
|
||||
///
|
||||
/// Neither is this: [first](x)`second` arst
|
||||
///
|
||||
/// This is: <code>[first](x)second</code> arst
|
||||
//~^ ERROR: adjacent
|
||||
///
|
||||
/// So is this <code>first[second](x)</code> arst
|
||||
//~^ ERROR: adjacent
|
||||
///
|
||||
/// So is this <code>[first](x)[second](x)</code> arst
|
||||
//~^ ERROR: adjacent
|
||||
///
|
||||
/// So is this <code>[first](x)[second](x)[third](x)</code> arst
|
||||
//~^ ERROR: adjacent
|
||||
///
|
||||
/// So is this <code>[first](x)second[third](x)</code> arst
|
||||
//~^ ERROR: adjacent
|
||||
pub struct WithTrailing;
|
||||
52
tests/ui/doc/link_adjacent.rs
Normal file
52
tests/ui/doc/link_adjacent.rs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#![warn(clippy::doc_link_code)]
|
||||
|
||||
//! Test case for code links that are adjacent to code text.
|
||||
//!
|
||||
//! This is not an example: `first``second`
|
||||
//!
|
||||
//! Neither is this: [`first`](x)
|
||||
//!
|
||||
//! Neither is this: [`first`](x) `second`
|
||||
//!
|
||||
//! Neither is this: [first](x)`second`
|
||||
//!
|
||||
//! This is: [`first`](x)`second`
|
||||
//~^ ERROR: adjacent
|
||||
//!
|
||||
//! So is this `first`[`second`](x)
|
||||
//~^ ERROR: adjacent
|
||||
//!
|
||||
//! So is this [`first`](x)[`second`](x)
|
||||
//~^ ERROR: adjacent
|
||||
//!
|
||||
//! So is this [`first`](x)[`second`](x)[`third`](x)
|
||||
//~^ ERROR: adjacent
|
||||
//!
|
||||
//! So is this [`first`](x)`second`[`third`](x)
|
||||
//~^ ERROR: adjacent
|
||||
|
||||
/// Test case for code links that are adjacent to code text.
|
||||
///
|
||||
/// This is not an example: `first``second` arst
|
||||
///
|
||||
/// Neither is this: [`first`](x) arst
|
||||
///
|
||||
/// Neither is this: [`first`](x) `second` arst
|
||||
///
|
||||
/// Neither is this: [first](x)`second` arst
|
||||
///
|
||||
/// This is: [`first`](x)`second` arst
|
||||
//~^ ERROR: adjacent
|
||||
///
|
||||
/// So is this `first`[`second`](x) arst
|
||||
//~^ ERROR: adjacent
|
||||
///
|
||||
/// So is this [`first`](x)[`second`](x) arst
|
||||
//~^ ERROR: adjacent
|
||||
///
|
||||
/// So is this [`first`](x)[`second`](x)[`third`](x) arst
|
||||
//~^ ERROR: adjacent
|
||||
///
|
||||
/// So is this [`first`](x)`second`[`third`](x) arst
|
||||
//~^ ERROR: adjacent
|
||||
pub struct WithTrailing;
|
||||
124
tests/ui/doc/link_adjacent.stderr
Normal file
124
tests/ui/doc/link_adjacent.stderr
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
error: code link adjacent to code text
|
||||
--> tests/ui/doc/link_adjacent.rs:13:14
|
||||
|
|
||||
LL | //! This is: [`first`](x)`second`
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: separate code snippets will be shown with a gap
|
||||
= note: `-D clippy::doc-link-code` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::doc_link_code)]`
|
||||
help: wrap the entire group in `<code>` tags
|
||||
|
|
||||
LL | //! This is: <code>[first](x)second</code>
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: code link adjacent to code text
|
||||
--> tests/ui/doc/link_adjacent.rs:16:16
|
||||
|
|
||||
LL | //! So is this `first`[`second`](x)
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: separate code snippets will be shown with a gap
|
||||
help: wrap the entire group in `<code>` tags
|
||||
|
|
||||
LL | //! So is this <code>first[second](x)</code>
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: code link adjacent to code text
|
||||
--> tests/ui/doc/link_adjacent.rs:19:16
|
||||
|
|
||||
LL | //! So is this [`first`](x)[`second`](x)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: separate code snippets will be shown with a gap
|
||||
help: wrap the entire group in `<code>` tags
|
||||
|
|
||||
LL | //! So is this <code>[first](x)[second](x)</code>
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: code link adjacent to code text
|
||||
--> tests/ui/doc/link_adjacent.rs:22:16
|
||||
|
|
||||
LL | //! So is this [`first`](x)[`second`](x)[`third`](x)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: separate code snippets will be shown with a gap
|
||||
help: wrap the entire group in `<code>` tags
|
||||
|
|
||||
LL | //! So is this <code>[first](x)[second](x)[third](x)</code>
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: code link adjacent to code text
|
||||
--> tests/ui/doc/link_adjacent.rs:25:16
|
||||
|
|
||||
LL | //! So is this [`first`](x)`second`[`third`](x)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: separate code snippets will be shown with a gap
|
||||
help: wrap the entire group in `<code>` tags
|
||||
|
|
||||
LL | //! So is this <code>[first](x)second[third](x)</code>
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: code link adjacent to code text
|
||||
--> tests/ui/doc/link_adjacent.rs:38:14
|
||||
|
|
||||
LL | /// This is: [`first`](x)`second` arst
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: separate code snippets will be shown with a gap
|
||||
help: wrap the entire group in `<code>` tags
|
||||
|
|
||||
LL | /// This is: <code>[first](x)second</code> arst
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: code link adjacent to code text
|
||||
--> tests/ui/doc/link_adjacent.rs:41:16
|
||||
|
|
||||
LL | /// So is this `first`[`second`](x) arst
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: separate code snippets will be shown with a gap
|
||||
help: wrap the entire group in `<code>` tags
|
||||
|
|
||||
LL | /// So is this <code>first[second](x)</code> arst
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: code link adjacent to code text
|
||||
--> tests/ui/doc/link_adjacent.rs:44:16
|
||||
|
|
||||
LL | /// So is this [`first`](x)[`second`](x) arst
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: separate code snippets will be shown with a gap
|
||||
help: wrap the entire group in `<code>` tags
|
||||
|
|
||||
LL | /// So is this <code>[first](x)[second](x)</code> arst
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: code link adjacent to code text
|
||||
--> tests/ui/doc/link_adjacent.rs:47:16
|
||||
|
|
||||
LL | /// So is this [`first`](x)[`second`](x)[`third`](x) arst
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: separate code snippets will be shown with a gap
|
||||
help: wrap the entire group in `<code>` tags
|
||||
|
|
||||
LL | /// So is this <code>[first](x)[second](x)[third](x)</code> arst
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: code link adjacent to code text
|
||||
--> tests/ui/doc/link_adjacent.rs:50:16
|
||||
|
|
||||
LL | /// So is this [`first`](x)`second`[`third`](x) arst
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: separate code snippets will be shown with a gap
|
||||
help: wrap the entire group in `<code>` tags
|
||||
|
|
||||
LL | /// So is this <code>[first](x)second[third](x)</code> arst
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue