[PATCH rfc] check-code: detect r'...\'...'

Mads Kiilerich mads at kiilerich.com
Tue Nov 8 19:37:54 CST 2011


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1320802647 -3600
# Node ID 20fe74e6bcd0518b108f85270c880f330963c490
# Parent  de7e2fba4326cad80bda0cb100d2ae2f58e67ee8
check-code: detect r'...\'...'

This spots the following spots:

.../contrib/check-code.py:70:
 >     (r'^([^"\'\n]|("[^"\n]*")|(\'[^\'\n]*\'))*\\^', "^ must be quoted"),
 don't use r'...\'...'
.../contrib/check-code.py:133:
 >     (r' x+[xo][\'"]\n\s+[\'"]x', 'string join across lines with no space'),
 don't use r'...\'...'
.../contrib/check-code.py:151:
 >     (r'("\')\.format\(', "str.format() not available in Python 2.4"),
 don't use r'...\'...'
.../contrib/check-code.py:174:
 >     (r' is\s+(not\s+)?["\'0-9-]', "object comparison with literal"),
 don't use r'...\'...'
.../contrib/check-code.py:204:
 >     (r'ui\.(status|progress|write|note|warn)\([\'\"]x',
 don't use r'...\'...'
.../contrib/hgfixes/fix_bytes.py:10:
 > _re = re.compile(r'[rR]?[\'\"]')
 don't use r'...\'...'
.../doc/hgmanpage.py:285:
 >             (u'´', ur'\''),
 don't use r'...\'...'

- but makes check-code.py even more obscure. For example: Should it be [xobqQ]
in line 133? (I guess not.)

Is it worth it?

Is there a simpler way to do it?

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -13,7 +13,10 @@
 
 def repquote(m):
     t = re.sub(r"\w", "x", m.group('text'))
-    t = re.sub(r"[^\s\nx]", "o", t)
+    t = re.sub("\\\\", "b", t)
+    t = re.sub("'", "q", t)
+    t = re.sub('"', "Q", t)
+    t = re.sub(r"[^\s\nxbqQ]", "o", t)
     return m.group('quote') + t + m.group('quote')
 
 def reppython(m):
@@ -191,6 +194,8 @@
      "always assign an opened file to a variable, and close it afterwards"),
     (r'(?i)descendent', "the proper spelling is descendAnt"),
     (r'\.debug\(\_', "don't mark debug messages for translation"),
+    ("r'[^']*bq", "don't use r'...\\'...'"),
+    ('r"[^"]*bQ', 'don\'t use r"...\\"..."'),
   ],
   # warnings
   [


More information about the Mercurial-devel mailing list