servo: Merge #8692 - Ensure crate are alphabetically sorted (from GuillaumeGomez:patch-1); r=Wafflespeanut

cc @nox

Source-Repo: https://github.com/servo/servo
Source-Revision: dbff1ab33636bc7d60a4c97b63f39b59985726ce
This commit is contained in:
Guillaume Gomez
2015-11-28 19:04:11 +05:00
parent 4a7358a41c
commit 7855be6622
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: