contrib/check-code.py
changeset 10722 c4fb2103e734
parent 10720 fbcccf9ec58f
child 10723 8ea152e94484
equal deleted inserted replaced
10721:67ba66070aee 10722:c4fb2103e734
     8 # GNU General Public License version 2 or any later version.
     8 # GNU General Public License version 2 or any later version.
     9 
     9 
    10 import sys, re, glob
    10 import sys, re, glob
    11 
    11 
    12 def repquote(m):
    12 def repquote(m):
    13     t = re.sub(r"\w", "x", m.group(2))
    13     t = re.sub(r"\w", "x", m.group('text'))
    14     t = re.sub(r"[^\sx]", "o", t)
    14     t = re.sub(r"[^\sx]", "o", t)
    15     return m.group(1) + t + m.group(1)
    15     return m.group('quote') + t + m.group('quote')
    16 
    16 
    17 def repcomment(m):
    17 def repcomment(m):
    18     return m.group(1) + "#" * len(m.group(2))
    18     return m.group(1) + "#" * len(m.group(2))
    19 
    19 
    20 def repccomment(m):
    20 def repccomment(m):
    94     (r'raise Exception', "don't raise generic exceptions"),
    94     (r'raise Exception', "don't raise generic exceptions"),
    95     (r'ui\.(status|progress|write|note)\([\'\"]x', "unwrapped ui message"),
    95     (r'ui\.(status|progress|write|note)\([\'\"]x', "unwrapped ui message"),
    96 ]
    96 ]
    97 
    97 
    98 pyfilters = [
    98 pyfilters = [
    99     (r'''(?<!")(")(([^"\n]|\\")+)"(?!")''', repquote),
    99     (r"""(?msx)(?P<quote>('''|\"\"\"|(?<!')'(?!')|(?<!")"(?!")))
   100     (r"""(?<!')(')(([^'\n]|\\')+)'(?!')""", repquote),
   100          (?P<text>(.*?))
   101     (r"""(''')(([^']|\\'|'{1,2}(?!'))*)'''""", repquote),
   101          (?<!\\)(?P=quote)""", repquote),
   102     (r'''(""")(([^"]|\\"|"{1,2}(?!"))*)"""''', repquote),
       
   103     (r"( *)(#([^\n]*\S)?)", repcomment),
   102     (r"( *)(#([^\n]*\S)?)", repcomment),
   104 ]
   103 ]
   105 
   104 
   106 cpats = [
   105 cpats = [
   107     (r'//', "don't use //-style comments"),
   106     (r'//', "don't use //-style comments"),
   121     (r'[^\n]\Z', "no trailing newline"),
   120     (r'[^\n]\Z', "no trailing newline"),
   122 ]
   121 ]
   123 
   122 
   124 cfilters = [
   123 cfilters = [
   125     (r'(/\*)(((\*(?!/))|[^*])*)\*/', repccomment),
   124     (r'(/\*)(((\*(?!/))|[^*])*)\*/', repccomment),
   126     (r'''(?<!")(")(([^"]|\\")+"(?!"))''', repquote),
   125     (r'''(?P<quote>(?<!")")(?P<text>([^"]|\\")+)"(?!")''', repquote),
   127     (r'''(#\s*include\s+<)([^>]+)>''', repinclude),
   126     (r'''(#\s*include\s+<)([^>]+)>''', repinclude),
   128     (r'(\()([^)]+\))', repcallspaces),
   127     (r'(\()([^)]+\))', repcallspaces),
   129 ]
   128 ]
   130 
   129 
   131 checks = [
   130 checks = [