1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Runs several rustdoc lints, consolidating them into a single pass for
//! efficiency and simplicity.

mod bare_urls;
mod check_code_block_syntax;
mod html_tags;
mod redundant_explicit_links;
mod unescaped_backticks;
mod unportable_markdown;

use super::Pass;
use crate::clean::*;
use crate::core::DocContext;
use crate::visit::DocVisitor;

pub(crate) const RUN_LINTS: Pass =
    Pass { name: "run-lints", run: run_lints, description: "runs some of rustdoc's lints" };

struct Linter<'a, 'tcx> {
    cx: &'a mut DocContext<'tcx>,
}

pub(crate) fn run_lints(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
    Linter { cx }.visit_crate(&krate);
    krate
}

impl<'a, 'tcx> DocVisitor for Linter<'a, 'tcx> {
    fn visit_item(&mut self, item: &Item) {
        bare_urls::visit_item(self.cx, item);
        check_code_block_syntax::visit_item(self.cx, item);
        html_tags::visit_item(self.cx, item);
        unescaped_backticks::visit_item(self.cx, item);
        redundant_explicit_links::visit_item(self.cx, item);
        unportable_markdown::visit_item(self.cx, item);

        self.visit_item_recur(item)
    }
}