changeset 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 e53f961ac75f
children 79a11506803f
files contrib/check-code.py tests/test-contrib-check-code.t
diffstat 2 files changed, 29 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/check-code.py	Sat May 21 21:43:29 2016 +0900
+++ b/contrib/check-code.py	Tue May 31 20:58:10 2016 +0900
@@ -51,22 +51,20 @@
     return re.compile(pat)
 
 def repquote(m):
-    fromc = '.:'
-    tochr = 'pq'
+    fixedmap = {'.': 'p', ':': 'q'}
     def encodechr(i):
         if i > 255:
             return 'u'
         c = chr(i)
         if c in ' \n':
             return c
+        if c in fixedmap:
+            return fixedmap[c]
         if c.isalpha():
             return 'x'
         if c.isdigit():
             return 'n'
-        try:
-            return tochr[fromc.find(c)]
-        except (ValueError, IndexError):
-            return 'o'
+        return 'o'
     t = m.group('text')
     tt = ''.join(encodechr(i) for i in xrange(256))
     t = t.translate(tt)
@@ -248,7 +246,7 @@
     (r'^\s+(\w|\.)+=\w[^,()\n]*$', "missing whitespace in assignment"),
     (r'\w\s=\s\s+\w', "gratuitous whitespace after ="),
     (r'.{81}', "line too long"),
-    (r' x+[xo][\'"]\n\s+[\'"]x', 'string join across lines with no space'),
+    (r' x+[xpqo][\'"]\n\s+[\'"]x', 'string join across lines with no space'),
     (r'[^\n]\Z', "no trailing newline"),
     (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"),
 #    (r'^\s+[^_ \n][^_. \n]+_[^_\n]+\s*=',
--- a/tests/test-contrib-check-code.t	Sat May 21 21:43:29 2016 +0900
+++ b/tests/test-contrib-check-code.t	Tue May 31 20:58:10 2016 +0900
@@ -248,3 +248,27 @@
    > {desc|escape}
    warning: follow desc keyword with either firstline or websub
   [1]
+
+'string join across lines with no space' detection
+
+  $ cat > stringjoin.py <<EOF
+  > foo = (' foo'
+  >        'bar foo.'
+  >        'bar foo:'
+  >        'bar foo@'
+  >        'bar')
+  > EOF
+  $ "$check_code" stringjoin.py
+  stringjoin.py:1:
+   > foo = (' foo'
+   string join across lines with no space
+  stringjoin.py:2:
+   >        'bar foo.'
+   string join across lines with no space
+  stringjoin.py:3:
+   >        'bar foo:'
+   string join across lines with no space
+  stringjoin.py:4:
+   >        'bar foo@'
+   string join across lines with no space
+  [1]