Add configuration to lint missing docs of pub(crate)
items
This commit is contained in:
parent
8a9860901f
commit
c6692a8b42
@ -665,12 +665,13 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
||||
))
|
||||
});
|
||||
let doc_valid_idents = conf.doc_valid_idents.iter().cloned().collect::<FxHashSet<_>>();
|
||||
let only_check_missing_docs_in_crate_items = conf.only_check_missing_docs_in_crate_items;
|
||||
store.register_late_pass(move |_| Box::new(doc::DocMarkdown::new(doc_valid_idents.clone())));
|
||||
store.register_late_pass(|_| Box::new(neg_multiply::NegMultiply));
|
||||
store.register_late_pass(|_| Box::new(mem_forget::MemForget));
|
||||
store.register_late_pass(|_| Box::new(let_if_seq::LetIfSeq));
|
||||
store.register_late_pass(|_| Box::new(mixed_read_write_in_expression::EvalOrderDependence));
|
||||
store.register_late_pass(|_| Box::new(missing_doc::MissingDoc::new()));
|
||||
store.register_late_pass(move |_| Box::new(missing_doc::MissingDoc::new(only_check_missing_docs_in_crate_items)));
|
||||
store.register_late_pass(|_| Box::new(missing_inline::MissingInline));
|
||||
store.register_late_pass(move |_| Box::new(exhaustive_items::ExhaustiveItems));
|
||||
store.register_late_pass(|_| Box::new(match_result_ok::MatchResultOk));
|
||||
|
@ -12,7 +12,7 @@ use if_chain::if_chain;
|
||||
use rustc_ast::ast::{self, MetaItem, MetaItemKind};
|
||||
use rustc_hir as hir;
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::ty::DefIdTree;
|
||||
use rustc_middle::ty::{DefIdTree, Visibility};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::def_id::CRATE_DEF_ID;
|
||||
use rustc_span::source_map::Span;
|
||||
@ -35,6 +35,8 @@ declare_clippy_lint! {
|
||||
}
|
||||
|
||||
pub struct MissingDoc {
|
||||
/// FIXME: docs
|
||||
crate_items_only: bool,
|
||||
/// Stack of whether #[doc(hidden)] is set
|
||||
/// at each level which has lint attributes.
|
||||
doc_hidden_stack: Vec<bool>,
|
||||
@ -43,14 +45,15 @@ pub struct MissingDoc {
|
||||
impl Default for MissingDoc {
|
||||
#[must_use]
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
Self::new(false)
|
||||
}
|
||||
}
|
||||
|
||||
impl MissingDoc {
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
pub fn new(crate_items_only: bool) -> Self {
|
||||
Self {
|
||||
crate_items_only,
|
||||
doc_hidden_stack: vec![false],
|
||||
}
|
||||
}
|
||||
@ -128,6 +131,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||
}
|
||||
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
|
||||
if self.crate_items_only {
|
||||
let vis = cx.tcx.visibility(it.owner_id.to_def_id());
|
||||
if vis != Visibility::Public && vis != Visibility::Restricted(CRATE_DEF_ID.into()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
match it.kind {
|
||||
hir::ItemKind::Fn(..) => {
|
||||
// ignore main()
|
||||
|
@ -454,6 +454,10 @@ define_Conf! {
|
||||
/// configuration will cause restriction lints to trigger even
|
||||
/// if no suggestion can be made.
|
||||
(suppress_restriction_lint_in_const: bool = false),
|
||||
/// Lint: MISSING_DOCS_IN_PRIVATE_ITEMS.
|
||||
///
|
||||
/// FIXME: docs
|
||||
(only_check_missing_docs_in_crate_items: bool = false),
|
||||
}
|
||||
|
||||
/// Search for the configuration file.
|
||||
|
1
tests/ui-toml/pub_crate_missing_docs/clippy.toml
Normal file
1
tests/ui-toml/pub_crate_missing_docs/clippy.toml
Normal file
@ -0,0 +1 @@
|
||||
only-check-missing-docs-in-crate-items = true
|
@ -0,0 +1,32 @@
|
||||
//! this is crate
|
||||
#![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() {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
my_mod::crate_with_docs();
|
||||
my_mod::crate_no_docs();
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
error: missing documentation for a function
|
||||
--> $DIR/pub_crate_missing_doc.rs:11: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:14:5
|
||||
|
|
||||
LL | pub(super) fn super_no_docs() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: missing documentation for a function
|
||||
--> $DIR/pub_crate_missing_doc.rs:22:9
|
||||
|
|
||||
LL | pub(crate) fn sub_crate_no_docs() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user