servo: Merge #15690 - Add 'use statements with extraneous spaces' tidy check (from vwvww:issue_14898); r=Wafflespeanut
authorvwvww <>
Wed, 22 Feb 2017 21:19:08 -0800
changeset 373418 27b94a28f81502a7c0ae13e4f4979019659c47b6
parent 373417 75228b956df12f72c324e25be2602202eb4ab6db
child 373419 20a81b2adf80e957b66aa861ff8159198c7d3684
push id10863
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs15690, 14898
servo: Merge #15690 - Add 'use statements with extraneous spaces' tidy check (from vwvww:issue_14898); r=Wafflespeanut Add 'use statements with extraneous spaces' tidy check I added simple check routine for 'use statements with extraneous spaces' and codes that breaks the check routine in * Added a code that using 'use statements with extraneous spaces' code in * Added assertion code in * check_rust function in now recognizes the simple case in the 'use statements with extraneous spaces'. * Ran tidy check on rust code and modified a code(tests/unit/style/parsing/ that is not passing on this new tidy check. TODO: this code has to be refactored to support more general cases, such as tab or newline. - [X] `./mach build -d` does not report any errors - [X] ./mach test-tidy does not report any errors - [X] These changes fix #14898 (github issue number if applicable). - [X] These changes do not require tests because ./mach test-tidy itself is the test for the code. Source-Repo: Source-Revision: b34fdf62341a01abb8da021f07071c5eb8b06622
--- a/servo/python/tidy/servo_tidy/
+++ b/servo/python/tidy/servo_tidy/
@@ -607,16 +607,20 @@ def check_rust(file_name, lines):
         # imports must be in the same line, alphabetically sorted, and merged
         # into a single import block
         if line.startswith("use "):
             import_block = True
             indent = len(original_line) - len(line)
             if not line.endswith(";") and '{' in line:
                 yield (idx + 1, "use statement spans multiple lines")
+            if '{ ' in line:
+                yield (idx + 1, "extra space after {")
+            if ' }' in line:
+                yield (idx + 1, "extra space before }")
             # strip "use" from the begin and ";" from the end
             current_use = line[4:-1]
             if prev_use:
                 current_use_cut = current_use.replace("{self,", ".").replace("{", ".")
                 prev_use_cut = prev_use.replace("{self,", ".").replace("{", ".")
                 if indent == current_indent and current_use_cut < prev_use_cut:
                     yield(idx + 1, decl_message.format("use statement")
                           + decl_expected.format(prev_use)
--- a/servo/python/tidy/servo_tidy_tests/
+++ b/servo/python/tidy/servo_tidy_tests/
@@ -1,13 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at */
 use    app_units::Au;
+use azure::azure_hl::{ AntialiasMode, Color, ColorPattern, CompositionOp };
 use azure::azure_hl::{AntialiasMode, Color,
 ColorPattern, CompositionOp};
 use euclid::size::Size2D;
 use azure::azure::AzIntSize;
 use azure::azure::{AzIntSize};
 use std;
--- a/servo/python/tidy/servo_tidy_tests/
+++ b/servo/python/tidy/servo_tidy_tests/
@@ -90,16 +90,18 @@ class CheckTidiness(unittest.TestCase):
     def test_apache2_incomplete(self):
         errors = tidy.collect_errors_for_files(iterFile(''), [], [tidy.check_license])
         self.assertEqual('incorrect license',[2])
     def test_rust(self):
         errors = tidy.collect_errors_for_files(iterFile(''), [], [tidy.check_rust], print_text=False)
+        self.assertEqual('extra space after {',[2])
+        self.assertEqual('extra space before }',[2])
         self.assertEqual('use statement spans multiple lines',[2])
         self.assertEqual('missing space before }',[2])
         self.assertTrue('use statement is not in alphabetical order' in[2])
         self.assertEqual('use statement contains braces for single import',[2])
         self.assertTrue('use statement is not in alphabetical order' in[2])
         self.assertEqual('encountered whitespace following a use statement',[2])
         self.assertTrue('mod declaration is not in alphabetical order' in[2])
         self.assertEqual('mod declaration spans multiple lines',[2])
--- a/servo/tests/unit/style/parsing/
+++ b/servo/tests/unit/style/parsing/
@@ -69,17 +69,17 @@ fn text_emphasis_style_longhand_should_p
     let devanagari_string = parse_longhand!(text_emphasis_style, "\"षि\"");
     let devanagari_string_struct = SpecifiedValue::String("षि".to_string());
     assert_eq!(devanagari_string, devanagari_string_struct);
 fn test_text_emphasis_position() {
     use style::properties::longhands::text_emphasis_position;
-    use style::properties::longhands::text_emphasis_position::{HorizontalWritingModeValue, VerticalWritingModeValue };
+    use style::properties::longhands::text_emphasis_position::{HorizontalWritingModeValue, VerticalWritingModeValue};
     use style::properties::longhands::text_emphasis_position::SpecifiedValue;
     let over_right = parse_longhand!(text_emphasis_position, "over right");
     assert_eq!(over_right, SpecifiedValue(HorizontalWritingModeValue::Over, VerticalWritingModeValue::Right));
     let over_left = parse_longhand!(text_emphasis_position, "over left");
     assert_eq!(over_left, SpecifiedValue(HorizontalWritingModeValue::Over, VerticalWritingModeValue::Left));