mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Auto merge of #17749 - SergeevPavel:extra-space-check, r=jdm
Extra space check <!-- Please describe your changes on the following line: --> Add tidy check for keywords with more than one space afterwards. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #17700 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17749) <!-- Reviewable:end -->
This commit is contained in:
commit
7d95fb8e49
7 changed files with 18 additions and 4 deletions
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue