servo: Merge #20213 - Add the option in servo-tidy to not check for alphabetical ordering (from nical:tidy-alphabetical-bs); r=jdm
authorNicolas Silva <nical@fastmail.com>
Tue, 06 Mar 2018 13:39:59 -0500
changeset 461816 a30bf832849293bae5b24454518121a74ab4d7bc
parent 461815 4811c426205d64975325c471f897ede03fba2757
child 461817 da7d8d24de6135355ebe6b2f72eefa8c475a9d30
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
milestone60.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 #20213 - Add the option in servo-tidy to not check for alphabetical ordering (from nical:tidy-alphabetical-bs); r=jdm <!-- Please describe your changes on the following line: --> An option to disable checking for alphabetical ordering of use/mod/extern crate statements in servo-tidy. These checks are still enabled by default but WebRender will turn them off. --- <!-- 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 <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because it doesn't affect servo. <!-- 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: c8eceb90a15f0a28478bf0d26702070225d5f1c1
servo/python/tidy/servo_tidy/tidy.py
servo/servo-tidy.toml
--- a/servo/python/tidy/servo_tidy/tidy.py
+++ b/servo/python/tidy/servo_tidy/tidy.py
@@ -35,16 +35,17 @@ from wptmanifest import parser, node
 
 CONFIG_FILE_PATH = os.path.join(".", "servo-tidy.toml")
 WPT_MANIFEST_PATH = wpt_path("include.ini")
 
 # Default configs
 config = {
     "skip-check-length": False,
     "skip-check-licenses": False,
+    "check-alphabetical-order": True,
     "check-ordered-json-keys": [],
     "lint-scripts": [],
     "blocked-packages": {},
     "ignore": {
         "files": [
             os.path.join(".", "."),   # ignore hidden files
         ],
         "directories": [
@@ -501,16 +502,17 @@ def check_rust(file_name, lines):
     multi_line_string = False
     current_indent = 0
     prev_crate = {}
     prev_mod = {}
     prev_feature_name = ""
     indent = 0
     prev_indent = 0
 
+    check_alphabetical_order = config["check-alphabetical-order"]
     decl_message = "{} is not in alphabetical order"
     decl_expected = "\n\t\033[93mexpected: {}\033[0m"
     decl_found = "\n\t\033[91mfound: {}\033[0m"
 
     for idx, original_line in enumerate(lines):
         # simplify the analysis
         line = original_line.strip()
         prev_indent = indent
@@ -665,39 +667,39 @@ def check_rust(file_name, lines):
                     yield (idx + 1, "space before {} is not a multiple of 4".format(match.group(1)))
 
         # check alphabetical order of extern crates
         if line.startswith("extern crate "):
             # strip "extern crate " from the begin and ";" from the end
             crate_name = line[13:-1]
             if indent not in prev_crate:
                 prev_crate[indent] = ""
-            if prev_crate[indent] > crate_name:
+            if prev_crate[indent] > crate_name and check_alphabetical_order:
                 yield(idx + 1, decl_message.format("extern crate declaration")
                       + decl_expected.format(prev_crate[indent])
                       + decl_found.format(crate_name))
             prev_crate[indent] = crate_name
 
         if line == "}":
             for i in [i for i in prev_crate.keys() if i > indent]:
                 del prev_crate[i]
 
         # check alphabetical order of feature attributes in lib.rs files
         if is_lib_rs_file:
             match = re.search(r"#!\[feature\((.*)\)\]", line)
 
             if match:
                 features = map(lambda w: w.strip(), match.group(1).split(','))
                 sorted_features = sorted(features)
-                if sorted_features != features:
+                if sorted_features != features and check_alphabetical_order:
                     yield(idx + 1, decl_message.format("feature attribute")
                           + decl_expected.format(tuple(sorted_features))
                           + decl_found.format(tuple(features)))
 
-                if prev_feature_name > sorted_features[0]:
+                if prev_feature_name > sorted_features[0] and check_alphabetical_order:
                     yield(idx + 1, decl_message.format("feature attribute")
                           + decl_expected.format(prev_feature_name + " after " + sorted_features[0])
                           + decl_found.format(prev_feature_name + " before " + sorted_features[0]))
 
                 prev_feature_name = sorted_features[0]
             else:
                 # not a feature attribute line, so empty previous name
                 prev_feature_name = ""
@@ -712,17 +714,17 @@ def check_rust(file_name, lines):
                 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:
+                if indent == current_indent and current_use_cut < prev_use_cut and check_alphabetical_order:
                     yield(idx + 1, decl_message.format("use statement")
                           + decl_expected.format(prev_use)
                           + decl_found.format(current_use))
             prev_use = current_use
             current_indent = indent
 
         if whitespace or not import_block:
             current_indent = 0
@@ -738,34 +740,34 @@ def check_rust(file_name, lines):
             mod = line[4:-1] if line.startswith("mod ") else line[8:-1]
 
             if (idx - 1) < 0 or "#[macro_use]" not in lines[idx - 1]:
                 match = line.find(" {")
                 if indent not in prev_mod:
                     prev_mod[indent] = ""
                 if match == -1 and not line.endswith(";"):
                     yield (idx + 1, "mod declaration spans multiple lines")
-                if prev_mod[indent] and mod < prev_mod[indent]:
+                if prev_mod[indent] and mod < prev_mod[indent] and check_alphabetical_order:
                     yield(idx + 1, decl_message.format("mod declaration")
                           + decl_expected.format(prev_mod[indent])
                           + decl_found.format(mod))
                 prev_mod[indent] = mod
         else:
             # we now erase previous entries
             prev_mod = {}
 
         # derivable traits should be alphabetically ordered
         if is_attribute:
             # match the derivable traits filtering out macro expansions
             match = re.search(r"#\[derive\(([a-zA-Z, ]*)", line)
             if match:
                 derives = map(lambda w: w.strip(), match.group(1).split(','))
                 # sort, compare and report
                 sorted_derives = sorted(derives)
-                if sorted_derives != derives:
+                if sorted_derives != derives and check_alphabetical_order:
                     yield(idx + 1, decl_message.format("derivable traits list")
                               + decl_expected.format(", ".join(sorted_derives))
                               + decl_found.format(", ".join(derives)))
 
 
 # Avoid flagging <Item=Foo> constructs
 def is_associated_type(match, line):
     if match.group(1) != '=':
--- a/servo/servo-tidy.toml
+++ b/servo/servo-tidy.toml
@@ -1,11 +1,12 @@
 [configs]
 skip-check-length = false
 skip-check-licenses = false
+check-alphabetical-order = true
 check-ordered-json-keys = [
   "./resources/prefs.json",
 ]
 lint-scripts = [
   "./python/servo/lints/wpt_lint.py",
 ]
 
 # Packages which we avoid using in Servo.