Add check for dbg! macro

This commit is contained in:
Edwin Cheng 2020-12-28 11:27:54 +08:00
parent 66b132b4b2
commit 8584d26926

View file

@ -85,6 +85,7 @@ fn rust_files_are_tidy() {
for path in rust_files(&project_root().join("crates")) { for path in rust_files(&project_root().join("crates")) {
let text = read_file(&path).unwrap(); let text = read_file(&path).unwrap();
check_todo(&path, &text); check_todo(&path, &text);
check_dbg(&path, &text);
check_trailing_ws(&path, &text); check_trailing_ws(&path, &text);
deny_clippy(&path, &text); deny_clippy(&path, &text);
tidy_docs.visit(&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) { fn check_todo(path: &Path, text: &str) {
let need_todo = &[ let need_todo = &[
// This file itself obviously needs to use todo (<- like this!). // This file itself obviously needs to use todo (<- like this!).
"tests/cli.rs", "tests/tidy.rs",
// Some of our assists generate `todo!()`. // Some of our assists generate `todo!()`.
"handlers/add_turbo_fish.rs", "handlers/add_turbo_fish.rs",
"handlers/generate_function.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) { fn check_trailing_ws(path: &Path, text: &str) {
if is_exclude_dir(path, &["test_data"]) { if is_exclude_dir(path, &["test_data"]) {
return; return;