From 9b91c7afebfcda5fb748868f0a2c173bf9497885 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Sun, 6 Mar 2016 15:26:22 -0800 Subject: [PATCH] Handle escaped strings in rust linting, tidy.py tidy.py now strips strings even if they have escapes before linting. Use raw strings for regex with lots of backslashes Handle ALL escape sequences in strings for tidy, not just escaped string terminators --- python/tidy.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/tidy.py b/python/tidy.py index 35b4f230dbb..de6365cc0e6 100644 --- a/python/tidy.py +++ b/python/tidy.py @@ -290,7 +290,7 @@ def check_rust(file_name, lines): # get rid of strings and chars because cases like regex expression, keep attributes if not line_is_attribute(line): - line = re.sub('".*?"|\'.*?\'', '', line) + line = re.sub(r'"(\\.|[^\\"])*?"|' + r"'(\\.|[^\\'])*?'", '', line) # get rid of comments line = re.sub('//.*?$|/\*.*?$|^\*.*?$', '', line) @@ -346,6 +346,7 @@ def check_rust(file_name, lines): for match in re.finditer(pattern, line): if not filter_func(match, line): continue + yield (idx + 1, message.format(*match.groups(), **match.groupdict())) # check alphabetical order of extern crates