-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add new comment_within_doc
lint
#15260
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
base: master
Are you sure you want to change the base?
Add new comment_within_doc
lint
#15260
Conversation
Some changes occurred in clippy_lints/src/doc cc @notriddle |
Lintcheck changes for 6634d4b
This comment will be updated if you push new changes |
736e910
to
938e647
Compare
If I understand correctly, this finds surrounding cases like: /// ...
// ...
/// ...
But at least #15245 was intended to only lint on empty ones like: /// ...
//
/// ...
The reason was to be more conservative to avoid false positives -- at least in the Linux kernel we expect to be able to write comments together to docs, and we already have 6 adjacent cases we would hit, e.g. one of them: /// Use the given initializer to in-place initialize a `T`.
///
/// If `T: !Unpin` it will not be able to move afterwards.
// We don't implement `InPlaceInit` because `ListArc` is implicitly pinned. This is similar to
// what we do for `Arc`.
#[inline]
pub fn pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> Result<Self, E> Moreover, I think we should also probably want to lint on adjacent cases, not just surrounded cases, e.g. /// ...
// So I think there are these cases:
Of those, 1 and 3 seem both pretty safe to enable and that was my original intention with the issue. 4 is not something we would want at least for the Linux kernel, since we expect to write those (and we have 6 cases already). And finally 3 could perhaps be interesting for some projects -- in the Linux kernel we don't have any case yet (if I grepped correctly), but when I wrote our coding guidelines about comments I expected it to be possible (https://docs.kernel.org/rust/coding-guidelines.html#comments): /// # Examples
///
// TODO: Find a better example.
/// ```
/// let foo = f(42);
/// ```
|
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.
Not sure if this us supposed to be empty comments only, or if it's supposed to be any comment sandwiched between doc comment lines.
I'm not sure if blank-lines-only would have enough true positives to justify maintaining it. Has this happened more than once?
tests/ui/comment_within_doc.fixed
Outdated
@@ -0,0 +1,23 @@ | |||
#![warn(clippy::comment_within_doc)] | |||
|
|||
//! Hello//!/ oups |
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.
That "fix" is wrong, isn't it?
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.
Completely wrong, good catch!
@ojeda I think checking for comments surrounded by doc comments is the right call. You can easily put an empty line before or after a code comment to not trigger this lint (which should be suggested by this lint too). Like that, we can handle all cases at once. I don't think there is any reason to forget a |
Hmm... Do you mean an empty
I am not sure what you mean. If you mean forgotten by the user, that is what triggered this issue, no? i.e. a missing slash. |
The only case where it triggers this lint is: ///
//
///
Empty or not. If you add an empty line: ///
//
///
Or your code comment is on multiple lines: ///
//
//
///
The lint is not triggered.
I mean, forgetting a |
0229d88
to
ec15494
Compare
ec15494
to
6634d4b
Compare
Thanks, that is clearer. Then this seems a different lint. What we would normally expect to be able to write (and thus not lint) things like: /// empty or not
// not empty /// empty or not
// not empty
/// empty or not
/// empty or not
// not empty
// empty
// not empty
/// empty or not
However, we would consider these to be likely mistakes (and thus lint): /// empty or not
// empty
/// empty or not
/// empty or not
// empty
// empty
/// empty or not
/// empty or not
// empty // empty
/// empty or not
Thus that is why I suggested linting for empty Now, if I understand you correctly, with this lint, we would need to write this case: /// empty or not
// not empty
/// empty or not
as: /// empty or not
// empty
// not empty
/// empty or not
It is not the end of the world, since it is quite uncommon. (A fully empty line looks worse, I think, so I don't think we would do that). And for this case, your lint wouldn't trigger, but it sounds like it is likely a mistake: /// empty or not
// empty
// empty
/// empty or not
Finally, there are other possibilities that are likely mistakes (in our version, I mean) but that may be best not to lint, or it could be a different lint, e.g. having an starting or ending empty /// empty or not
// empty
// not empty
/// empty or not
/// empty or not
/// empty
(With your lint the former would be OK since that is precisely the way to allow a comment). |
Fixes #15245.
Considering how many false positive we might trigger with this lint, I put it into
pedantic
.cc @ojeda
r? @samueltardieu
changelog: Add new
comment_within_doc
lintSummary Notes
Managed by
@rustbot
—see help for details