Skip to content

Commit

Permalink
add check for unsorted uses
Browse files Browse the repository at this point in the history
  • Loading branch information
tafia committed Aug 20, 2015
1 parent caf11a6 commit d2b6603
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions python/tidy.py
Expand Up @@ -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()
Expand Down Expand Up @@ -248,8 +251,19 @@ def is_associated_type(match, line, index):
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):
Expand Down

0 comments on commit d2b6603

Please sign in to comment.