aboutsummaryrefslogtreecommitdiffstats
path: root/python/tidy/servo_tidy
diff options
context:
space:
mode:
authorcoalman <tehcoalman@gmail.com>2017-04-17 03:45:30 -0400
committercoalman <tehcoalman@gmail.com>2017-04-18 14:56:03 -0400
commit57e74542ee0b33bf103064a194f4d7ba27ea5b49 (patch)
treebb92f0ff2aa4aa185e3f23b8ec02178f45b33a97 /python/tidy/servo_tidy
parenta754c10e79ef237b500bbf173eb7ba43529e51eb (diff)
downloadservo-57e74542ee0b33bf103064a194f4d7ba27ea5b49.tar.gz
servo-57e74542ee0b33bf103064a194f4d7ba27ea5b49.zip
Make tidy check that opening and closing braces that begin a line do so with proper alignment.
Diffstat (limited to 'python/tidy/servo_tidy')
-rw-r--r--python/tidy/servo_tidy/tidy.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/python/tidy/servo_tidy/tidy.py b/python/tidy/servo_tidy/tidy.py
index 1468d00bf42..ccca233db9c 100644
--- a/python/tidy/servo_tidy/tidy.py
+++ b/python/tidy/servo_tidy/tidy.py
@@ -450,6 +450,8 @@ def check_rust(file_name, lines):
prev_crate = {}
prev_mod = {}
prev_feature_name = ""
+ indent = 0
+ prev_indent = 0
decl_message = "{} is not in alphabetical order"
decl_expected = "\n\t\033[93mexpected: {}\033[0m"
@@ -458,6 +460,9 @@ def check_rust(file_name, lines):
for idx, original_line in enumerate(lines):
# simplify the analysis
line = original_line.strip()
+ prev_indent = indent
+ indent = len(original_line) - len(line)
+
is_attribute = re.search(r"#\[.*\]", line)
is_comment = re.search(r"^//|^/\*|^\*", line)
@@ -577,11 +582,17 @@ def check_rust(file_name, lines):
yield (idx + 1, "found an empty line following a {")
prev_open_brace = line.endswith("{")
+ # ensure a line starting with { or } has a number of leading spaces that is a multiple of 4
+ if line.startswith(("{", "}")):
+ match = re.match(r"(?: {4})* {1,3}([{}])", original_line)
+ if match:
+ if indent != prev_indent - 4:
+ yield (idx + 1, "space before {} is not a multiple of 4".format(match.group(1)))
+
# check alphabetical order of extern crates
if line.startswith("extern crate "):
# strip "extern crate " from the begin and ";" from the end
crate_name = line[13:-1]
- indent = len(original_line) - len(line)
if indent not in prev_crate:
prev_crate[indent] = ""
if prev_crate[indent] > crate_name:
@@ -616,7 +627,6 @@ def check_rust(file_name, lines):
# into a single import block
if line.startswith("use "):
import_block = True
- indent = len(original_line) - len(line)
if not line.endswith(";") and '{' in line:
yield (idx + 1, "use statement spans multiple lines")
if '{ ' in line:
@@ -645,7 +655,6 @@ def check_rust(file_name, lines):
# modules must be in the same line and alphabetically sorted
if line.startswith("mod ") or line.startswith("pub mod "):
- indent = len(original_line) - len(line)
# strip /(pub )?mod/ from the left and ";" from the right
mod = line[4:-1] if line.startswith("mod ") else line[8:-1]