comparison contrib/check-code.py @ 29276:4dd530df4742

check-code: replace quoted characters correctly 169cb9e47f8e tried to detect '.. note::' more exactly. But implementation of it seems not correct, because: - fromc.find(c) returns -1 for other than "." and ":" - tochr[-1] returns "q" for such characters, but - expected result for them is "o" This patch uses dict to manage replacement instead of replacing str.find() by str.index(), for improvement/refactoring in subsequent patches. Examination by fixedmap is placed just after examination for ' ' and '\n', because subsequent patch will integrate the latter into the former. This patch also changes regexp for 'string join across lines with no space' rule, and adds detailed test for it, because 169cb9e47f8e did: - make repquote() distinguish "." (as "p") and ":" (as "q") from others (as "o"), but - not change this regexp without any reason (in commit log, at least), even though this regexp depends on what "o" means This patch doesn't focuses on deciding whether "." and/or ":" should be followed by whitespace or not in translatable messages.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 31 May 2016 20:58:10 +0900
parents 2f9ad6ca19c2
children 79a11506803f
comparison
equal deleted inserted replaced
29275:e53f961ac75f 29276:4dd530df4742
49 except re2.error: 49 except re2.error:
50 pass 50 pass
51 return re.compile(pat) 51 return re.compile(pat)
52 52
53 def repquote(m): 53 def repquote(m):
54 fromc = '.:' 54 fixedmap = {'.': 'p', ':': 'q'}
55 tochr = 'pq'
56 def encodechr(i): 55 def encodechr(i):
57 if i > 255: 56 if i > 255:
58 return 'u' 57 return 'u'
59 c = chr(i) 58 c = chr(i)
60 if c in ' \n': 59 if c in ' \n':
61 return c 60 return c
61 if c in fixedmap:
62 return fixedmap[c]
62 if c.isalpha(): 63 if c.isalpha():
63 return 'x' 64 return 'x'
64 if c.isdigit(): 65 if c.isdigit():
65 return 'n' 66 return 'n'
66 try: 67 return 'o'
67 return tochr[fromc.find(c)]
68 except (ValueError, IndexError):
69 return 'o'
70 t = m.group('text') 68 t = m.group('text')
71 tt = ''.join(encodechr(i) for i in xrange(256)) 69 tt = ''.join(encodechr(i) for i in xrange(256))
72 t = t.translate(tt) 70 t = t.translate(tt)
73 return m.group('quote') + t + m.group('quote') 71 return m.group('quote') + t + m.group('quote')
74 72
246 (r'(\w|\)),\w', "missing whitespace after ,"), 244 (r'(\w|\)),\w', "missing whitespace after ,"),
247 (r'(\w|\))[+/*\-<>]\w', "missing whitespace in expression"), 245 (r'(\w|\))[+/*\-<>]\w', "missing whitespace in expression"),
248 (r'^\s+(\w|\.)+=\w[^,()\n]*$', "missing whitespace in assignment"), 246 (r'^\s+(\w|\.)+=\w[^,()\n]*$', "missing whitespace in assignment"),
249 (r'\w\s=\s\s+\w', "gratuitous whitespace after ="), 247 (r'\w\s=\s\s+\w', "gratuitous whitespace after ="),
250 (r'.{81}', "line too long"), 248 (r'.{81}', "line too long"),
251 (r' x+[xo][\'"]\n\s+[\'"]x', 'string join across lines with no space'), 249 (r' x+[xpqo][\'"]\n\s+[\'"]x', 'string join across lines with no space'),
252 (r'[^\n]\Z', "no trailing newline"), 250 (r'[^\n]\Z', "no trailing newline"),
253 (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"), 251 (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"),
254 # (r'^\s+[^_ \n][^_. \n]+_[^_\n]+\s*=', 252 # (r'^\s+[^_ \n][^_. \n]+_[^_\n]+\s*=',
255 # "don't use underbars in identifiers"), 253 # "don't use underbars in identifiers"),
256 (r'^\s+(self\.)?[A-za-z][a-z0-9]+[A-Z]\w* = ', 254 (r'^\s+(self\.)?[A-za-z][a-z0-9]+[A-Z]\w* = ',