Skip to content

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 2 commits into from
Feb 14, 2025

Conversation

notriddle
Copy link
Contributor

This is the lint described at rust-lang/rust#136308 (comment) that recommends using HTML to nest links inside code.

changelog: [doc_link_code]: warn when a link with code and a code span are back-to-back

@rustbot
Copy link
Collaborator

rustbot commented Jan 30, 2025

r? @Centri3

rustbot has assigned @Centri3.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 30, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
This is the lint described at
rust-lang/rust#136308 (comment)
that recommends using HTML to nest links inside code.
@notriddle
Copy link
Contributor Author

cc @GuillaumeGomez

@GuillaumeGomez
Copy link
Member

Seems surprising to make it a clippy lint. Why not a rustdoc lint instead?

@notriddle
Copy link
Contributor Author

Implementing it in Clippy gives us a chance to shake out any unforeseen corner cases before uplifting it in Rustdoc.

@Centri3
Copy link
Member

Centri3 commented Feb 8, 2025

Oh gosh, I don't feel qualified for this PR at all. @GuillaumeGomez you're free to review this as you know rustdoc well, otherwise I'll reroll.

@GuillaumeGomez
Copy link
Member

I'll review soon. I'm done on my more pressing stuff. ;)

let mut events = events.peekable();

while let Some((event, range)) = events.next() {
code_cluster = match (code_cluster, &event) {
Copy link
Member

@GuillaumeGomez GuillaumeGomez Feb 10, 2025

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.

Copy link
Contributor Author

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.

Verified

This commit was signed with the committer’s verified signature.
ggerganov Georgi Gerganov
By using a separate loop, I can just skip nodes that I don't want
to process twice, instead of having to hand-build a state machine
with an enum.
@GuillaumeGomez
Copy link
Member

This looks much better, thanks!

Looks all good to me @Centri3. :)

@Centri3
Copy link
Member

Centri3 commented Feb 14, 2025

Thanks for reviewing!

@Centri3 Centri3 added this pull request to the merge queue Feb 14, 2025
Merged via the queue into rust-lang:master with commit 50ecb6e Feb 14, 2025
11 checks passed
@notriddle notriddle deleted the codecluster branch February 14, 2025 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants