comparison contrib/check-code.py @ 10727:62b8f15683f2

check-code: more tests and more robust python filtering
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Thu, 18 Mar 2010 16:32:03 +0100
parents 8ea152e94484
children cd0c49bdbfd9
comparison
equal deleted inserted replaced
10726:bedef1c228d3 10727:62b8f15683f2
11 11
12 def repquote(m): 12 def repquote(m):
13 t = re.sub(r"\w", "x", m.group('text')) 13 t = re.sub(r"\w", "x", m.group('text'))
14 t = re.sub(r"[^\sx]", "o", t) 14 t = re.sub(r"[^\sx]", "o", t)
15 return m.group('quote') + t + m.group('quote') 15 return m.group('quote') + t + m.group('quote')
16
17 def reppython(m):
18 comment = m.group('comment')
19 if comment:
20 return "#" * len(comment)
21 return repquote(m)
16 22
17 def repcomment(m): 23 def repcomment(m):
18 return m.group(1) + "#" * len(m.group(2)) 24 return m.group(1) + "#" * len(m.group(2))
19 25
20 def repccomment(m): 26 def repccomment(m):
94 (r'raise Exception', "don't raise generic exceptions"), 100 (r'raise Exception', "don't raise generic exceptions"),
95 (r'ui\.(status|progress|write|note)\([\'\"]x', "unwrapped ui message"), 101 (r'ui\.(status|progress|write|note)\([\'\"]x', "unwrapped ui message"),
96 ] 102 ]
97 103
98 pyfilters = [ 104 pyfilters = [
99 (r"""(?msx)(?P<quote>('''|\"\"\"|(?<!')'(?!')|(?<!")"(?!"))) 105 (r"""(?msx)(?P<comment>\#.*?$)|
100 (?P<text>(.*?)) 106 ((?P<quote>('''|\"\"\"|(?<!')'(?!')|(?<!")"(?!")))
101 (?<!\\)(?P=quote)""", repquote), 107 (?P<text>(([^\\]|\\.)*?))
102 (r"( *)(#([^\n]*\S)?)", repcomment), 108 (?P=quote))""", reppython),
103 ] 109 ]
104 110
105 cpats = [ 111 cpats = [
106 (r'//', "don't use //-style comments"), 112 (r'//', "don't use //-style comments"),
107 (r'^ ', "don't use spaces to indent"), 113 (r'^ ', "don't use spaces to indent"),