Browse Source

Add --dump-vim-command option for code policy

Also exclude a few debug log macro call sites which are incorrectly
reported as problems.
v1.0-maintenance
Sami Vaarala 10 years ago
parent
commit
ff3db386e7
  1. 23
      util/check_code_policy.py

23
util/check_code_policy.py

@ -20,6 +20,7 @@
import os import os
import sys import sys
import re import re
import optparse
class Problem: class Problem:
filename = None filename = None
@ -59,6 +60,14 @@ def checkDebugLogCalls(line):
if log_wrapper + '(' in line: if log_wrapper + '(' in line:
return return
# exclude '#define DUK_DPRINT...' macros in duk_debug.h
if len(line) >= 1 and line[0] == '#':
return
# exclude a few comment lines in duk_debug.h
if len(line) >= 3 and line[0:3] == ' * ':
return
raise Exception('invalid debug log call form') raise Exception('invalid debug log call form')
def checkTrailingWhitespace(line): def checkTrailingWhitespace(line):
@ -110,6 +119,10 @@ def processFile(filename, checkers):
f.close() f.close()
def main(): def main():
parser = optparse.OptionParser()
parser.add_option('--dump-vim-commands', dest='dump_vim_commands', default=False, help='Dump oneline vim command')
(opts, args) = parser.parse_args()
checkers = [] checkers = []
checkers.append(checkDebugLogCalls) checkers.append(checkDebugLogCalls)
checkers.append(checkTrailingWhitespace) checkers.append(checkTrailingWhitespace)
@ -117,7 +130,7 @@ def main():
checkers.append(checkMixedIndent) checkers.append(checkMixedIndent)
checkers.append(checkFixme) checkers.append(checkFixme)
for filename in sys.argv[1:]: for filename in args:
processFile(filename, checkers) processFile(filename, checkers)
if len(problems) > 0: if len(problems) > 0:
@ -132,6 +145,14 @@ def main():
print(tmp) print(tmp)
print '*** Total: %d problems' % len(problems) print '*** Total: %d problems' % len(problems)
if opts.dump_vim_commands:
cmds = []
for i in problems:
cmds.append('vim +' + str(i.linenumber) + ' "' + i.filename + '"')
print ''
print('; '.join(cmds))
sys.exit(1) sys.exit(1)
sys.exit(0) sys.exit(0)

Loading…
Cancel
Save