|
15 | 15 | //!
|
16 | 16 | //! A number of these checks can be opted-out of with various directives of the form:
|
17 | 17 | //! `// ignore-tidy-CHECK-NAME`.
|
| 18 | +// ignore-tidy-dbg |
18 | 19 |
|
19 | 20 | use crate::walk::{filter_dirs, walk};
|
20 | 21 | use regex::{Regex, RegexSet};
|
@@ -278,6 +279,7 @@ pub fn check(path: &Path, bad: &mut bool) {
|
278 | 279 | let mut skip_leading_newlines =
|
279 | 280 | contains_ignore_directive(can_contain, &contents, "leading-newlines");
|
280 | 281 | let mut skip_copyright = contains_ignore_directive(can_contain, &contents, "copyright");
|
| 282 | + let mut skip_dbg = contains_ignore_directive(can_contain, &contents, "dbg"); |
281 | 283 | let mut leading_new_lines = false;
|
282 | 284 | let mut trailing_new_lines = 0;
|
283 | 285 | let mut lines = 0;
|
@@ -306,6 +308,21 @@ pub fn check(path: &Path, bad: &mut bool) {
|
306 | 308 | let mut err = |msg: &str| {
|
307 | 309 | tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
|
308 | 310 | };
|
| 311 | + |
| 312 | + if trimmed.contains("dbg!") |
| 313 | + && !trimmed.starts_with("//") |
| 314 | + && !file |
| 315 | + .ancestors() |
| 316 | + .any(|a| a.ends_with("src/test") || a.ends_with("library/alloc/tests")) |
| 317 | + && filename != "tests.rs" |
| 318 | + { |
| 319 | + suppressible_tidy_err!( |
| 320 | + err, |
| 321 | + skip_dbg, |
| 322 | + "`dbg!` macro is intended as a debugging tool. It should not be in version control." |
| 323 | + ) |
| 324 | + } |
| 325 | + |
309 | 326 | if !under_rustfmt
|
310 | 327 | && line.chars().count() > max_columns
|
311 | 328 | && !long_line_is_ok(&extension, is_error_code, max_columns, line)
|
|
0 commit comments