diff options
author | Johann Tuffe <tafia973@gmail.com> | 2015-08-20 20:47:25 +0800 |
---|---|---|
committer | Johann Tuffe <tafia973@gmail.com> | 2015-08-20 20:47:25 +0800 |
commit | 009f6f63ad45164b7ef7fbc6322d421143c03185 (patch) | |
tree | b4ab729dbbceac207feeed19111a271bc51f9860 /python/tidy.py | |
parent | ec07178b6fc5a0ab559eb191952101cf92b5d666 (diff) | |
download | servo-009f6f63ad45164b7ef7fbc6322d421143c03185.tar.gz servo-009f6f63ad45164b7ef7fbc6322d421143c03185.zip |
check for uses to be sorted
Diffstat (limited to 'python/tidy.py')
-rw-r--r-- | python/tidy.py | 18 |
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): |