aboutsummaryrefslogtreecommitdiffstats
path: root/python/tidy.py
diff options
context:
space:
mode:
authorwilmoz <wcubasalas@gmail.com>2015-08-12 15:07:36 -0500
committerJosh Matthews <josh@joshmatthews.net>2015-08-16 10:25:50 -0400
commite57a3888a592242da33fa61a90551316831f9c95 (patch)
tree1a2ad39a45054c6ace8e4002164f4f5109ef5a6c /python/tidy.py
parent4d7dd66ec9f0a5229a52b3301ac1a38848ebfb4b (diff)
downloadservo-e57a3888a592242da33fa61a90551316831f9c95.tar.gz
servo-e57a3888a592242da33fa61a90551316831f9c95.zip
Check for simple Rust style nits in tidy.py
Diffstat (limited to 'python/tidy.py')
-rw-r--r--python/tidy.py52
1 files changed, 51 insertions, 1 deletions
diff --git a/python/tidy.py b/python/tidy.py
index 40251cdf8a7..fdc2f9ada11 100644
--- a/python/tidy.py
+++ b/python/tidy.py
@@ -165,6 +165,55 @@ def check_toml(file_name, contents):
yield (idx + 1, "found asterisk instead of minimum version number")
+def check_rust(file_name, contents):
+ if not file_name.endswith(".rs") or file_name.endswith("properties.mako.rs"):
+ raise StopIteration
+ contents = contents.splitlines(True)
+ for idx, line in enumerate(contents):
+ # simplify the analisis
+ line = line.lstrip()
+
+ # get rid of strings and chars because cases like regex expression
+ line = re.sub('".*?"|\'.*?\'', '', line)
+
+ # get rid of comments and attributes
+ line = re.sub('//.*?$|/\*.*?$|^\*.*?$|^#.*?$', '', line)
+
+ match = re.search(r",[A-Za-z0-9]", line)
+ if match is not None:
+ yield (idx + 1, "there should be a space following a comma")
+
+ match = re.search(r"[A-Za-z0-9][\+\-/\*%=]", line)
+ if match is not None:
+ yield (idx + 1, "there should be a space preceding an operator")
+
+ # * not included because of dereferencing and casting
+ # - not included because of unary negation
+ match = re.search(r"[\+/\%=][A-Za-z0-9]", line)
+ if match is not None:
+ yield (idx + 1, "there should be a space following an operator")
+
+ match = re.search(r"\)->", line)
+ if match is not None:
+ yield (idx + 1, "there should be a space before -> in a function return type")
+
+ match = re.search(r"->[A-Za-z]", line)
+ if match is not None:
+ yield (idx + 1, "there should be a space after -> in a function return type")
+
+ match = re.search(r" :", line)
+ if match is not None:
+ yield (idx + 1, "there should not be a space preceding a colon")
+
+ match = re.search(r"[A-Za-z0-9\)]{", line)
+ if match is not None:
+ yield (idx + 1, "there should be a space before an open brace")
+
+ match = re.search(r"^use", line)
+ if match is not None and "{" in line and "}" not in line:
+ yield (idx + 1, "use statements should not span more than one line")
+
+
def check_webidl_spec(file_name, contents):
# Sorted by this function (in pseudo-Rust). The idea is to group the same
# organization together.
@@ -278,7 +327,8 @@ def scan():
all_files = collect_file_names()
files_to_check = filter(should_check, all_files)
- checking_functions = [check_license, check_by_line, check_flake8, check_toml, check_webidl_spec, check_spec]
+ checking_functions = [check_license, check_by_line, check_flake8, check_toml,
+ check_rust, check_webidl_spec, check_spec]
errors = collect_errors_for_files(files_to_check, checking_functions)
reftest_files = collect_file_names(reftest_directories)