Auto merge of #10303 - pvdrz:pub_crate_missing_docs, r=giraffate

Add configuration to lint missing docs of `pub(crate)` items

Fixes this: https://github.com/rust-lang/rust-clippy/issues/5736#issuecomment-1412442404

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](https://github.com/rust-lang/rust-clippy/pull/10303)
<!-- changelog_checked -->
This commit is contained in:
bors 2023-02-20 23:59:07 +00:00
commit b1cf1e7b6a
8 changed files with 152 additions and 10 deletions

View file

@ -0,0 +1 @@
missing-docs-in-crate-items = true

View file

@ -0,0 +1,59 @@
//! this is crate
#![allow(missing_docs)]
#![warn(clippy::missing_docs_in_private_items)]
/// this is mod
mod my_mod {
/// some docs
fn priv_with_docs() {}
fn priv_no_docs() {}
/// some docs
pub(crate) fn crate_with_docs() {}
pub(crate) fn crate_no_docs() {}
/// some docs
pub(super) fn super_with_docs() {}
pub(super) fn super_no_docs() {}
mod my_sub {
/// some docs
fn sub_priv_with_docs() {}
fn sub_priv_no_docs() {}
/// some docs
pub(crate) fn sub_crate_with_docs() {}
pub(crate) fn sub_crate_no_docs() {}
/// some docs
pub(super) fn sub_super_with_docs() {}
pub(super) fn sub_super_no_docs() {}
}
/// some docs
pub(crate) struct CrateStructWithDocs {
/// some docs
pub(crate) crate_field_with_docs: (),
pub(crate) crate_field_no_docs: (),
/// some docs
priv_field_with_docs: (),
priv_field_no_docs: (),
}
pub(crate) struct CrateStructNoDocs {
/// some docs
pub(crate) crate_field_with_docs: (),
pub(crate) crate_field_no_docs: (),
/// some docs
priv_field_with_docs: (),
priv_field_no_docs: (),
}
}
/// some docs
type CrateTypedefWithDocs = String;
type CrateTypedefNoDocs = String;
/// some docs
pub type PubTypedefWithDocs = String;
pub type PubTypedefNoDocs = String;
fn main() {
my_mod::crate_with_docs();
my_mod::crate_no_docs();
}

View file

@ -0,0 +1,52 @@
error: missing documentation for a function
--> $DIR/pub_crate_missing_doc.rs:12:5
|
LL | pub(crate) fn crate_no_docs() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings`
error: missing documentation for a function
--> $DIR/pub_crate_missing_doc.rs:15:5
|
LL | pub(super) fn super_no_docs() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function
--> $DIR/pub_crate_missing_doc.rs:23:9
|
LL | pub(crate) fn sub_crate_no_docs() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a struct field
--> $DIR/pub_crate_missing_doc.rs:33:9
|
LL | pub(crate) crate_field_no_docs: (),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a struct
--> $DIR/pub_crate_missing_doc.rs:39:5
|
LL | / pub(crate) struct CrateStructNoDocs {
LL | | /// some docs
LL | | pub(crate) crate_field_with_docs: (),
LL | | pub(crate) crate_field_no_docs: (),
... |
LL | | priv_field_no_docs: (),
LL | | }
| |_____^
error: missing documentation for a struct field
--> $DIR/pub_crate_missing_doc.rs:42:9
|
LL | pub(crate) crate_field_no_docs: (),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a type alias
--> $DIR/pub_crate_missing_doc.rs:51:1
|
LL | type CrateTypedefNoDocs = String;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 7 previous errors

View file

@ -33,6 +33,7 @@ error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown fie
max-struct-bools
max-suggested-slice-pattern-length
max-trait-bounds
missing-docs-in-crate-items
msrv
pass-by-value-size-limit
single-char-binding-names-threshold