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 #7446

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

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

… attribute
  • Loading branch information
Hugo Thiessard
Hugo Thiessard committed Aug 29, 2015
commit ee7007d2f25f3b54898e51faa4198f8e1b0db4c0
@@ -169,6 +169,8 @@ def check_rust(file_name, contents):

uses = []

mods = []

for idx, line in enumerate(contents):
# simplify the analysis
line = line.strip()
@@ -192,7 +194,7 @@ def check_rust(file_name, contents):
line = re.sub('".*?"|\'.*?\'', '', line)

# get rid of comments and attributes
line = re.sub('//.*?$|/\*.*?$|^\*.*?$|^#.*?$', '', line)
line = re.sub('//.*?$|/\*.*?$|^\*.*?$|^#!?\[.*?]\s', '', line)

match = re.search(r",[A-Za-z0-9]", line)
if match:
@@ -259,6 +261,29 @@ def is_associated_type(match, line, index):
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 = []


def check_webidl_spec(file_name, contents):
# Sorted by this function (in pseudo-Rust). The idea is to group the same
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.