Patchwork [1,of,3,STABLE] i18n: fix "% inside _()" problems

login
register
mail settings
Submitter Katsunori FUJIWARA
Date April 13, 2014, 1:32 p.m.
Message ID <6c252c9898beaedcf323.1397395937@feefifofum>
Download mbox | patch
Permalink /patch/4314/
State Superseded
Headers show

Comments

Katsunori FUJIWARA - April 13, 2014, 1:32 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1397394948 -32400
#      Sun Apr 13 22:15:48 2014 +0900
# Branch stable
# Node ID 6c252c9898beaedcf3230741445310b0071e5cb4
# Parent  469d949a7cb8d20e0fee7464c3b12dcac1e55d4c
i18n: fix "% inside _()" problems

Before this patch, "contrib/check-code.py" can't detect these
problems, because the regexp pattern to detect "% inside _()" doesn't
suppose the case that there are white-space characters between the
left parenthesis of "_()" and the format string.

This patch adds regexp pattern "[ \t\n]*" to match against such
white-space characters.

"[\s\n]" can't be used in this purpose, because "\s" is automatically
replaced with "[ \t]" by "_preparepats()" and "\s" in "[]" causes
nested "[]" unexpectedly.
Pierre-Yves David - April 14, 2014, 2:11 p.m.
On 04/13/2014 09:32 AM, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1397394948 -32400
> #      Sun Apr 13 22:15:48 2014 +0900
> # Branch stable
> # Node ID 6c252c9898beaedcf3230741445310b0071e5cb4
> # Parent  469d949a7cb8d20e0fee7464c3b12dcac1e55d4c
> i18n: fix "% inside _()" problems

I started to reviewing this series, but my brain started digging an 
escape tunnel in the back of my head.

Here are a few things that would prevent brain melt down when reading it:

1. split the actual fix in core from the checkcode addition: The flow 
would be:

   a. Fixing this silly issue easy to understand
   b. Adding a new brain melting regexp to catch it
   c. Fixing another silly issue
   d. Another crazy regexp
   e. Fixing a third silly issue
   f. Introduce the mother of all regexp

2. includes examples of undetected bad behavior. Typical message I would 
expect:

   check-code: detect blablabla when % are aligned with pluto and alpha 
centaury

   This changeset add regexp to catch these errors:

     _("lks;kgfd;lksgklds" % ";ldfklgskgf;lkds")
     _("lks;kgfd;lksgklds" % (";ldfklgskgf;lkds", 56))


   New need to add this insane regexp because the previous crazy regexp 
did not take in accout … (rest of the brain melting explanation)


3. add a corresponding test when adding the check code rules (missing in 
patches 1)

Those patch are however much welcome. Looking forward to challenge my 
mind again with V2)

Patch

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -198,8 +198,8 @@ 
     (r'\s<>\s', '<> operator is not available in Python 3+, use !='),
     (r'^\s*\t', "don't use tabs"),
     (r'\S;\s*\n', "semicolon"),
-    (r'[^_]_\((?:"[^"]+"[ \t\n+]*)+%', "don't use % inside _()"),
-    (r"[^_]_\((?:'[^']+'[ \t\n+]*)+%", "don't use % inside _()"),
+    (r'[^_]_\([ \t\n]*(?:"[^"]+"[ \t\n+]*)+%', "don't use % inside _()"),
+    (r"[^_]_\([ \t\n]*(?:'[^']+'[ \t\n+]*)+%", "don't use % inside _()"),
     (r'(\w|\)),\w', "missing whitespace after ,"),
     (r'(\w|\))[+/*\-<>]\w', "missing whitespace in expression"),
     (r'^\s+(\w|\.)+=\w[^,()\n]*$', "missing whitespace in assignment"),
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -760,8 +760,8 @@ 
         d = hg.defaultdest(source)
     if opts.get('all_largefiles') and not hg.islocal(d):
             raise util.Abort(_(
-            '--all-largefiles is incompatible with non-local destination %s' %
-            d))
+            '--all-largefiles is incompatible with non-local destination %s') %
+            d)
 
     return orig(ui, source, dest, **opts)