Skip to content
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

WIP: empty_doc #11633

Closed
wants to merge 9 commits into from
Closed

WIP: empty_doc #11633

wants to merge 9 commits into from

Conversation

SET001
Copy link

@SET001 SET001 commented Oct 6, 2023

Fixes #9931

changelog: [`empty_doc`]: Detects documentation that is empty.

@rustbot
Copy link
Collaborator

rustbot commented Oct 6, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Alexendoo (or someone else) soon.

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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 6, 2023
Copy link
Member

@blyxyas blyxyas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good for a first patch ❤️, mainly just some documentation rephrasing and refactoring to fit better with the rest of the codebase 🐈

clippy_lints/src/empty_docs.rs Outdated Show resolved Hide resolved
clippy_lints/src/empty_docs.rs Outdated Show resolved Hide resolved
clippy_lints/src/empty_docs.rs Outdated Show resolved Hide resolved
clippy_lints/src/empty_docs.rs Outdated Show resolved Hide resolved
clippy_lints/src/empty_docs.rs Outdated Show resolved Hide resolved
Comment on lines 6 to 26
//!

//! valid doc comment

//!!

//!! valid doc comment

///

/// valid doc comment

/**
*
*/

/**
* valid block doc comment
*/

pub mod inner_module {}
Copy link
Member

@Alexendoo Alexendoo Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of these are actually empty documentation, this is ~equivalent to

//!
//! valid doc comment
//!!
//!! valid doc comment

///
/// valid doc comment
/// 
/// valid block doc comment

Because doc comments and #[doc] attributes are merged together

This really should go in doc.rs where this merging/parsing is all handled already

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alexendoo according to https://doc.rust-lang.org/reference/comments.html there are one line and block doc comments.
What you show in your example is 8 separate one-line doc comments. They are not being merged in 2, just because there are no line breaks within them. So lint in this PR will trigger on lines 1, 3, 5, 6 (and I'm updating the test to demonstrate this).

As for block doc comments, I assume they might have empty lines (for formatting purposes) because the definition of empty for a block comment is when all lines are empty.

Tbh I do not understand the part about merging with #[doc] attributes. Can you please explain?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really should go in doc.rs where this merging/parsing is all handled already

there is no much merging/parsing happening in this current lint. The idea is to have all doc-related lints in doc.rs?

Copy link
Member

@Alexendoo Alexendoo Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not saying the attributes are merged in the AST/HIR, but the multiple attributes representing doc comments are merged into a single piece of documentation by rustdoc, be they line comments, block comments or #[doc = ".."] attributes

My example was to represent what rustdoc approximately sees as the documentation, not to say that doc comments get converted to line comments. A screenshot may be clearer:

    ///

    /// valid doc comment

    /**
     *
     */

    /**
     * valid block doc comment
     */

    pub mod inner_module {}

image

The whitespace between the doc comments are not significant, e.g.

/// a

///

/// b

is the same as

/// a
///
/// b

But we certainly don't want to lint the middle line comment, it's significant because it causes a and b to be separate paragraphs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no much merging/parsing happening in this current lint. The idea is to have all doc-related lints in doc.rs?

Yeah, it could go here

if doc.is_empty() {
return Some(DocHeaders::default());
}

With .is_empty() being changed to check that doc only contains whitespace if needed, you can use https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/rustdoc/fn.span_of_fragments.html on fragments to get the span

SET001 and others added 6 commits October 7, 2023 12:49
remove empty line

Co-authored-by: Alejandra González <blyxyas@gmail.com>
Co-authored-by: Alejandra González <blyxyas@gmail.com>
Co-authored-by: Alejandra González <blyxyas@gmail.com>
Co-authored-by: Alejandra González <blyxyas@gmail.com>
@rustbot
Copy link
Collaborator

rustbot commented Oct 7, 2023

There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

You can start a rebase with the following commands:

$ # rebase
$ git rebase -i master
$ # delete any merge commits in the editor that appears
$ git push --force-with-lease

The following commits are merge commits:

@Alexendoo Alexendoo added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Oct 16, 2023
@bors
Copy link
Collaborator

bors commented Nov 14, 2023

☔ The latest upstream changes (presumably #11791) made this pull request unmergeable. Please resolve the merge conflicts.

comment
.trim()
.split("\n")
.map(|comment| comment.trim().trim_matches('*').trim_matches('!'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that one shouldn't be needed.

.trim()
.split("\n")
.map(|comment| comment.trim().trim_matches('*').trim_matches('!'))
.collect::<Vec<&str>>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a missing .filter(|line| !line.is_empty())

@lucarlig lucarlig mentioned this pull request Feb 24, 2024
@xFrednet
Copy link
Member

Hey @SET001, this is a ping from triage, since there hasn't been any activity in some time. Are you still planning to continue this implementation?

If you have any questions, you're always welcome to ask them in this PR or on Zulip.

@rustbot author

@y21
Copy link
Member

y21 commented Mar 31, 2024

Looks like this was continued in #12342 because of inactivity. The lint exists now: https://rust-lang.github.io/rust-clippy/master/index.html#/empty_docs

@xFrednet
Copy link
Member

Thank you for the comment @y21. Then let's close this one.

@SET001 thank you for the time you put into this PR!

@xFrednet xFrednet closed this Mar 31, 2024
@SET001
Copy link
Author

SET001 commented Apr 4, 2024

@xFrednet hi, I do not plan to continue work on this implementation. Happy that someone finally did this )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect documentation that is empty
8 participants