From 33f0a3765d6ac523afefa3922d56bcb519edf3c3 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 22 Apr 2019 16:15:18 +0100 Subject: [PATCH] Look specifically for comments containing tidy ignore directives --- src/tools/tidy/src/style.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index fb2bfb13a74..ae4ddd825dc 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -90,6 +90,11 @@ fn long_line_is_ok(line: &str) -> bool { false } +fn contains_ignore_directive(contents: &String, check: &str) -> bool { + contents.contains(&format!("// ignore-tidy-{}", check)) || + contents.contains(&format!("# ignore-tidy-{}", check)) +} + pub fn check(path: &Path, bad: &mut bool) { let mut contents = String::new(); super::walk(path, &mut super::filter_dirs, &mut |file| { @@ -107,11 +112,11 @@ pub fn check(path: &Path, bad: &mut bool) { tidy_error!(bad, "{}: empty file", file.display()); } - let skip_cr = contents.contains("ignore-tidy-cr"); - let skip_tab = contents.contains("ignore-tidy-tab"); - let skip_length = contents.contains("ignore-tidy-linelength"); - let skip_end_whitespace = contents.contains("ignore-tidy-end-whitespace"); - let skip_copyright = contents.contains("ignore-tidy-copyright"); + let skip_cr = contains_ignore_directive(&contents, "cr"); + let skip_tab = contains_ignore_directive(&contents, "tab"); + let skip_length = contains_ignore_directive(&contents, "linelength"); + let skip_end_whitespace = contains_ignore_directive(&contents, "end-whitespace"); + let skip_copyright = contains_ignore_directive(&contents, "copyright"); let mut leading_new_lines = false; let mut trailing_new_lines = 0; for (i, line) in contents.split('\n').enumerate() {