From ff3db386e7c296e99bd1ec83ae0cb668634c2126 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Sat, 13 Sep 2014 00:40:21 +0300 Subject: [PATCH] Add --dump-vim-command option for code policy Also exclude a few debug log macro call sites which are incorrectly reported as problems. --- util/check_code_policy.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/util/check_code_policy.py b/util/check_code_policy.py index 49e8c3a8..2a66f0a4 100644 --- a/util/check_code_policy.py +++ b/util/check_code_policy.py @@ -20,6 +20,7 @@ import os import sys import re +import optparse class Problem: filename = None @@ -59,6 +60,14 @@ def checkDebugLogCalls(line): if log_wrapper + '(' in line: 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') def checkTrailingWhitespace(line): @@ -110,6 +119,10 @@ def processFile(filename, checkers): f.close() 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.append(checkDebugLogCalls) checkers.append(checkTrailingWhitespace) @@ -117,7 +130,7 @@ def main(): checkers.append(checkMixedIndent) checkers.append(checkFixme) - for filename in sys.argv[1:]: + for filename in args: processFile(filename, checkers) if len(problems) > 0: @@ -132,6 +145,14 @@ def main(): print(tmp) 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(0)