Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #7390 : tidy now check the order of mod declarations even whith attribute #7680

Merged
merged 2 commits into from Sep 18, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

fixes #7390 : tidy now check the order of mod declarations even whith…

… attribute
  • Loading branch information
Hugo Thiessard
Hugo Thiessard committed Sep 18, 2015
commit e81e91207cb87ade4eeaa99917eaecd0f5ecd00d
@@ -203,6 +203,8 @@ def check_rust(file_name, contents):

uses = []

mods = []

for idx, line in enumerate(contents):
# simplify the analysis
line = line.strip()
@@ -305,6 +307,29 @@ def check_rust(file_name, contents):
yield (idx + 1 - len(uses) + i, message + expected + found)
uses = []

# modules must be in the same line and alphabetically sorted
if line.startswith("mod ") or line.startswith("pub mod "):
mod = ""
if line.startswith("mod "):
mod = line[4:]
else:
mod = line[8:]

match = line.find(" {")
if match == -1:
if not mod.endswith(";"):
yield (idx + 1, "mod statement spans multiple lines")
mods.append(mod[:len(mod) - 1])
elif len(mods) > 0:
sorted_mods = sorted(mods)
for i in range(len(mods)):
if sorted_mods[i] != mods[i]:
message = "mod statement is not in alphabetical order"
expected = "\n\t\033[93mexpected: {}\033[0m".format(sorted_mods[i])
found = "\n\t\033[91mfound: {}\033[0m".format(mods[i])
yield (idx + 1 - len(mods) + i, message + expected + found)
mods = []


# Avoid flagging <Item=Foo> constructs
def is_associated_type(match, line, index):
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.