mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
tidy: add extra space after keyword check
This commit is contained in:
parent
17f99e2a7b
commit
c225847a81
3 changed files with 14 additions and 0 deletions
|
@ -584,6 +584,12 @@ def check_rust(file_name, lines):
|
||||||
# -> () is unnecessary
|
# -> () is unnecessary
|
||||||
(r"-> \(\)", "encountered function signature with -> ()", no_filter),
|
(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 pattern, message, filter_func in regex_rules:
|
||||||
for match in re.finditer(pattern, line):
|
for match in re.finditer(pattern, line):
|
||||||
|
|
|
@ -72,4 +72,10 @@ impl test {
|
||||||
} else { // Should not trigger
|
} else { // Should not trigger
|
||||||
"false"
|
"false"
|
||||||
} // Should not trigger
|
} // Should not trigger
|
||||||
|
|
||||||
|
if true { // Double space after keyword
|
||||||
|
42
|
||||||
|
} else {
|
||||||
|
let xif = 42 in { xif } // Should not trigger
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,7 @@ class CheckTidiness(unittest.TestCase):
|
||||||
|
|
||||||
def test_rust(self):
|
def test_rust(self):
|
||||||
errors = tidy.collect_errors_for_files(iterFile('rust_tidy.rs'), [], [tidy.check_rust], print_text=False)
|
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 after {', errors.next()[2])
|
||||||
self.assertEqual('extra space before }', errors.next()[2])
|
self.assertEqual('extra space before }', errors.next()[2])
|
||||||
self.assertEqual('use statement spans multiple lines', 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('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('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)
|
self.assertNoMoreErrors(errors)
|
||||||
|
|
||||||
feature_errors = tidy.collect_errors_for_files(iterFile('lib.rs'), [], [tidy.check_rust], print_text=False)
|
feature_errors = tidy.collect_errors_for_files(iterFile('lib.rs'), [], [tidy.check_rust], print_text=False)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue