Skip to content

Commit 33f0a37

Browse files
committed
Look specifically for comments containing tidy ignore directives
1 parent 0f11354 commit 33f0a37

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/tools/tidy/src/style.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ fn long_line_is_ok(line: &str) -> bool {
9090
false
9191
}
9292

93+
fn contains_ignore_directive(contents: &String, check: &str) -> bool {
94+
contents.contains(&format!("// ignore-tidy-{}", check)) ||
95+
contents.contains(&format!("# ignore-tidy-{}", check))
96+
}
97+
9398
pub fn check(path: &Path, bad: &mut bool) {
9499
let mut contents = String::new();
95100
super::walk(path, &mut super::filter_dirs, &mut |file| {
@@ -107,11 +112,11 @@ pub fn check(path: &Path, bad: &mut bool) {
107112
tidy_error!(bad, "{}: empty file", file.display());
108113
}
109114

110-
let skip_cr = contents.contains("ignore-tidy-cr");
111-
let skip_tab = contents.contains("ignore-tidy-tab");
112-
let skip_length = contents.contains("ignore-tidy-linelength");
113-
let skip_end_whitespace = contents.contains("ignore-tidy-end-whitespace");
114-
let skip_copyright = contents.contains("ignore-tidy-copyright");
115+
let skip_cr = contains_ignore_directive(&contents, "cr");
116+
let skip_tab = contains_ignore_directive(&contents, "tab");
117+
let skip_length = contains_ignore_directive(&contents, "linelength");
118+
let skip_end_whitespace = contains_ignore_directive(&contents, "end-whitespace");
119+
let skip_copyright = contains_ignore_directive(&contents, "copyright");
115120
let mut leading_new_lines = false;
116121
let mut trailing_new_lines = 0;
117122
for (i, line) in contents.split('\n').enumerate() {

0 commit comments

Comments
 (0)