mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-11 07:34:18 +00:00
Auto merge of #3883 - daxpedda:missing_docs_in_private_items, r=phansch
Add `doc(include = ...)` detection to `missing_docs_in_private_items` The whole `missing documentation in crate` part doesn't have any tests. If I should add test cases tell me.
This commit is contained in:
commit
e7806413c6
5 changed files with 39 additions and 2 deletions
|
@ -6,11 +6,12 @@
|
|||
//
|
||||
|
||||
use crate::utils::{in_macro, span_lint};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir;
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
|
||||
use rustc::ty;
|
||||
use rustc::{declare_tool_lint, lint_array};
|
||||
use syntax::ast;
|
||||
use syntax::ast::{self, MetaItem, MetaItemKind};
|
||||
use syntax::attr;
|
||||
use syntax::source_map::Span;
|
||||
|
||||
|
@ -52,6 +53,20 @@ impl MissingDoc {
|
|||
*self.doc_hidden_stack.last().expect("empty doc_hidden_stack")
|
||||
}
|
||||
|
||||
fn has_include(meta: Option<MetaItem>) -> bool {
|
||||
if_chain! {
|
||||
if let Some(meta) = meta;
|
||||
if let MetaItemKind::List(list) = meta.node;
|
||||
if let Some(meta) = list.get(0);
|
||||
if let Some(name) = meta.name();
|
||||
then {
|
||||
name == "include"
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_missing_docs_attrs(
|
||||
&self,
|
||||
cx: &LateContext<'_, '_>,
|
||||
|
@ -74,7 +89,9 @@ impl MissingDoc {
|
|||
return;
|
||||
}
|
||||
|
||||
let has_doc = attrs.iter().any(|a| a.is_value_str() && a.name() == "doc");
|
||||
let has_doc = attrs
|
||||
.iter()
|
||||
.any(|a| a.name() == "doc" && (a.is_value_str() || Self::has_include(a.meta())));
|
||||
if !has_doc {
|
||||
span_lint(
|
||||
cx,
|
||||
|
|
3
tests/ui/missing-doc-crate-missing.rs
Normal file
3
tests/ui/missing-doc-crate-missing.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
#![warn(clippy::missing_docs_in_private_items)]
|
||||
|
||||
fn main() {}
|
12
tests/ui/missing-doc-crate-missing.stderr
Normal file
12
tests/ui/missing-doc-crate-missing.stderr
Normal file
|
@ -0,0 +1,12 @@
|
|||
error: missing documentation for crate
|
||||
--> $DIR/missing-doc-crate-missing.rs:1:1
|
||||
|
|
||||
LL | / #![warn(clippy::missing_docs_in_private_items)]
|
||||
LL | |
|
||||
LL | | fn main() {}
|
||||
| |____________^
|
||||
|
|
||||
= note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
5
tests/ui/missing-doc-crate.rs
Normal file
5
tests/ui/missing-doc-crate.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
#![warn(clippy::missing_docs_in_private_items)]
|
||||
#![feature(external_doc)]
|
||||
#![doc(include = "../../README.md")]
|
||||
|
||||
fn main() {}
|
0
tests/ui/missing-doc-crate.stderr
Normal file
0
tests/ui/missing-doc-crate.stderr
Normal file
Loading…
Reference in a new issue