Auto merge of #8692 - GuillaumeGomez:patch-1, r=Wafflespeanut

Ensure crate are alphabetically sorted

cc @nox

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8692)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-11-28 19:34:11 +05:30
commit dbff1ab336
22 changed files with 111 additions and 108 deletions

View file

@ -221,12 +221,25 @@ def check_rust(file_name, contents):
whitespace = False
uses = []
prev_crate = {}
mods = []
for idx, line in enumerate(contents):
for idx, original_line in enumerate(contents):
# simplify the analysis
line = line.strip()
line = original_line.strip()
# check extern crates
if line.startswith("extern crate"):
crate_name = line.replace("extern crate ", "").replace(";", "")
indent = len(original_line) - len(line)
if indent not in prev_crate:
prev_crate[indent] = ""
if prev_crate[indent] > crate_name:
message = "extern crate statement is not in alphabetical order"
expected = "\n\t\033[93mexpected: {}\033[0m".format(prev_crate[indent])
found = "\n\t\033[91mfound: {}\033[0m".format(crate_name)
yield(idx + 1, message + expected + found)
prev_crate[indent] = crate_name
# Simple heuristic to avoid common case of no comments.
if '/' in line: