From 753633d3beba6fbbe9122edeaf9402cd9e3c8be0 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 19 Jun 2019 23:21:13 +0200 Subject: [PATCH] Remove regex-based checks in servo-tidy that are covered by rustfmt --- python/tidy/servo_tidy/tidy.py | 63 ----------------------- python/tidy/servo_tidy_tests/test_tidy.py | 25 --------- 2 files changed, 88 deletions(-) diff --git a/python/tidy/servo_tidy/tidy.py b/python/tidy/servo_tidy/tidy.py index 0fdda070899..b54bc35bfbf 100644 --- a/python/tidy/servo_tidy/tidy.py +++ b/python/tidy/servo_tidy/tidy.py @@ -524,7 +524,6 @@ def check_rust(file_name, lines): prev_mod = {} prev_feature_name = "" indent = 0 - prev_indent = 0 check_alphabetical_order = config["check-alphabetical-order"] decl_message = "{} is not in alphabetical order" @@ -534,7 +533,6 @@ def check_rust(file_name, lines): for idx, original_line in enumerate(lines): # simplify the analysis line = original_line.strip() - prev_indent = indent indent = len(original_line) - len(line) is_attribute = re.search(r"#\[.*\]", line) @@ -595,50 +593,6 @@ def check_rust(file_name, lines): # tuple format: (pattern, format_message, filter_function(match, line)) no_filter = lambda match, line: True regex_rules = [ - (r",[^\s]", "missing space after ,", - lambda match, line: '$' not in line and not is_attribute), - (r"([A-Za-z0-9_]+) (\()", "extra space after {0}", - lambda match, line: not ( - is_attribute or - re.match(r"\bmacro_rules!\s+", line[:match.start()]) or - re.search(r"[^']'[A-Za-z0-9_]+ \($", line[:match.end()]) or - match.group(1) in ['const', 'fn', 'for', 'if', 'in', - 'let', 'match', 'mut', 'return'])), - (r"[A-Za-z0-9\"]=", "missing space before =", - lambda match, line: is_attribute), - (r"=[A-Za-z0-9\"]", "missing space after =", - lambda match, line: is_attribute), - (r"^=\s", "no = in the beginning of line", - lambda match, line: not is_comment), - # ignore scientific notation patterns like 1e-6 - (r"[A-DF-Za-df-z0-9]-", "missing space before -", - lambda match, line: not is_attribute), - (r"[A-Za-z0-9]([\+/\*%=])", "missing space before {0}", - lambda match, line: (not is_attribute and - not is_associated_type(match, line))), - # * not included because of dereferencing and casting - # - not included because of unary negation - (r'([\+/\%=])[A-Za-z0-9"]', "missing space after {0}", - lambda match, line: (not is_attribute and - not is_associated_type(match, line))), - (r"\)->", "missing space before ->", no_filter), - (r"->[A-Za-z]", "missing space after ->", no_filter), - (r"[^ ]=>", "missing space before =>", lambda match, line: match.start() != 0), - (r"=>[^ ]", "missing space after =>", lambda match, line: match.end() != len(line)), - (r"=> ", "extra space after =>", no_filter), - # ignore " ::crate::mod" and "trait Foo : Bar" - (r" :[^:]", "extra space before :", - lambda match, line: 'trait ' not in line[:match.start()]), - # ignore "crate::mod" and ignore flagging macros like "$t1:expr" - (r"[^:]:[A-Za-z0-9\"]", "missing space after :", - lambda match, line: '$' not in line[:match.end()]), - (r"[A-Za-z0-9\)]{", "missing space before {{", no_filter), - # ignore cases like "{}", "}`", "}}" and "use::std::{Foo, Bar}" - (r"[^\s{}]}[^`]", "missing space before }}", - lambda match, line: not re.match(r'^(pub )?use', line)), - # ignore cases like "{}", "`{", "{{" and "use::std::{Foo, Bar}" - (r"[^`]{[^\s{}]", "missing space after {{", - lambda match, line: not re.match(r'^(pub )?use', line)), # There should not be any extra pointer dereferencing (r": &Vec<", "use &[T] instead of &Vec", no_filter), # No benefit over using &str @@ -652,22 +606,12 @@ def check_rust(file_name, lines): # No benefit to using &Root (r": &Root<", "use &T instead of &Root", no_filter), (r"^&&", "operators should go at the end of the first line", no_filter), - (r"\{[A-Za-z0-9_]+\};", "use statement contains braces for single import", - lambda match, line: line.startswith('use ')), - (r"^\s*else {", "else braces should be on the same line", no_filter), - (r"[^$ ]\([ \t]", "extra space after (", no_filter), # This particular pattern is not reentrant-safe in script_thread.rs (r"match self.documents.borrow", "use a separate variable for the match expression", lambda match, line: file_name.endswith('script_thread.rs')), # -> () is unnecessary (r"-> \(\)", "encountered function signature with -> ()", no_filter), ] - keywords = ["if", "let", "mut", "extern", "as", "impl", "fn", "struct", "enum", "pub", "mod", - "use", "in", "ref", "type", "where", "trait"] - extra_space_after = lambda key: (r"(?', errors.next()[2]) - self.assertEqual('missing space after ->', errors.next()[2]) - self.assertEqual('missing space after :', errors.next()[2]) - self.assertEqual('missing space before {', errors.next()[2]) - self.assertEqual('missing space before =', errors.next()[2]) - self.assertEqual('missing space after =', errors.next()[2]) - self.assertEqual('missing space before -', errors.next()[2]) - self.assertEqual('missing space before *', errors.next()[2]) - self.assertEqual('missing space after =>', errors.next()[2]) - self.assertEqual('missing space after :', errors.next()[2]) - self.assertEqual('missing space after :', errors.next()[2]) - self.assertEqual('extra space before :', errors.next()[2]) - self.assertEqual('extra space before :', errors.next()[2]) self.assertEqual('use &[T] instead of &Vec', errors.next()[2]) self.assertEqual('use &str instead of &String', errors.next()[2]) self.assertEqual('use &T instead of &Root', errors.next()[2]) self.assertEqual('encountered function signature with -> ()', errors.next()[2]) self.assertEqual('operators should go at the end of the first line', errors.next()[2]) - self.assertEqual('else braces should be on the same line', errors.next()[2]) - self.assertEqual('extra space after (', errors.next()[2]) - self.assertEqual('extra space after (', errors.next()[2]) - self.assertEqual('extra space after (', errors.next()[2]) - self.assertEqual('extra space after test_fun', errors.next()[2]) - self.assertEqual('no = in the beginning of line', errors.next()[2]) - self.assertEqual('space before { is not a multiple of 4', errors.next()[2]) - self.assertEqual('space before } is not a multiple of 4', errors.next()[2]) - self.assertEqual('extra space after if', errors.next()[2]) self.assertNoMoreErrors(errors) feature_errors = tidy.collect_errors_for_files(iterFile('lib.rs'), [], [tidy.check_rust], print_text=False)