mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
working naive with outside check_attrs
This commit is contained in:
parent
3093b291f6
commit
84219f45a3
25
clippy_lints/src/doc/empty_docs.rs
Normal file
25
clippy_lints/src/doc/empty_docs.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
use clippy_utils::diagnostics::span_lint_and_help;
|
||||||
|
use rustc_ast::Attribute;
|
||||||
|
use rustc_lint::LateContext;
|
||||||
|
|
||||||
|
use super::EMPTY_DOCS;
|
||||||
|
|
||||||
|
// TODO: Adjust the parameters as necessary
|
||||||
|
pub(super) fn check(cx: &LateContext<'_>, attrs: &[Attribute]) {
|
||||||
|
let doc_attrs: Vec<_> = attrs.iter().filter(|attr| attr.doc_str().is_some()).collect();
|
||||||
|
|
||||||
|
let span;
|
||||||
|
if let Some(first) = doc_attrs.first()
|
||||||
|
&& let Some(last) = doc_attrs.last()
|
||||||
|
{
|
||||||
|
span = first.span.with_hi(last.span.hi());
|
||||||
|
span_lint_and_help(
|
||||||
|
cx,
|
||||||
|
EMPTY_DOCS,
|
||||||
|
span,
|
||||||
|
"empty doc comment",
|
||||||
|
None,
|
||||||
|
"consider removing or filling it",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -23,10 +23,11 @@ use rustc_resolve::rustdoc::{
|
|||||||
};
|
};
|
||||||
use rustc_session::impl_lint_pass;
|
use rustc_session::impl_lint_pass;
|
||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
use rustc_span::{sym, Span, DUMMY_SP};
|
use rustc_span::{sym, Span};
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
mod empty_docs;
|
||||||
mod link_with_quotes;
|
mod link_with_quotes;
|
||||||
mod markdown;
|
mod markdown;
|
||||||
mod missing_headers;
|
mod missing_headers;
|
||||||
@ -403,17 +404,8 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(span) = get_empty_doc_combined_span(attrs, item.span)
|
if headers.empty && !item.span.is_dummy() {
|
||||||
&& headers.empty
|
empty_docs::check(cx, attrs);
|
||||||
{
|
|
||||||
span_lint_and_help(
|
|
||||||
cx,
|
|
||||||
EMPTY_DOCS,
|
|
||||||
span,
|
|
||||||
"empty doc comment",
|
|
||||||
None,
|
|
||||||
"consider removing or filling it",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match item.kind {
|
match item.kind {
|
||||||
@ -759,20 +751,3 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
|
|||||||
self.cx.tcx.hir()
|
self.cx.tcx.hir()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_empty_doc_combined_span(attrs: &[Attribute], item_span: Span) -> Option<Span> {
|
|
||||||
let mut attrs_span = DUMMY_SP;
|
|
||||||
if attrs.len() > 0 {
|
|
||||||
attrs_span = attrs
|
|
||||||
.iter()
|
|
||||||
.map(|attr| attr.span)
|
|
||||||
.fold(attrs[0].span, |acc, next| acc.to(next));
|
|
||||||
}
|
|
||||||
|
|
||||||
match (!item_span.is_dummy(), !attrs_span.is_dummy()) {
|
|
||||||
(true, true) => Some(item_span.shrink_to_lo().to(attrs_span)),
|
|
||||||
(true, false) => Some(item_span),
|
|
||||||
(false, true) => Some(attrs_span),
|
|
||||||
(false, false) => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -15,17 +15,26 @@ enum Warn {
|
|||||||
B,
|
B,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum WarnForB {
|
enum WarnA {
|
||||||
|
///
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum DontWarn {
|
||||||
/// it's ok
|
/// it's ok
|
||||||
A,
|
A,
|
||||||
///
|
///
|
||||||
B,
|
B,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = ""]
|
|
||||||
#[doc = ""]
|
#[doc = ""]
|
||||||
fn warn_about_this() {}
|
fn warn_about_this() {}
|
||||||
|
|
||||||
|
#[doc = ""]
|
||||||
|
#[doc = ""]
|
||||||
|
fn this_doesn_warn() {}
|
||||||
|
|
||||||
#[doc = "a fine function"]
|
#[doc = "a fine function"]
|
||||||
fn this_is_fine() {}
|
fn this_is_fine() {}
|
||||||
|
|
||||||
@ -33,11 +42,20 @@ fn warn_about_this_as_well() {
|
|||||||
//!
|
//!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
fn warn_inner_outer() {
|
||||||
|
//! what
|
||||||
|
}
|
||||||
|
|
||||||
fn this_is_ok() {
|
fn this_is_ok() {
|
||||||
//!
|
//!
|
||||||
//! inside the function
|
//! inside the function
|
||||||
}
|
}
|
||||||
|
|
||||||
fn warn() {
|
fn warn() {
|
||||||
/*! inside the function */
|
/*! */
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dont_warn() {
|
||||||
|
/*! dont warn me */
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,26 @@
|
|||||||
error: empty doc comment
|
error: empty doc comment
|
||||||
--> tests/ui/empty_docs.rs:10:1
|
--> tests/ui/empty_docs.rs:10:1
|
||||||
|
|
|
|
||||||
LL | / ///
|
LL | ///
|
||||||
LL | | enum Warn {
|
| ^^^
|
||||||
| |_
|
|
||||||
|
|
|
|
||||||
= help: consider removing or filling it
|
= help: consider removing or filling it
|
||||||
= note: `-D clippy::empty-docs` implied by `-D warnings`
|
= note: `-D clippy::empty-docs` implied by `-D warnings`
|
||||||
= help: to override `-D warnings` add `#[allow(clippy::empty_docs)]`
|
= help: to override `-D warnings` add `#[allow(clippy::empty_docs)]`
|
||||||
|
|
||||||
error: empty doc comment
|
error: empty doc comment
|
||||||
--> tests/ui/empty_docs.rs:18:1
|
--> tests/ui/empty_docs.rs:31:1
|
||||||
|
|
|
|
||||||
LL | / enum WarnForB {
|
LL | #[doc = ""]
|
||||||
LL | | /// it's ok
|
| ^^^^^^^^^^^
|
||||||
LL | | A,
|
|
||||||
LL | | ///
|
|
||||||
LL | | B,
|
|
||||||
LL | | }
|
|
||||||
| |_^
|
|
||||||
|
|
|
|
||||||
= help: consider removing or filling it
|
= help: consider removing or filling it
|
||||||
|
|
||||||
error: empty doc comment
|
error: empty doc comment
|
||||||
--> tests/ui/empty_docs.rs:32:1
|
--> tests/ui/empty_docs.rs:42:5
|
||||||
|
|
|
|
||||||
LL | / fn warn_about_this_as_well() {
|
LL | //!
|
||||||
LL | | //!
|
| ^^^
|
||||||
| |_______^
|
|
||||||
|
|
|
|
||||||
= help: consider removing or filling it
|
= help: consider removing or filling it
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user