Patchwork [2,of,2,STABLE] check-code: detect (maybe) complicated processing inside "_()"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Jan. 28, 2015, 1:29 p.m.
Message ID <7ec60cf08e322ccd3f5a.1422451787@juju>
Download mbox | patch
Permalink /patch/7569/
State Deferred
Headers show

Comments

Katsunori FUJIWARA - Jan. 28, 2015, 1:29 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1422451379 -32400
#      Wed Jan 28 22:22:59 2015 +0900
# Branch stable
# Node ID 7ec60cf08e322ccd3f5ac17a8d443ff020d07407
# Parent  3da525e1db16adbc32734aa86a20cc7254724eb3
check-code: detect (maybe) complicated processing inside "_()"

This patch can detect problematic "_()" usages like one fixed by
previous patch.

For simplicity, this patch focuses only on the 1st element inside
"_()". It should be a string (starting with single-/double-quotation)
or a symbol (for referring variable or invoking function).
Sean Farley - Jan. 28, 2015, 6:09 p.m.
FUJIWARA Katsunori writes:

> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1422451379 -32400
> #      Wed Jan 28 22:22:59 2015 +0900
> # Branch stable
> # Node ID 7ec60cf08e322ccd3f5ac17a8d443ff020d07407
> # Parent  3da525e1db16adbc32734aa86a20cc7254724eb3
> check-code: detect (maybe) complicated processing inside "_()"
>
> This patch can detect problematic "_()" usages like one fixed by
> previous patch.
>
> For simplicity, this patch focuses only on the 1st element inside
> "_()". It should be a string (starting with single-/double-quotation)
> or a symbol (for referring variable or invoking function).

These patches look good to me, for what it's worth. Thanks for fixing
this!
Matt Mackall - Jan. 28, 2015, 8:41 p.m.
On Wed, 2015-01-28 at 22:29 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1422451379 -32400
> #      Wed Jan 28 22:22:59 2015 +0900
> # Branch stable
> # Node ID 7ec60cf08e322ccd3f5ac17a8d443ff020d07407
> # Parent  3da525e1db16adbc32734aa86a20cc7254724eb3
> check-code: detect (maybe) complicated processing inside "_()"

I like this idea, but we should probably expand it to complain about
anything that's not a bare string. Let's revisit after the freeze.

Patch

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -211,6 +211,8 @@  pypats = [
     (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]*[^"\'\w \t\n]',
+     "don't put complicated expression 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 ,"),