servo: Merge #15690 - Add 'use statements with extraneous spaces' tidy check (from vwvww:issue_14898); r=Wafflespeanut
authorvwvww <memory128m@gmail.com>
Wed, 22 Feb 2017 21:19:08 -0800
changeset 373418 27b94a28f81502a7c0ae13e4f4979019659c47b6
parent 373417 75228b956df12f72c324e25be2602202eb4ab6db
child 373419 20a81b2adf80e957b66aa861ff8159198c7d3684
push id10863
push userjlorenzo@mozilla.com
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)
reviewersWafflespeanut
bugs15690, 14898
milestone54.0a1
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 rust_tidy.rs. * Added a code that using 'use statements with extraneous spaces' code in rust_tidy.rs * Added assertion code in test_tidy.py. * check_rust function in tidy.py 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/inherited_text.rs) 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: https://github.com/servo/servo Source-Revision: b34fdf62341a01abb8da021f07071c5eb8b06622
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/style/parsing/inherited_text.rs
--- a/servo/python/tidy/servo_tidy/tidy.py
+++ b/servo/python/tidy/servo_tidy/tidy.py
@@ -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/rust_tidy.rs
+++ b/servo/python/tidy/servo_tidy_tests/rust_tidy.rs
@@ -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 http://mozilla.org/MPL/2.0/. */
 
 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/test_tidy.py
+++ b/servo/python/tidy/servo_tidy_tests/test_tidy.py
@@ -90,16 +90,18 @@ 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 {', 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])
         self.assertTrue('mod declaration is not in alphabetical order' in errors.next()[2])
         self.assertEqual('mod declaration spans multiple lines', errors.next()[2])
--- a/servo/tests/unit/style/parsing/inherited_text.rs
+++ b/servo/tests/unit/style/parsing/inherited_text.rs
@@ -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);
 }
 
 #[test]
 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));