mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Auto merge of #12472 - GuillaumeGomez:fix-10262, r=blyxyas
Don't emit `doc_markdown` lint for missing backticks if it's inside a quote Fixes #10262. changelog: Don't emit `doc_markdown` lint for missing backticks if it's inside a quote
This commit is contained in:
commit
b667d02340
5 changed files with 61 additions and 6 deletions
|
@ -8,7 +8,14 @@ use url::Url;
|
|||
|
||||
use crate::doc::DOC_MARKDOWN;
|
||||
|
||||
pub fn check(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, text: &str, span: Span, code_level: isize) {
|
||||
pub fn check(
|
||||
cx: &LateContext<'_>,
|
||||
valid_idents: &FxHashSet<String>,
|
||||
text: &str,
|
||||
span: Span,
|
||||
code_level: isize,
|
||||
blockquote_level: isize,
|
||||
) {
|
||||
for orig_word in text.split(|c: char| c.is_whitespace() || c == '\'') {
|
||||
// Trim punctuation as in `some comment (see foo::bar).`
|
||||
// ^^
|
||||
|
@ -46,11 +53,11 @@ pub fn check(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, text: &str,
|
|||
span.parent(),
|
||||
);
|
||||
|
||||
check_word(cx, word, span, code_level);
|
||||
check_word(cx, word, span, code_level, blockquote_level);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_word(cx: &LateContext<'_>, word: &str, span: Span, code_level: isize) {
|
||||
fn check_word(cx: &LateContext<'_>, word: &str, span: Span, code_level: isize, blockquote_level: isize) {
|
||||
/// Checks if a string is upper-camel-case, i.e., starts with an uppercase and
|
||||
/// contains at least two uppercase letters (`Clippy` is ok) and one lower-case
|
||||
/// letter (`NASA` is ok).
|
||||
|
@ -97,7 +104,9 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span, code_level: isize) {
|
|||
}
|
||||
|
||||
// We assume that mixed-case words are not meant to be put inside backticks. (Issue #2343)
|
||||
if code_level > 0 || (has_underscore(word) && has_hyphen(word)) {
|
||||
//
|
||||
// We also assume that backticks are not necessary if inside a quote. (Issue #10262)
|
||||
if code_level > 0 || blockquote_level > 0 || (has_underscore(word) && has_hyphen(word)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use clippy_utils::{is_entrypoint_fn, method_chain_args};
|
|||
use pulldown_cmark::Event::{
|
||||
Code, End, FootnoteReference, HardBreak, Html, Rule, SoftBreak, Start, TaskListMarker, Text,
|
||||
};
|
||||
use pulldown_cmark::Tag::{CodeBlock, Heading, Item, Link, Paragraph};
|
||||
use pulldown_cmark::Tag::{BlockQuote, CodeBlock, Heading, Item, Link, Paragraph};
|
||||
use pulldown_cmark::{BrokenLink, CodeBlockKind, CowStr, Options};
|
||||
use rustc_ast::ast::Attribute;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
|
@ -611,6 +611,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
|
|||
let mut text_to_check: Vec<(CowStr<'_>, Range<usize>, isize)> = Vec::new();
|
||||
let mut paragraph_range = 0..0;
|
||||
let mut code_level = 0;
|
||||
let mut blockquote_level = 0;
|
||||
|
||||
for (event, range) in events {
|
||||
match event {
|
||||
|
@ -619,8 +620,14 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
|
|||
code_level += 1;
|
||||
} else if tag.starts_with("</code") {
|
||||
code_level -= 1;
|
||||
} else if tag.starts_with("<blockquote") || tag.starts_with("<q") {
|
||||
blockquote_level += 1;
|
||||
} else if tag.starts_with("</blockquote") || tag.starts_with("</q") {
|
||||
blockquote_level -= 1;
|
||||
}
|
||||
},
|
||||
Start(BlockQuote) => blockquote_level += 1,
|
||||
End(BlockQuote) => blockquote_level -= 1,
|
||||
Start(CodeBlock(ref kind)) => {
|
||||
in_code = true;
|
||||
if let CodeBlockKind::Fenced(lang) = kind {
|
||||
|
@ -672,7 +679,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
|
|||
} else {
|
||||
for (text, range, assoc_code_level) in text_to_check {
|
||||
if let Some(span) = fragments.span(cx, range) {
|
||||
markdown::check(cx, valid_idents, &text, span, assoc_code_level);
|
||||
markdown::check(cx, valid_idents, &text, span, assoc_code_level, blockquote_level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
tests/ui/doc/issue_10262.fixed
Normal file
12
tests/ui/doc/issue_10262.fixed
Normal file
|
@ -0,0 +1,12 @@
|
|||
#![warn(clippy::doc_markdown)]
|
||||
|
||||
// Should only warn for the first line!
|
||||
/// `AviSynth` documentation:
|
||||
//~^ ERROR: item in documentation is missing backticks
|
||||
///
|
||||
/// > AvisynthPluginInit3 may be called more than once with different IScriptEnvironments.
|
||||
///
|
||||
/// <blockquote>bla AvisynthPluginInit3 bla</blockquote>
|
||||
///
|
||||
/// <q>bla AvisynthPluginInit3 bla</q>
|
||||
pub struct Foo;
|
12
tests/ui/doc/issue_10262.rs
Normal file
12
tests/ui/doc/issue_10262.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
#![warn(clippy::doc_markdown)]
|
||||
|
||||
// Should only warn for the first line!
|
||||
/// AviSynth documentation:
|
||||
//~^ ERROR: item in documentation is missing backticks
|
||||
///
|
||||
/// > AvisynthPluginInit3 may be called more than once with different IScriptEnvironments.
|
||||
///
|
||||
/// <blockquote>bla AvisynthPluginInit3 bla</blockquote>
|
||||
///
|
||||
/// <q>bla AvisynthPluginInit3 bla</q>
|
||||
pub struct Foo;
|
15
tests/ui/doc/issue_10262.stderr
Normal file
15
tests/ui/doc/issue_10262.stderr
Normal file
|
@ -0,0 +1,15 @@
|
|||
error: item in documentation is missing backticks
|
||||
--> tests/ui/doc/issue_10262.rs:4:5
|
||||
|
|
||||
LL | /// AviSynth documentation:
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::doc-markdown` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]`
|
||||
help: try
|
||||
|
|
||||
LL | /// `AviSynth` documentation:
|
||||
| ~~~~~~~~~~
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
Loading…
Reference in a new issue