diff options
author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2015-11-26 01:23:11 +0100 |
---|---|---|
committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2015-11-28 03:11:08 +0100 |
commit | 6e7de62b38a04e614c60e864c8d100bf3e72304f (patch) | |
tree | de97525c5e08f1fe84691b6da5b1a03a033fc960 /python/tidy.py | |
parent | f96e8ce9e8c0a2c9de9574f538718defdcd93c11 (diff) | |
download | servo-6e7de62b38a04e614c60e864c8d100bf3e72304f.tar.gz servo-6e7de62b38a04e614c60e864c8d100bf3e72304f.zip |
Add check up on extern crate order and sort extern crates alphabetically
Diffstat (limited to 'python/tidy.py')
-rw-r--r-- | python/tidy.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/python/tidy.py b/python/tidy.py index 499fb8c5efc..78675b88162 100644 --- a/python/tidy.py +++ b/python/tidy.py @@ -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: |