diff contrib/check-code.py @ 21097:e8ef59b351c3

check-code: detect "% inside _()" when there are leading whitespaces Before this patch, "contrib/check-code.py" can't detect "% inside _()" correctly, when there are leading whitespaces before the format string, like below: _( "format string %s" % v) This patch adds regexp pattern "[ \t\n]*" before the pattern matching against the format string. "[\s\n]" can't be used in this purpose, because "\s" is automatically replaced with "[ \t]" by "_preparepats()" and "\s" in "[]" causes nested "[]" unexpectedly.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Wed, 16 Apr 2014 03:05:00 +0900
parents 6500a2eebee8
children 4840abc83970
line wrap: on
line diff
--- a/contrib/check-code.py	Wed Apr 16 03:05:00 2014 +0900
+++ b/contrib/check-code.py	Wed Apr 16 03:05:00 2014 +0900
@@ -207,8 +207,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"),