1 use clippy_utils
::diagnostics
::span_lint
;
2 use itertools
::Itertools
;
3 use rustc_ast
::{AttrKind, Attribute}
;
4 use rustc_lint
::{EarlyContext, EarlyLintPass}
;
5 use rustc_session
::{declare_lint_pass, declare_tool_lint}
;
9 /// Detects the syntax `['foo']` in documentation comments (notice quotes instead of backticks)
10 /// outside of code blocks
11 /// ### Why is this bad?
12 /// It is likely a typo when defining an intra-doc link
16 /// /// See also: ['foo']
21 /// /// See also: [`foo`]
24 #[clippy::version = "1.60.0"]
25 pub DOC_LINK_WITH_QUOTES
,
27 "possible typo for an intra-doc link"
29 declare_lint_pass
!(DocLinkWithQuotes
=> [DOC_LINK_WITH_QUOTES
]);
31 impl EarlyLintPass
for DocLinkWithQuotes
{
32 fn check_attribute(&mut self, ctx
: &EarlyContext
<'_
>, attr
: &Attribute
) {
33 if let AttrKind
::DocComment(_
, symbol
) = attr
.kind
{
34 if contains_quote_link(symbol
.as_str()) {
39 "possible intra-doc link using quotes instead of backticks",
46 fn contains_quote_link(s
: &str) -> bool
{
47 let mut in_backticks
= false;
48 let mut found_opening
= false;
50 for c
in s
.chars().tuple_windows
::<(char, char)>() {
52 ('`'
, _
) => in_backticks
= !in_backticks
,
53 ('
['
, '
\''
) if !in_backticks
=> found_opening
= true,
54 ('
\''
, '
]'
) if !in_backticks
&& found_opening
=> return true,