Auto merge of #13988 - dsprenkels:tidy-fncalls, r=Wafflespeanut

test-tidy: Check for space between function name and `(`

<!-- Please describe your changes on the following line: -->

Disallow an extraneous space in a function call between
the function name and the opening parenthesis in Rust
code, while ignoring macro declarations.

---

<!-- 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 --all` does not report any errors
- [x] `./mach test-tidy --self` does not report any errors
- [x] These changes fix #13980

<!-- Either: -->
- [x] There are tests for these changes, these are written in
 - `python/tidy/servo_tidy_tests/rust_tidy.rs`
 - `python/tidy/servo_tidy_tests/test_tidy.py`
- [ ] These changes do not require tests

<!-- 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/13988)

<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-10-31 13:03:32 -05:00 committed by GitHub
commit ccefef5be4
10 changed files with 25 additions and 15 deletions

View file

@ -416,8 +416,8 @@ pub fn Navigate(iframe: &HTMLIFrameElement, direction: TraversalDirection) -> Er
Ok(()) Ok(())
} else { } else {
debug!("this frame is not mozbrowser: mozbrowser attribute missing, or not a top debug!(concat!("this frame is not mozbrowser: mozbrowser attribute missing, or not a top",
level window, or mozbrowser preference not set (use --pref dom.mozbrowser.enabled)"); "level window, or mozbrowser preference not set (use --pref dom.mozbrowser.enabled)"));
Err(Error::NotSupported) Err(Error::NotSupported)
} }
} }
@ -499,8 +499,8 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
} }
Ok(()) Ok(())
} else { } else {
debug!("this frame is not mozbrowser: mozbrowser attribute missing, or not a top debug!(concat!("this frame is not mozbrowser: mozbrowser attribute missing, or not a top",
level window, or mozbrowser preference not set (use --pref dom.mozbrowser.enabled)"); "level window, or mozbrowser preference not set (use --pref dom.mozbrowser.enabled)"));
Err(Error::NotSupported) Err(Error::NotSupported)
} }
} }
@ -511,8 +511,8 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
self.set_visible(visible); self.set_visible(visible);
Ok(()) Ok(())
} else { } else {
debug!("this frame is not mozbrowser: mozbrowser attribute missing, or not a top debug!(concat!("this frame is not mozbrowser: mozbrowser attribute missing, or not a top",
level window, or mozbrowser preference not set (use --pref dom.mozbrowser.enabled)"); "level window, or mozbrowser preference not set (use --pref dom.mozbrowser.enabled)"));
Err(Error::NotSupported) Err(Error::NotSupported)
} }
} }
@ -522,8 +522,8 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
if self.Mozbrowser() { if self.Mozbrowser() {
Ok(self.visibility.get()) Ok(self.visibility.get())
} else { } else {
debug!("this frame is not mozbrowser: mozbrowser attribute missing, or not a top debug!(concat!("this frame is not mozbrowser: mozbrowser attribute missing, or not a top",
level window, or mozbrowser preference not set (use --pref dom.mozbrowser.enabled)"); "level window, or mozbrowser preference not set (use --pref dom.mozbrowser.enabled)"));
Err(Error::NotSupported) Err(Error::NotSupported)
} }
} }

View file

@ -442,6 +442,13 @@ def check_rust(file_name, lines):
regex_rules = [ regex_rules = [
(r",[^\s]", "missing space after ,", (r",[^\s]", "missing space after ,",
lambda match, line: '$' not in line and not is_attribute), 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 =", (r"[A-Za-z0-9\"]=", "missing space before =",
lambda match, line: is_attribute), lambda match, line: is_attribute),
(r"=[A-Za-z0-9\"]", "missing space after =", (r"=[A-Za-z0-9\"]", "missing space after =",

View file

@ -52,7 +52,9 @@ impl test {
type Text_Fun3 = fn( i32) -> i32; type Text_Fun3 = fn( i32) -> i32;
fn test_fun3<Text_Fun3>( y: Text_Fun3) { fn test_fun3<Text_Fun3>( y: Text_Fun3) {
test_fun( 1); let (x, y) = (1, 2) // Should not trigger
test_fun( x);
test_fun (y);
} }
// Should not be triggered // Should not be triggered

View file

@ -124,6 +124,7 @@ class CheckTidiness(unittest.TestCase):
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 (', 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.assertNoMoreErrors(errors) self.assertNoMoreErrors(errors)
def test_spec_link(self): def test_spec_link(self):