]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/dbg_macro.rs
add more test cases for dbg_macro rule
[rust.git] / clippy_lints / src / dbg_macro.rs
1 use crate::utils::span_help_and_lint;
2 use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
3 use rustc::{declare_tool_lint, lint_array};
4 use syntax::ast;
5
6 /// **What it does:** Checks for usage of dbg!() macro.
7 ///
8 /// **Why is this bad?** `dbg!` macro is intended as a debugging tool. It
9 /// should not be in version control.
10 ///
11 /// **Known problems:** None.
12 ///
13 /// **Example:**
14 /// ```rust,ignore
15 /// // Bad
16 /// dbg!(true)
17 ///
18 /// // Good
19 /// true
20 /// ```
21 declare_clippy_lint! {
22     pub DBG_MACRO,
23     restriction,
24     "`dbg!` macro is intended as a debugging tool"
25 }
26
27 #[derive(Copy, Clone, Debug)]
28 pub struct Pass;
29
30 impl LintPass for Pass {
31     fn get_lints(&self) -> LintArray {
32         lint_array!(DBG_MACRO)
33     }
34
35     fn name(&self) -> &'static str {
36         "DbgMacro"
37     }
38 }
39
40 impl EarlyLintPass for Pass {
41     fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
42         if mac.node.path == "dbg" {
43             span_help_and_lint(
44                 cx,
45                 DBG_MACRO,
46                 mac.span,
47                 "`dbg!` macro is intended as a debugging tool",
48                 "ensure to avoid having uses of it in version control",
49             );
50         }
51     }
52 }