Skip to content

Commit 11759d1

Browse files
Don't emit doc_markdown lint for missing backticks if it's inside a quote
1 parent 98ac5f1 commit 11759d1

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

clippy_lints/src/doc/markdown.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ use url::Url;
88

99
use crate::doc::DOC_MARKDOWN;
1010

11-
pub fn check(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, text: &str, span: Span, code_level: isize) {
11+
pub fn check(
12+
cx: &LateContext<'_>,
13+
valid_idents: &FxHashSet<String>,
14+
text: &str,
15+
span: Span,
16+
code_level: isize,
17+
blockquote_level: isize,
18+
) {
1219
for orig_word in text.split(|c: char| c.is_whitespace() || c == '\'') {
1320
// Trim punctuation as in `some comment (see foo::bar).`
1421
// ^^
@@ -46,11 +53,11 @@ pub fn check(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, text: &str,
4653
span.parent(),
4754
);
4855

49-
check_word(cx, word, span, code_level);
56+
check_word(cx, word, span, code_level, blockquote_level);
5057
}
5158
}
5259

53-
fn check_word(cx: &LateContext<'_>, word: &str, span: Span, code_level: isize) {
60+
fn check_word(cx: &LateContext<'_>, word: &str, span: Span, code_level: isize, blockquote_level: isize) {
5461
/// Checks if a string is upper-camel-case, i.e., starts with an uppercase and
5562
/// contains at least two uppercase letters (`Clippy` is ok) and one lower-case
5663
/// letter (`NASA` is ok).
@@ -97,7 +104,9 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span, code_level: isize) {
97104
}
98105

99106
// We assume that mixed-case words are not meant to be put inside backticks. (Issue #2343)
100-
if code_level > 0 || (has_underscore(word) && has_hyphen(word)) {
107+
//
108+
// We also assume that backticks are not necessary if inside a quote. (Issue #10262)
109+
if code_level > 0 || blockquote_level > 0 || (has_underscore(word) && has_hyphen(word)) {
101110
return;
102111
}
103112

clippy_lints/src/doc/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use clippy_utils::{is_entrypoint_fn, method_chain_args};
77
use pulldown_cmark::Event::{
88
Code, End, FootnoteReference, HardBreak, Html, Rule, SoftBreak, Start, TaskListMarker, Text,
99
};
10-
use pulldown_cmark::Tag::{CodeBlock, Heading, Item, Link, Paragraph};
10+
use pulldown_cmark::Tag::{BlockQuote, CodeBlock, Heading, Item, Link, Paragraph};
1111
use pulldown_cmark::{BrokenLink, CodeBlockKind, CowStr, Options};
1212
use rustc_ast::ast::Attribute;
1313
use rustc_data_structures::fx::FxHashSet;
@@ -602,6 +602,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
602602
let mut text_to_check: Vec<(CowStr<'_>, Range<usize>, isize)> = Vec::new();
603603
let mut paragraph_range = 0..0;
604604
let mut code_level = 0;
605+
let mut blockquote_level = 0;
605606

606607
for (event, range) in events {
607608
match event {
@@ -612,6 +613,8 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
612613
code_level -= 1;
613614
}
614615
},
616+
Start(BlockQuote) => blockquote_level += 1,
617+
End(BlockQuote) => blockquote_level -= 1,
615618
Start(CodeBlock(ref kind)) => {
616619
in_code = true;
617620
if let CodeBlockKind::Fenced(lang) = kind {
@@ -663,7 +666,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
663666
} else {
664667
for (text, range, assoc_code_level) in text_to_check {
665668
if let Some(span) = fragments.span(cx, range) {
666-
markdown::check(cx, valid_idents, &text, span, assoc_code_level);
669+
markdown::check(cx, valid_idents, &text, span, assoc_code_level, blockquote_level);
667670
}
668671
}
669672
}

0 commit comments

Comments
 (0)