Set the limit of characters to 200 and don't run the lint on private items unless config allows it
This commit is contained in:
parent
855a9d1377
commit
f455587fee
6 changed files with 37 additions and 18 deletions
|
|
@ -493,7 +493,13 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
|
|||
|
||||
match cx.tcx.hir_node(cx.last_node_with_lint_attrs) {
|
||||
Node::Item(item) => {
|
||||
too_long_first_doc_paragraph::check(cx, attrs, item.kind, headers.first_paragraph_len);
|
||||
too_long_first_doc_paragraph::check(
|
||||
cx,
|
||||
item,
|
||||
attrs,
|
||||
headers.first_paragraph_len,
|
||||
self.check_private_items,
|
||||
);
|
||||
match item.kind {
|
||||
ItemKind::Fn(sig, _, body_id) => {
|
||||
if !(is_entrypoint_fn(cx, item.owner_id.to_def_id())
|
||||
|
|
@ -627,9 +633,8 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
|
|||
acc
|
||||
});
|
||||
doc.pop();
|
||||
let doc = doc.trim();
|
||||
|
||||
if doc.is_empty() {
|
||||
if doc.trim().is_empty() {
|
||||
if let Some(span) = span_of_fragments(&fragments) {
|
||||
span_lint_and_help(
|
||||
cx,
|
||||
|
|
@ -653,7 +658,7 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
|
|||
cx,
|
||||
valid_idents,
|
||||
parser.into_offset_iter(),
|
||||
doc,
|
||||
&doc,
|
||||
Fragments {
|
||||
fragments: &fragments,
|
||||
doc: &doc,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use rustc_ast::ast::Attribute;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::ItemKind;
|
||||
use rustc_hir::{Item, ItemKind};
|
||||
use rustc_lint::LateContext;
|
||||
|
||||
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
|
||||
|
|
@ -10,13 +10,17 @@ use super::TOO_LONG_FIRST_DOC_PARAGRAPH;
|
|||
|
||||
pub(super) fn check(
|
||||
cx: &LateContext<'_>,
|
||||
item: &Item<'_>,
|
||||
attrs: &[Attribute],
|
||||
item_kind: ItemKind<'_>,
|
||||
mut first_paragraph_len: usize,
|
||||
check_private_items: bool,
|
||||
) {
|
||||
if first_paragraph_len <= 100
|
||||
if !check_private_items && !cx.effective_visibilities.is_exported(item.owner_id.def_id) {
|
||||
return;
|
||||
}
|
||||
if first_paragraph_len <= 200
|
||||
|| !matches!(
|
||||
item_kind,
|
||||
item.kind,
|
||||
ItemKind::Static(..)
|
||||
| ItemKind::Const(..)
|
||||
| ItemKind::Fn(..)
|
||||
|
|
@ -32,6 +36,7 @@ pub(super) fn check(
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
let mut spans = Vec::new();
|
||||
let mut should_suggest_empty_doc = false;
|
||||
|
||||
|
|
@ -42,7 +47,7 @@ pub(super) fn check(
|
|||
let doc = doc.trim();
|
||||
if spans.len() == 1 {
|
||||
// We make this suggestion only if the first doc line ends with a punctuation
|
||||
// because if might just need to add an empty line with `///`.
|
||||
// because it might just need to add an empty line with `///`.
|
||||
should_suggest_empty_doc = doc.ends_with('.') || doc.ends_with('!') || doc.ends_with('?');
|
||||
}
|
||||
let len = doc.chars().count();
|
||||
|
|
@ -68,7 +73,7 @@ pub(super) fn check(
|
|||
|diag| {
|
||||
diag.span_suggestion(
|
||||
new_span,
|
||||
"add",
|
||||
"add an empty line",
|
||||
format!("{snippet}///\n"),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue