-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add new lint doc_include_without_cfg
#13625
base: master
Are you sure you want to change the base?
Add new lint doc_include_without_cfg
#13625
Conversation
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.
Very very good PR, just a nit.
I'll open the FCP now, because I'm sure this review cycle will go fast
&& normal.item.path == sym::doc | ||
&& let AttrArgs::Eq(_, AttrArgsEq::Hir(ref meta)) = normal.item.args | ||
&& !attr.span.contains(meta.span) | ||
&& let Some(snippet) = snippet_opt(cx, attr.span) |
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've looked for way to remove this snippet, but as the include_macro
expands before we check the #[doc]
attribute, I don't think it's possible.
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.
Adding a comment will still be a good improvement. :)
&& !attr.span.contains(meta.span) | ||
&& let Some(snippet) = snippet_opt(cx, attr.span) | ||
&& let Some(start) = snippet.find('[') | ||
&& let Some(end) = snippet.rfind(']') |
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.
Maybe a "we cannot remove this because a #[doc = include]
can occupy several lines" comment would be useful here, I also checked removing these, but it doesn't seem possible =^w^=
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.
Could you add a test for one of the other ways that the #[doc]
attribute can behave?
#![doc(html_playground_url = "https://playground.example.com/")]
And such
43466bb
to
a1a88d9
Compare
d0caf07
to
fbf36cc
Compare
Added code comments and added extra tests. |
@GuillaumeGomez Using macros may trigger false positives (found by looking at the lintcheck diff): macro_rules! tst {
($(#[$attr:meta])*) => {
$(#[$attr])*
fn main() {
println!("Hello, world!");
}
}
}
tst!{
/// This is a test with no included file
} will trigger with:
|
Great catch! If the attribute is generated from a macro, the lint now ignores it. |
18d01ce
to
5111470
Compare
Fixed formatting... |
Great. The new hits in |
afe4556
to
400894d
Compare
They were false positives. So we're forced to check that the snippet is indeed |
It's becoming more and more common to see people including markdown files in their code using
doc = include_str!("...")
, which is great. However, often there is no condition on this include, which is not great because it slows down compilation and might trigger recompilation if these files are updated.This lint aims at fixing this situation.
changelog: Add new lint
doc_include_without_cfg