-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement dbg_macro rule (fixes #3721)
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; | ||
use rustc::{declare_tool_lint, lint_array}; | ||
use crate::utils::span_lint; | ||
use syntax::ast; | ||
|
||
/// **What it does:** Checks for usage of dbg!() macro not to have it in | ||
/// version control. | ||
/// | ||
/// **Why is this bad?** `dbg!` macro is intended as a debugging tool. | ||
/// | ||
/// **Known problems:** None. | ||
/// | ||
/// **Example:** | ||
/// ```rust,ignore | ||
/// // Bad | ||
/// dbg!(true) | ||
/// | ||
/// // Good | ||
/// true | ||
/// ``` | ||
declare_clippy_lint! { | ||
pub DBG_MACRO, | ||
style, | ||
"`dbg!` macro is intended as a debugging tool" | ||
} | ||
|
||
#[derive(Copy, Clone, Debug)] | ||
pub struct Pass; | ||
|
||
impl LintPass for Pass { | ||
fn get_lints(&self) -> LintArray { | ||
lint_array!(DBG_MACRO) | ||
} | ||
|
||
fn name(&self) -> &'static str { | ||
"DbgMacro" | ||
} | ||
} | ||
|
||
impl EarlyLintPass for Pass { | ||
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) { | ||
if mac.node.path == "dbg" { | ||
span_lint( | ||
cx, | ||
DBG_MACRO, | ||
mac.span, | ||
"`dbg!` macro is intended as a debugging tool. ensure to avoid having uses of it in version control", | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
dbg!(42); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: `dbg!` macro is intended as a debugging tool. ensure to avoid having uses of it in version control | ||
--> $DIR/dbg_macro.rs:2:5 | ||
| | ||
LL | dbg!(42); | ||
| ^^^^^^^^ | ||
| | ||
= note: `-D clippy::dbg-macro` implied by `-D warnings` | ||
|
||
error: aborting due to previous error | ||
|