-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add lint for broken doc links #13696
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Jarcho (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
8d859c9
to
6ff53c7
Compare
Just noticed there are tests failing due to a false positive like this:
This will be considered a broken link although actually it isn't. I guess in order to fix it I won't be able to check |
I will try to use similar approach used on https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/tabs_in_doc_comments.rs |
640f282
to
8deb383
Compare
☔ The latest upstream changes (presumably 8298da7) made this pull request unmergeable. Please resolve the merge conflicts. |
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 for the long wait. Left a couple of specific comments.
One thing you'll need to do is take the text input from the markdown parser. Currently you'll be linting inside code and html sections. Doc attribute can also contain multiple lines.
@Jarcho thanks for taking the time to review this. I applied two of your code improvement suggestions. I am a bit confused though about these others comments:
Do you mean this lint should run on this parser's output instead of running before that step, which is done against the rust AST attributes? I tried doing that as the first approach, but the
It is being applied only for
This current logic is checking for broken links across multiple lines, so I am confused what you mean on this one, as it is already checking for multiple lines. |
@rustbot review |
Yes. And markdown contain code and html sections. Neither of which will try to parse links.
Right now you're assuming that each attribute contains a single line. This is normally true, but isn't guaranteed. |
@Jarcho So, to make sure I got it right:
Are you saying About this other one:
Would attributes with multiple lines be represented with |
I don't see why that would stop this from working. You can use the span given to the callback to know where to start parsing the input string for the link's destination.
rustdoc joins all the doc attributes together with |
Ok. I will give the markdown parser another try.
rustdoc might do that, but that is not what I have seen on clippy. Each line is a different |
hey @Jarcho, I just pushed some temporary changes to confirm I am on the right direction. I added a new function to the
So, as we can see the @rustbot review |
hi @Jarcho, I have not heard back from you in a month, hopefully everything is alright with you and you are only taking a time off. If you are not back yet, is there someone else that could assist me with this PR? |
Sorry for the wait. Reading from the link title span is what I had in mind.
Clippy is combining With the implementation running through the broken links handler this will be handled properly. |
@rustbot review |
clippy_lints/src/doc/mod.rs
Outdated
fn fake_broken_link_callback<'a>(_: BrokenLink<'_>) -> Option<(CowStr<'a>, CowStr<'a>)> { | ||
Some(("fake".into(), "fake".into())) | ||
} | ||
|
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.
I had to move this function declaration down so it has access to doc and fragments variables.
hey @Jarcho could you review this please? |
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.
Again, sorry for the long delay. Behaviour wise this looks to be fine. Can you rebase this so we can get a lintcheck run on it please?
This comment has been minimized.
This comment has been minimized.
776fe26
to
f577d71
Compare
b5effa4
to
bd214be
Compare
@rustbot review |
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.
Looks like everything is good. Thank you.
Can you just squash the commits down please.
Ping @maxclaus from triage. This is only waiting on the commits being squashed. |
Fix false positives on broken link detection Refactor variable names Fix doc comment about broken link lint Refactor, remove not used variable Improve broken link to catch more cases and span point to whole link Include reason why a link is considered broken Drop some checker because rustdoc already warn about them Refactor to use a single enum instead of multiple bool variables Fix lint warnings Rename function to collect broken links Warn directly instead of collecting all entries first Iterate directly rather than collecting Temporary change to confirm with code reviewer the next steps Handle broken links as part of the fake_broken_link_callback handler Simplify broken link detection without state machine usage Fix typos Add url check to reduce false positives Drop reason enum as there is only one reason Fix duplicated diagnostics Fix linter
bd214be
to
8964f6e
Compare
@Jarcho done |
fixes #2179
changelog: [
doc_broken_link
]: Add pedantic lint to catch broken doc links that won't produce a link tag by rustdoc.