Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tidy check for dbg #106327

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions library/std/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! This module contains a set of macros which are exported from the standard
//! library. Each macro is available for use when linking against the standard
//! library.
// ignore-tidy-dbg

#[doc = include_str!("../../core/src/macros/panic.md")]
#[macro_export]
Expand Down
17 changes: 17 additions & 0 deletions src/tools/tidy/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//!
//! A number of these checks can be opted-out of with various directives of the form:
//! `// ignore-tidy-CHECK-NAME`.
// ignore-tidy-dbg

use crate::walk::{filter_dirs, walk};
use regex::{Regex, RegexSet};
Expand Down Expand Up @@ -278,6 +279,7 @@ pub fn check(path: &Path, bad: &mut bool) {
let mut skip_leading_newlines =
contains_ignore_directive(can_contain, &contents, "leading-newlines");
let mut skip_copyright = contains_ignore_directive(can_contain, &contents, "copyright");
let mut skip_dbg = contains_ignore_directive(can_contain, &contents, "dbg");
let mut leading_new_lines = false;
let mut trailing_new_lines = 0;
let mut lines = 0;
Expand Down Expand Up @@ -306,6 +308,21 @@ pub fn check(path: &Path, bad: &mut bool) {
let mut err = |msg: &str| {
tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
};

if trimmed.contains("dbg!")
&& !trimmed.starts_with("//")
gimbling-away marked this conversation as resolved.
Show resolved Hide resolved
&& !file
.ancestors()
.any(|a| a.ends_with("src/test") || a.ends_with("library/alloc/tests"))
&& filename != "tests.rs"
{
suppressible_tidy_err!(
err,
skip_dbg,
"`dbg!` macro is intended as a debugging tool. It should not be in version control."
)
}

if !under_rustfmt
&& line.chars().count() > max_columns
&& !long_line_is_ok(&extension, is_error_code, max_columns, line)
Expand Down