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