-
Notifications
You must be signed in to change notification settings - Fork 1.7k
doc_link_code: add check for links with code spans that render weird #14121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,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; |
This file contains hidden or 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,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; |
This file contains hidden or 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,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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to say but this but is absolutely unreadable. ^^'
Can't you check the tag instead and see if more than one code (even if embedded into an intra-doc link) instead? Code might be a bit longer but I also expect it to be much simpler to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The simpler way I could come up with to implement this requires the checker to be able to "skip" a
Code
event.To do that, I need an entirely separate loop just for this lint. But the code is a lot more readable that way.