diff options
author | Pavel Sergeev <sergeev.pavel.al@gmail.com> | 2017-07-16 13:26:08 +0300 |
---|---|---|
committer | Pavel Sergeev <sergeev.pavel.al@gmail.com> | 2017-07-20 00:44:59 +0300 |
commit | c225847a81588f7d709f5028cb24944077b4b548 (patch) | |
tree | 49c9a369f90cb8a7660fd25c4ba47a7494b14ad3 /python/tidy | |
parent | 17f99e2a7bb0d7eec167eac952f12a7feafd647d (diff) | |
download | servo-c225847a81588f7d709f5028cb24944077b4b548.tar.gz servo-c225847a81588f7d709f5028cb24944077b4b548.zip |
tidy: add extra space after keyword check
Diffstat (limited to 'python/tidy')
-rw-r--r-- | python/tidy/servo_tidy/tidy.py | 6 | ||||
-rw-r--r-- | python/tidy/servo_tidy_tests/rust_tidy.rs | 6 | ||||
-rw-r--r-- | python/tidy/servo_tidy_tests/test_tidy.py | 2 |
3 files changed, 14 insertions, 0 deletions
diff --git a/python/tidy/servo_tidy/tidy.py b/python/tidy/servo_tidy/tidy.py index 989b83aa505..3bf6176de44 100644 --- a/python/tidy/servo_tidy/tidy.py +++ b/python/tidy/servo_tidy/tidy.py @@ -584,6 +584,12 @@ def check_rust(file_name, lines): # -> () 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"(?<![A-Za-z0-9\-_]){key} ".format(key=key), + "extra space after {key}".format(key=key), + lambda match, line: not is_attribute) + regex_rules.extend(map(extra_space_after, keywords)) for pattern, message, filter_func in regex_rules: for match in re.finditer(pattern, line): diff --git a/python/tidy/servo_tidy_tests/rust_tidy.rs b/python/tidy/servo_tidy_tests/rust_tidy.rs index f50cbaa5ef7..bed4664a279 100644 --- a/python/tidy/servo_tidy_tests/rust_tidy.rs +++ b/python/tidy/servo_tidy_tests/rust_tidy.rs @@ -72,4 +72,10 @@ impl test { } else { // Should not trigger "false" } // Should not trigger + + if true { // Double space after keyword + 42 + } else { + let xif = 42 in { xif } // Should not trigger + } } diff --git a/python/tidy/servo_tidy_tests/test_tidy.py b/python/tidy/servo_tidy_tests/test_tidy.py index e02e065bd10..df8bf316cd0 100644 --- a/python/tidy/servo_tidy_tests/test_tidy.py +++ b/python/tidy/servo_tidy_tests/test_tidy.py @@ -95,6 +95,7 @@ class CheckTidiness(unittest.TestCase): def test_rust(self): errors = tidy.collect_errors_for_files(iterFile('rust_tidy.rs'), [], [tidy.check_rust], print_text=False) + self.assertEqual('extra space after use', errors.next()[2]) self.assertEqual('extra space after {', errors.next()[2]) self.assertEqual('extra space before }', errors.next()[2]) self.assertEqual('use statement spans multiple lines', errors.next()[2]) @@ -133,6 +134,7 @@ class CheckTidiness(unittest.TestCase): 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) |