servo: Merge #17749 - Extra space check (from SergeevPavel:extra-space-check); r=jdm
authorPavel Sergeev <sergeev.pavel.al@gmail.com>
Wed, 19 Jul 2017 16:03:51 -0700
changeset 418469 7eb11c4b0159a321d2f4b06b57336c507daea216
parent 418468 986de13adb0a2b7ba6369deaccdd583915857d91
child 418470 edca2b43880708121a7a4a5930ed4feee77de5a2
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs17749, 17700
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #17749 - Extra space check (from SergeevPavel:extra-space-check); r=jdm <!-- 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. --> Source-Repo: https://github.com/servo/servo Source-Revision: 7d95fb8e49dd0eb9fa9efb9d70008f5f9bf20a83
servo/components/constellation/constellation.rs
servo/components/script/dom/document.rs
servo/components/script/serviceworker_manager.rs
servo/python/tidy/servo_tidy/tidy.py
servo/python/tidy/servo_tidy_tests/rust_tidy.rs
servo/python/tidy/servo_tidy_tests/test_tidy.py
servo/tests/unit/net/http_loader.rs
--- a/servo/components/constellation/constellation.rs
+++ b/servo/components/constellation/constellation.rs
@@ -2032,17 +2032,17 @@ impl<Message, LTF, STF> Constellation<Me
         let (browsing_context_id, parent_pipeline_info) = match self.pipelines.get(&pipeline_id) {
             None => return warn!("Visibity change for closed pipeline {:?}.", pipeline_id),
             Some(pipeline) => (pipeline.browsing_context_id, pipeline.parent_info),
         };
         if let Some((parent_pipeline_id, _)) = parent_pipeline_info {
             let visibility_msg = ConstellationControlMsg::NotifyVisibilityChange(parent_pipeline_id,
                                                                                  browsing_context_id,
                                                                                  visibility);
-            let  result = match self.pipelines.get(&parent_pipeline_id) {
+            let result = match self.pipelines.get(&parent_pipeline_id) {
                 None => return warn!("Parent pipeline {:?} closed", parent_pipeline_id),
                 Some(parent_pipeline) => parent_pipeline.event_loop.send(visibility_msg),
             };
 
             if let Err(e) = result {
                 self.handle_send_error(parent_pipeline_id, e);
             }
         }
--- a/servo/components/script/dom/document.rs
+++ b/servo/components/script/dom/document.rs
@@ -955,17 +955,17 @@ impl Document {
             let DBL_CLICK_TIMEOUT = Duration::from_millis(PREFS.get("dom.document.dblclick_timeout").as_u64()
                                                                                                     .unwrap_or(300));
             let DBL_CLICK_DIST_THRESHOLD = PREFS.get("dom.document.dblclick_dist").as_u64().unwrap_or(1);
 
             // Calculate distance between this click and the previous click.
             let line = click_pos - last_pos;
             let dist = (line.dot(line) as f64).sqrt();
 
-            if  now.duration_since(last_time) < DBL_CLICK_TIMEOUT &&
+            if now.duration_since(last_time) < DBL_CLICK_TIMEOUT &&
                 dist < DBL_CLICK_DIST_THRESHOLD as f64 {
                 // A double click has occurred if this click is within a certain time and dist. of previous click.
                 let click_count = 2;
                 let client_x = click_pos.x as i32;
                 let client_y = click_pos.y as i32;
 
                 let event = MouseEvent::new(&self.window,
                                             DOMString::from("dblclick"),
--- a/servo/components/script/serviceworker_manager.rs
+++ b/servo/components/script/serviceworker_manager.rs
@@ -171,17 +171,17 @@ impl ServiceWorkerManager {
                         let _ = sender.send(ServiceWorkerScriptMsg::Response(mediator));
                     }
                 } else {
                     if let Some(sender) = self.wakeup_serviceworker(scope) {
                         let _ = sender.send(ServiceWorkerScriptMsg::Response(mediator));
                     }
                 }
             } else {
-                let  _ = mediator.response_chan.send(None);
+                let _ = mediator.response_chan.send(None);
             }
         } else {
             let _ = mediator.response_chan.send(None);
         }
         true
     }
 
     #[allow(unsafe_code)]
--- a/servo/python/tidy/servo_tidy/tidy.py
+++ b/servo/python/tidy/servo_tidy/tidy.py
@@ -579,16 +579,22 @@ def check_rust(file_name, lines):
             (r"^\s*else {", "else braces should be on the same line", no_filter),
             (r"[^$ ]\([ \t]", "extra space after (", no_filter),
             # This particular pattern is not reentrant-safe in script_thread.rs
             (r"match self.documents.borrow", "use a separate variable for the match expression",
              lambda match, line: file_name.endswith('script_thread.rs')),
             # -> () 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):
                 if filter_func(match, line):
                     yield (idx + 1, message.format(*match.groups(), **match.groupdict()))
 
         if prev_open_brace and not line:
             yield (idx + 1, "found an empty line following a {")
--- a/servo/python/tidy/servo_tidy_tests/rust_tidy.rs
+++ b/servo/python/tidy/servo_tidy_tests/rust_tidy.rs
@@ -67,9 +67,15 @@ impl test {
     fn test_fun4()
        {
      }
     let var = if true {
           "true"
       } else { // Should not trigger
           "false"
       } // Should not trigger
+
+    if  true { // Double space after keyword
+        42
+    } else {
+        let xif = 42 in {  xif  } // Should not trigger
+    }
 }
--- a/servo/python/tidy/servo_tidy_tests/test_tidy.py
+++ b/servo/python/tidy/servo_tidy_tests/test_tidy.py
@@ -90,16 +90,17 @@ class CheckTidiness(unittest.TestCase):
         self.assertNoMoreErrors(errors)
 
     def test_apache2_incomplete(self):
         errors = tidy.collect_errors_for_files(iterFile('apache2_license.rs'), [], [tidy.check_license])
         self.assertEqual('incorrect license', errors.next()[2])
 
     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])
         self.assertEqual('missing space before }', errors.next()[2])
         self.assertTrue('use statement is not in alphabetical order' in errors.next()[2])
         self.assertEqual('use statement contains braces for single import', errors.next()[2])
         self.assertTrue('use statement is not in alphabetical order' in errors.next()[2])
         self.assertEqual('encountered whitespace following a use statement', errors.next()[2])
@@ -128,16 +129,17 @@ class CheckTidiness(unittest.TestCase):
         self.assertEqual('else braces should be on the same line', 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.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)
 
         self.assertTrue('feature attribute is not in alphabetical order' in feature_errors.next()[2])
         self.assertTrue('feature attribute is not in alphabetical order' in feature_errors.next()[2])
         self.assertTrue('feature attribute is not in alphabetical order' in feature_errors.next()[2])
         self.assertTrue('feature attribute is not in alphabetical order' in feature_errors.next()[2])
--- a/servo/tests/unit/net/http_loader.rs
+++ b/servo/tests/unit/net/http_loader.rs
@@ -938,17 +938,17 @@ fn test_load_follows_a_redirect() {
 
     let internal_response = response.internal_response.unwrap();
     assert!(internal_response.status.unwrap().is_success());
     assert_eq!(*internal_response.body.lock().unwrap(),
                ResponseBody::Done(b"Yay!".to_vec()));
 }
 
 #[test]
-fn  test_redirect_from_x_to_y_provides_y_cookies_from_y() {
+fn test_redirect_from_x_to_y_provides_y_cookies_from_y() {
     let shared_url_y = Arc::new(Mutex::new(None::<ServoUrl>));
     let shared_url_y_clone = shared_url_y.clone();
     let handler = move |request: HyperRequest, mut response: HyperResponse| {
         let path = match request.uri {
             RequestUri::AbsolutePath(path) => path,
             uri => panic!("Unexpected uri: {:?}", uri),
         };
         if path == "/com/" {