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

Split missing_docs_in_private_items into various lints #5736

Open
jhpratt opened this issue Jun 22, 2020 · 7 comments
Open

Split missing_docs_in_private_items into various lints #5736

jhpratt opened this issue Jun 22, 2020 · 7 comments
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@jhpratt
Copy link
Member

jhpratt commented Jun 22, 2020

Would it be feasible and acceptable to split missing_docs_in_private_items into a few different lints? I find myself quite frequently adding #[allow] to enum variants and struct fields, in large part because the naming is typically self-explanatory. Even splitting the lint in two (fields/variants and everything else) would be incredibly useful for me, and would avoid cluttering declarations with unnecessary (imo) #[allow] attributes.

Having different lints for modules and top-level crate documentation would also be great, but are less important to me.

@flip1995 flip1995 added S-needs-discussion Status: Needs further discussion before merging or work can be started C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy labels Jun 22, 2020
@jhpratt
Copy link
Member Author

jhpratt commented Jul 25, 2020

A quick rg and tokei on a project of mine (admittedly with a large number of structs) shows that I have #[allow(clippy::missing_docs_in_private_items)] 64 times out of 1387 total lines of Rust code (4.6% of all lines). All 64 are on enum variants and struct fields.

If this is something that is desired, I'd be interested in contributing once I get some free time.

@flip1995
Copy link
Member

Maybe even better: Don't split it, but make it configurable, so that you can configure it to only warn on functions for example.

@jhpratt
Copy link
Member Author

jhpratt commented Jul 28, 2020

That could certainly work, and would be backwards-compatible as well.

@flip1995 flip1995 removed the S-needs-discussion Status: Needs further discussion before merging or work can be started label Jul 28, 2020
@jhpratt
Copy link
Member Author

jhpratt commented Aug 3, 2020

Another situation I've found myself allowing the lint regularly is statics, consts, structs, etc. that are only used within the function they're defined in.

@flip1995
Copy link
Member

flip1995 commented Aug 4, 2020

I think we should not lint at all on definitions inside a function.

@pvdrz
Copy link
Contributor

pvdrz commented Feb 1, 2023

On bindgen we do this hack to keep reusable code documented by marking it as public but putting it inside a module that's only public if compiled with a certain feature: https://github.com/rust-lang/rust-bindgen/blob/a7ff8e136027c9542f65eca97a7ff3c0b870518d/bindgen/lib.rs#L36-L50

This has the undesired effect of not being able to detect unused items because they are public.

If this lint could be configured to detect missing docs in pub(crate) items, we could remove this hack and remove the downside of not detecting unused code.

Let me know if this would be a reasonable change and I will start working on it.

@flip1995
Copy link
Member

flip1995 commented Feb 2, 2023

I could see a config option, that you can set to specify if the lint should lint on all private items or only on crate items. All private items should be the default though. Let me know if you need help implementing this. clippy_lints/src/utils/conf.rs is a good starting point to look at for adding config options.

bors added a commit that referenced this issue Feb 20, 2023
Add configuration to lint missing docs of `pub(crate)` items

Fixes this: #5736 (comment)

TODO:
- [x] Needs docs
- [x] Needs better names
- [x] Should `pub` items be checked to when this new option is enabled? I'm saying no because `missing_docs` already exists

`@flip1995` I'd like to get some input from you :)

---

changelog: Enhancement: [`missing_docs_in_private_items`]: Added new configuration `missing-docs-in-crate-items` to lint on items visible within the current crate. For example, `pub(crate)` items.
[#10303](#10303)
<!-- changelog_checked -->
bors added a commit that referenced this issue Nov 3, 2024
Don't lint unnamed consts and nested items within functions in `missing_docs_in_private_items`

With this change we no longer require doc comments for `const _: ()` items as well as nested items in functions or other bodies. In both of those cases, rustdoc generates no documentation even with `--document-private-items`.

Fixes #13427 (first commit)
Fixes #13298 (second commit)
cc #5736 (comment)

changelog: [`missing_docs_in_private_items`]: avoid linting in more cases where rustdoc generates no documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

No branches or pull requests

4 participants