diff options
author | erneyja <joshua.erney@gmail.com> | 2015-08-30 22:20:38 -0400 |
---|---|---|
committer | erneyja <joshua.erney@gmail.com> | 2015-09-01 07:18:19 -0400 |
commit | 17663315dd64bba0ebb64c908f9beacc2e352d3a (patch) | |
tree | d335a52f3b9504f99822692923143c16cf8e5983 /python/tidy.py | |
parent | ccb8e4655759341e1b45139217cae7d8c2f7ec48 (diff) | |
download | servo-17663315dd64bba0ebb64c908f9beacc2e352d3a.tar.gz servo-17663315dd64bba0ebb64c908f9beacc2e352d3a.zip |
make test-tidy check that = have space after them
Diffstat (limited to 'python/tidy.py')
-rw-r--r-- | python/tidy.py | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/python/tidy.py b/python/tidy.py index 9ea9de24f30..6f1cbea5ea0 100644 --- a/python/tidy.py +++ b/python/tidy.py @@ -188,33 +188,35 @@ def check_rust(file_name, contents): line = merged_lines + line merged_lines = '' - # get rid of strings and chars because cases like regex expression - line = re.sub('".*?"|\'.*?\'', '', line) + # get rid of strings and chars because cases like regex expression, keep attributes + if not line_is_attribute(line): + line = re.sub('".*?"|\'.*?\'', '', line) - # get rid of comments and attributes - line = re.sub('//.*?$|/\*.*?$|^\*.*?$|^#.*?$', '', line) + # get rid of comments + line = re.sub('//.*?$|/\*.*?$|^\*.*?$', '', line) + + # get rid of attributes that do not contain = + line = re.sub('^#[A-Za-z0-9\(\)\[\]_]*?$', '', line) match = re.search(r",[A-Za-z0-9]", line) if match: yield (idx + 1, "missing space after ,") - # Avoid flagging <Item=Foo> constructs - def is_associated_type(match, line, index): - open_angle = line[0:match.end()].rfind('<') - close_angle = line[open_angle:].find('>') if open_angle != -1 else -1 - is_equals = match.group(0)[index] == '=' - generic_open = open_angle != -1 and open_angle < match.start() - generic_close = close_angle != -1 and close_angle + open_angle >= match.end() - return is_equals and generic_open and generic_close - - # - not included because of scientific notation (1e-6) - match = re.search(r"[A-Za-z0-9][\+/\*%=]", line) + if line_is_attribute(line): + pre_space_re = r"[A-Za-z0-9]=" + post_space_re = r"=[A-Za-z0-9\"]" + else: + # - not included because of scientific notation (1e-6) + pre_space_re = r"[A-Za-z0-9][\+/\*%=]" + # * not included because of dereferencing and casting + # - not included because of unary negation + post_space_re = r"[\+/\%=][A-Za-z0-9\"]" + + match = re.search(pre_space_re, line) if match and not is_associated_type(match, line, 1): yield (idx + 1, "missing space before %s" % match.group(0)[1]) - # * not included because of dereferencing and casting - # - not included because of unary negation - match = re.search(r"[\+/\%=][A-Za-z0-9]", line) + match = re.search(post_space_re, line) if match and not is_associated_type(match, line, 0): yield (idx + 1, "missing space after %s" % match.group(0)[0]) @@ -260,6 +262,20 @@ def check_rust(file_name, contents): uses = [] +# Avoid flagging <Item=Foo> constructs +def is_associated_type(match, line, index): + open_angle = line[0:match.end()].rfind('<') + close_angle = line[open_angle:].find('>') if open_angle != -1 else -1 + is_equals = match.group(0)[index] == '=' + generic_open = open_angle != -1 and open_angle < match.start() + generic_close = close_angle != -1 and close_angle + open_angle >= match.end() + return is_equals and generic_open and generic_close + + +def line_is_attribute(line): + return re.search(r"#\[.*\]", line) + + def check_webidl_spec(file_name, contents): # Sorted by this function (in pseudo-Rust). The idea is to group the same # organization together. |