Patchwork [4,of,6] check-code: make repquote distinguish more characters for exact detection

login
register
mail settings
Submitter Katsunori FUJIWARA
Date May 31, 2016, 12:15 p.m.
Message ID <353c034224f9e213ae82.1464696938@feefifofum>
Download mbox | patch
Permalink /patch/15277/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - May 31, 2016, 12:15 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1464696150 -32400
#      Tue May 31 21:02:30 2016 +0900
# Node ID 353c034224f9e213ae82594eaecf40cb49638e19
# Parent  5eda83fb09fc7e197aea86fcdceca195e7f7fbe9
check-code: make repquote distinguish more characters for exact detection

This patch makes repquote() distinguish more characters below, as a
preparation for exact detection in subsequent patch.

  - "%"  as "%"
  - "\\" as "b"(ackslash)
  - "*"  as "A"(sterisk)
  - "+"  as "P"(lus)
  - "-"  as "M"(inus)

Characters other than "%" don't' use itself as replacement, because
they are treated as special ones in regexp.
timeless - May 31, 2016, 6:55 p.m.
FUJIWARA Katsunori wrote:
> Characters other than "%" don't' use itself as replacement, because

you have a stray `'` after the `t` in `don't`
Yuya Nishihara - June 1, 2016, 2:50 p.m.
On Tue, 31 May 2016 14:55:02 -0400, timeless wrote:
> FUJIWARA Katsunori wrote:
> > Characters other than "%" don't' use itself as replacement, because
> 
> you have a stray `'` after the `t` in `don't`

This series wasn't as simple as I expected, but the change looks good.
I've pushed the first 4 patches to the committed repo, thanks.

Patch

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -53,7 +53,8 @@  def compilere(pat, multiline=False):
 def repquote(m):
     # check "rules depending on implementation of repquote()" in each
     # patterns (especially pypats), before changing this function
-    fixedmap = {' ': ' ', '\n': '\n', '.': 'p', ':': 'q'}
+    fixedmap = {' ': ' ', '\n': '\n', '.': 'p', ':': 'q',
+                '%': '%', '\\': 'b', '*': 'A', '+': 'P', '-': 'M'}
     def encodechr(i):
         if i > 255:
             return 'u'
@@ -326,7 +327,8 @@  pypats = [
     (r'\.next\(\)', "don't use .next(), use next(...)"),
 
     # rules depending on implementation of repquote()
-    (r' x+[xpqo][\'"]\n\s+[\'"]x', 'string join across lines with no space'),
+    (r' x+[xpqo%APM][\'"]\n\s+[\'"]x',
+     'string join across lines with no space'),
     (r'ui\.(status|progress|write|note|warn)\([\'\"]x',
      "missing _() in ui message (use () to hide false-positives)"),
   ],
diff --git a/tests/test-contrib-check-code.t b/tests/test-contrib-check-code.t
--- a/tests/test-contrib-check-code.t
+++ b/tests/test-contrib-check-code.t
@@ -256,6 +256,10 @@  web templates
   >        'bar foo.'
   >        'bar foo:'
   >        'bar foo@'
+  >        'bar foo%'
+  >        'bar foo*'
+  >        'bar foo+'
+  >        'bar foo-'
   >        'bar')
   > EOF
   $ "$check_code" stringjoin.py
@@ -271,4 +275,16 @@  web templates
   stringjoin.py:4:
    >        'bar foo@'
    string join across lines with no space
+  stringjoin.py:5:
+   >        'bar foo%'
+   string join across lines with no space
+  stringjoin.py:6:
+   >        'bar foo*'
+   string join across lines with no space
+  stringjoin.py:7:
+   >        'bar foo+'
+   string join across lines with no space
+  stringjoin.py:8:
+   >        'bar foo-'
+   string join across lines with no space
   [1]