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_session::impl_lint_pass;
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::{sym, Span, DUMMY_SP};
|
||||
use rustc_span::{sym, Span};
|
||||
use std::ops::Range;
|
||||
use url::Url;
|
||||
|
||||
mod empty_docs;
|
||||
mod link_with_quotes;
|
||||
mod markdown;
|
||||
mod missing_headers;
|
||||
@ -403,17 +404,8 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
return;
|
||||
};
|
||||
|
||||
if let Some(span) = get_empty_doc_combined_span(attrs, item.span)
|
||||
&& headers.empty
|
||||
{
|
||||
span_lint_and_help(
|
||||
cx,
|
||||
EMPTY_DOCS,
|
||||
span,
|
||||
"empty doc comment",
|
||||
None,
|
||||
"consider removing or filling it",
|
||||
);
|
||||
if headers.empty && !item.span.is_dummy() {
|
||||
empty_docs::check(cx, attrs);
|
||||
}
|
||||
|
||||
match item.kind {
|
||||
@ -759,20 +751,3 @@ fn nested_visit_map(&mut self) -> Self::Map {
|
||||
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,
|
||||
}
|
||||
|
||||
enum WarnForB {
|
||||
enum WarnA {
|
||||
///
|
||||
A,
|
||||
B,
|
||||
}
|
||||
|
||||
enum DontWarn {
|
||||
/// it's ok
|
||||
A,
|
||||
///
|
||||
B,
|
||||
}
|
||||
|
||||
#[doc = ""]
|
||||
#[doc = ""]
|
||||
fn warn_about_this() {}
|
||||
|
||||
#[doc = ""]
|
||||
#[doc = ""]
|
||||
fn this_doesn_warn() {}
|
||||
|
||||
#[doc = "a fine function"]
|
||||
fn this_is_fine() {}
|
||||
|
||||
@ -33,11 +42,20 @@ fn warn_about_this_as_well() {
|
||||
//!
|
||||
}
|
||||
|
||||
///
|
||||
fn warn_inner_outer() {
|
||||
//! what
|
||||
}
|
||||
|
||||
fn this_is_ok() {
|
||||
//!
|
||||
//! inside the function
|
||||
}
|
||||
|
||||
fn warn() {
|
||||
/*! inside the function */
|
||||
/*! */
|
||||
}
|
||||
|
||||
fn dont_warn() {
|
||||
/*! dont warn me */
|
||||
}
|
||||
|
@ -1,33 +1,26 @@
|
||||
error: empty doc comment
|
||||
--> tests/ui/empty_docs.rs:10:1
|
||||
|
|
||||
LL | / ///
|
||||
LL | | enum Warn {
|
||||
| |_
|
||||
LL | ///
|
||||
| ^^^
|
||||
|
|
||||
= help: consider removing or filling it
|
||||
= note: `-D clippy::empty-docs` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::empty_docs)]`
|
||||
|
||||
error: empty doc comment
|
||||
--> tests/ui/empty_docs.rs:18:1
|
||||
--> tests/ui/empty_docs.rs:31:1
|
||||
|
|
||||
LL | / enum WarnForB {
|
||||
LL | | /// it's ok
|
||||
LL | | A,
|
||||
LL | | ///
|
||||
LL | | B,
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | #[doc = ""]
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= help: consider removing or filling it
|
||||
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user