Skip to content

Commit

Permalink
work in progress: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Feb 1, 2019
1 parent f894adc commit f4500bb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
19 changes: 12 additions & 7 deletions clippy_lints/src/dbg_macro.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use crate::utils::span_lint;
use crate::utils::span_lint_and_sugg;
use syntax::ast;
use rustc_errors::Applicability;

/// **What it does:** Checks for usage of dbg!() macro not to have it in
/// version control.
/// **What it does:** Checks for usage of dbg!() macro.
///
/// **Why is this bad?** `dbg!` macro is intended as a debugging tool.
/// **Why is this bad?** `dbg!` macro is intended as a debugging tool. It
/// should not be in version control.
///
/// **Known problems:** None.
///
Expand All @@ -20,7 +21,7 @@ use syntax::ast;
/// ```
declare_clippy_lint! {
pub DBG_MACRO,
style,
restriction,
"`dbg!` macro is intended as a debugging tool"
}

Expand All @@ -39,12 +40,16 @@ impl LintPass for Pass {

impl EarlyLintPass for Pass {
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
println!("{:?}", mac);
if mac.node.path == "dbg" {
span_lint(
span_lint_and_sugg(
cx,
DBG_MACRO,
mac.span,
"`dbg!` macro is intended as a debugging tool. ensure to avoid having uses of it in version control",
"`dbg!` macro is intended as a debugging tool",
"ensure to avoid having uses of it in version control",
mac.node.tts.to_string(), // TODO: to string
Applicability::MaybeIncorrect,
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/dbg_macro.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![warn(clippy::dbg_macro)]

fn main() {
dbg!(42);
}
8 changes: 3 additions & 5 deletions tests/ui/dbg_macro.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
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
error: `dbg!` macro is used
--> $DIR/dbg_macro.rs:4:5
|
LL | dbg!(42);
| ^^^^^^^^
| ^^^^^^^^ help: `dbg!` macro is intended as a debugging tool: `ensure to avoid having uses of it in version control`
|
= note: `-D clippy::dbg-macro` implied by `-D warnings`

error: aborting due to previous error

0 comments on commit f4500bb

Please sign in to comment.