Auto merge of #12243 - TravisDean:else-brace-check, r=ConnorGBrewster

Add style check and test for else braces

<!-- Please describe your changes on the following line: -->
Added a regex check to enforce project style guidelines. Added unit check. Catches:
```
}
else {
```
when it should be
`} else {`

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors (no core files changed)
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #12234 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12243)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-07-04 16:52:19 -07:00 committed by GitHub
commit e21b47c2cc
9 changed files with 26 additions and 20 deletions

View file

@ -2261,8 +2261,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
rendergl::render_scene(layer.clone(), context, &self.scene); rendergl::render_scene(layer.clone(), context, &self.scene);
gl::disable(gl::SCISSOR_TEST); gl::disable(gl::SCISSOR_TEST);
} } else {
else {
rendergl::render_scene(layer.clone(), context, &self.scene); rendergl::render_scene(layer.clone(), context, &self.scene);
} }
} }

View file

@ -1788,8 +1788,11 @@ impl ScaledFontExtensionMethods for ScaledFont {
let mut options = struct__AzDrawOptions { let mut options = struct__AzDrawOptions {
mAlpha: 1f64 as AzFloat, mAlpha: 1f64 as AzFloat,
mCompositionOp: CompositionOp::Over as u8, mCompositionOp: CompositionOp::Over as u8,
mAntialiasMode: if antialias { AntialiasMode::Subpixel as u8 } mAntialiasMode: if antialias {
else { AntialiasMode::None as u8 } AntialiasMode::Subpixel as u8
} else {
AntialiasMode::None as u8
}
}; };
let mut origin = baseline_origin.clone(); let mut origin = baseline_origin.clone();

View file

@ -81,12 +81,12 @@ pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img
pub fn detect_image_format(buffer: &[u8]) -> Result<ImageFormat, &str> { pub fn detect_image_format(buffer: &[u8]) -> Result<ImageFormat, &str> {
if is_gif(buffer) { Ok(ImageFormat::GIF) } if is_gif(buffer) { Ok(ImageFormat::GIF)
else if is_jpeg(buffer) { Ok(ImageFormat::JPEG) } } else if is_jpeg(buffer) { Ok(ImageFormat::JPEG)
else if is_png(buffer) { Ok(ImageFormat::PNG) } } else if is_png(buffer) { Ok(ImageFormat::PNG)
else if is_bmp(buffer) { Ok(ImageFormat::BMP) } } else if is_bmp(buffer) { Ok(ImageFormat::BMP)
else if is_ico(buffer) { Ok(ImageFormat::ICO) } } else if is_ico(buffer) { Ok(ImageFormat::ICO)
else { Err("Image Format Not Supported") } } else { Err("Image Format Not Supported") }
} }
fn is_gif(buffer: &[u8]) -> bool { fn is_gif(buffer: &[u8]) -> bool {

View file

@ -133,9 +133,8 @@ impl AsyncResponseListener for HTMLMediaElementContext {
// Step 5 // Step 5
elem.fire_simple_event("error"); elem.fire_simple_event("error");
} } else {
// => "If the media data cannot be fetched at all..." // => "If the media data cannot be fetched at all..."
else {
elem.queue_dedicated_media_source_failure_steps(); elem.queue_dedicated_media_source_failure_steps();
} }

View file

@ -1128,9 +1128,8 @@ impl XMLHttpRequest {
// Step 5 // Step 5
if self.response_type.get() == XMLHttpRequestResponseType::_empty { if self.response_type.get() == XMLHttpRequestResponseType::_empty {
return None; return None;
} } else {
// Step 6 // Step 6
else {
temp_doc = self.document_text_html(); temp_doc = self.document_text_html();
} }
}, },
@ -1143,8 +1142,7 @@ impl XMLHttpRequest {
Some(Mime(_, mime::SubLevel::Ext(sub), _)) => { Some(Mime(_, mime::SubLevel::Ext(sub), _)) => {
if sub.ends_with("+xml") { if sub.ends_with("+xml") {
temp_doc = self.handle_xml(); temp_doc = self.handle_xml();
} } else {
else {
return None; return None;
} }
}, },

View file

@ -374,8 +374,7 @@ pub fn handle_is_selected(context: &BrowsingContext,
} }
else if let Some(_) = node.downcast::<HTMLElement>() { else if let Some(_) = node.downcast::<HTMLElement>() {
Ok(false) // regular elements are not selectable Ok(false) // regular elements are not selectable
} } else {
else {
Err(()) Err(())
} }
}, },

View file

@ -415,6 +415,7 @@ def check_rust(file_name, lines):
(r"^&&", "operators should go at the end of the first line", 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", (r"\{[A-Za-z0-9_]+\};", "use statement contains braces for single import",
lambda match, line: line.startswith('use ')), lambda match, line: line.startswith('use ')),
(r"^\s*else {", "else braces should be on the same line", no_filter),
] ]
for pattern, message, filter_func in regex_rules: for pattern, message, filter_func in regex_rules:

View file

@ -41,6 +41,12 @@ impl test {
let x = true; let x = true;
x x
&& x; && x;
if x {
;
}
else {
;
}
} }
} }

View file

@ -76,6 +76,7 @@ class CheckTidiness(unittest.TestCase):
self.assertEqual('use &str instead of &String', errors.next()[2]) self.assertEqual('use &str instead of &String', errors.next()[2])
self.assertEqual('use &T instead of &Root<T>', errors.next()[2]) self.assertEqual('use &T instead of &Root<T>', errors.next()[2])
self.assertEqual('operators should go at the end of the first line', 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.assertNoMoreErrors(errors) self.assertNoMoreErrors(errors)
def test_spec_link(self): def test_spec_link(self):