aboutsummaryrefslogtreecommitdiffstats
path: root/python/tidy.py
diff options
context:
space:
mode:
authorJohann Tuffe <tafia973@gmail.com>2015-08-20 20:47:25 +0800
committerJohann Tuffe <tafia973@gmail.com>2015-08-20 20:47:25 +0800
commit009f6f63ad45164b7ef7fbc6322d421143c03185 (patch)
treeb4ab729dbbceac207feeed19111a271bc51f9860 /python/tidy.py
parentec07178b6fc5a0ab559eb191952101cf92b5d666 (diff)
downloadservo-009f6f63ad45164b7ef7fbc6322d421143c03185.tar.gz
servo-009f6f63ad45164b7ef7fbc6322d421143c03185.zip
check for uses to be sorted
Diffstat (limited to 'python/tidy.py')
-rw-r--r--python/tidy.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/python/tidy.py b/python/tidy.py
index 20306baf1bb..9a51f821388 100644
--- a/python/tidy.py
+++ b/python/tidy.py
@@ -174,6 +174,9 @@ def check_rust(file_name, contents):
contents = contents.splitlines(True)
comment_depth = 0
merged_lines = ''
+
+ uses = []
+
for idx, line in enumerate(contents):
# simplify the analysis
line = line.strip()
@@ -248,8 +251,19 @@ def check_rust(file_name, contents):
if match:
yield (idx + 1, "missing space before {")
- if line.startswith("use ") and "{" in line and "}" not in line:
- yield (idx + 1, "use statement spans multiple lines")
+ # imports must be in the same line and alphabetically sorted
+ if line.startswith("use "):
+ use = line[4:]
+ match = use.find('{')
+ if match >= 0 and "}" not in use[match:]:
+ yield (idx + 1, "use statement spans multiple lines")
+ uses.append(use[:len(use) - 1])
+ elif len(uses) > 0:
+ sorted_uses = sorted(uses)
+ for i in range(len(uses)):
+ if sorted_uses[i] != uses[i]:
+ yield (idx + 1 - len(uses) + i, "use statement is not in alphabetical order")
+ uses = []
def check_webidl_spec(file_name, contents):