contrib/check-code.py
changeset 12364 e128fa4615f2
parent 11886 73112cb2a6d7
child 12366 c01dc9087d9a
equal deleted inserted replaced
12363:8a5b6383ba02 12364:e128fa4615f2
    66 ]
    66 ]
    67 
    67 
    68 testfilters = [
    68 testfilters = [
    69     (r"( *)(#([^\n]*\S)?)", repcomment),
    69     (r"( *)(#([^\n]*\S)?)", repcomment),
    70     (r"<<(\S+)((.|\n)*?\n\1)", rephere),
    70     (r"<<(\S+)((.|\n)*?\n\1)", rephere),
       
    71 ]
       
    72 
       
    73 uprefix = r"^  \$ "
       
    74 utestpats = [
       
    75     (uprefix + r'(true|exit 0)', "explicit zero exit unnecessary"),
       
    76     (uprefix + r'.*\$\?', "explicit exit code checks unnecessary"),
       
    77     (uprefix + r'.*\|\| echo.*(fail|error)',
       
    78      "explicit exit code checks unnecessary"),
       
    79     (uprefix + r'set -e', "don't use set -e"),
       
    80 ]
       
    81 
       
    82 for p, m in testpats:
       
    83     if p.startswith('^'):
       
    84         p = uprefix + p[1:]
       
    85     else:
       
    86         p = uprefix + p
       
    87     utestpats.append((p, m))
       
    88 
       
    89 utestfilters = [
       
    90     (r"( *)(#([^\n]*\S)?)", repcomment),
    71 ]
    91 ]
    72 
    92 
    73 pypats = [
    93 pypats = [
    74     (r'^\s*def\s*\w+\s*\(.*,\s*\(',
    94     (r'^\s*def\s*\w+\s*\(.*,\s*\(',
    75      "tuple parameter unpacking not available in Python 3+"),
    95      "tuple parameter unpacking not available in Python 3+"),
   155 
   175 
   156 checks = [
   176 checks = [
   157     ('python', r'.*\.(py|cgi)$', pyfilters, pypats),
   177     ('python', r'.*\.(py|cgi)$', pyfilters, pypats),
   158     ('test script', r'(.*/)?test-[^.~]*$', testfilters, testpats),
   178     ('test script', r'(.*/)?test-[^.~]*$', testfilters, testpats),
   159     ('c', r'.*\.c$', cfilters, cpats),
   179     ('c', r'.*\.c$', cfilters, cpats),
       
   180     ('unified test', r'.*\.t$', utestfilters, utestpats),
   160 ]
   181 ]
   161 
   182 
   162 class norepeatlogger(object):
   183 class norepeatlogger(object):
   163     def __init__(self):
   184     def __init__(self):
   164         self._lastseen = None
   185         self._lastseen = None