From 8584d269262e73aa7c3ebe25b1d61483375de267 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 28 Dec 2020 11:27:54 +0800 Subject: Add check for dbg! macro --- xtask/tests/tidy.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs index e3572424b..a957e36af 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/tests/tidy.rs @@ -85,6 +85,7 @@ fn rust_files_are_tidy() { for path in rust_files(&project_root().join("crates")) { let text = read_file(&path).unwrap(); check_todo(&path, &text); + check_dbg(&path, &text); check_trailing_ws(&path, &text); deny_clippy(&path, &text); tidy_docs.visit(&path, &text); @@ -223,7 +224,7 @@ Zlib OR Apache-2.0 OR MIT fn check_todo(path: &Path, text: &str) { let need_todo = &[ // This file itself obviously needs to use todo (<- like this!). - "tests/cli.rs", + "tests/tidy.rs", // Some of our assists generate `todo!()`. "handlers/add_turbo_fish.rs", "handlers/generate_function.rs", @@ -251,6 +252,32 @@ fn check_todo(path: &Path, text: &str) { } } +fn check_dbg(path: &Path, text: &str) { + let need_dbg = &[ + // This file itself obviously needs to use dbg. + "tests/tidy.rs", + // Assists to remove `dbg!()` + "handlers/remove_dbg.rs", + // We have .dbg postfix + "completion/src/completions/postfix.rs", + // The documentation in string literals may contain anything for its own purposes + "completion/src/lib.rs", + "completion/src/generated_lint_completions.rs", + // test for doc test for remove_dbg + "src/tests/generated.rs", + ]; + if need_dbg.iter().any(|p| path.ends_with(p)) { + return; + } + if text.contains("dbg!") { + panic!( + "\ndbg! macros should not be committed to the master branch,\n\ + {}\n", + path.display(), + ) + } +} + fn check_trailing_ws(path: &Path, text: &str) { if is_exclude_dir(path, &["test_data"]) { return; -- cgit v1.2.3