From 8b8d898b9670b2667e68d21918c54c74fc7dbd6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 28 Jul 2015 14:20:38 +0200 Subject: [PATCH] Addons/naming.py: verify variable/function names against regular expressions --- addons/naming.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 addons/naming.py diff --git a/addons/naming.py b/addons/naming.py new file mode 100644 index 000000000..fd94aeeb6 --- /dev/null +++ b/addons/naming.py @@ -0,0 +1,33 @@ +#/usr/bin/python +# cppcheck addon for naming conventions + +import cppcheckdata +import sys +import re + +RE_VARNAME = None +RE_FUNCTIONNAME = None +for arg in sys.argv[1:]: + if arg[:6]=='--var=': + RE_VARNAME = arg[6:] + elif arg[:11]=='--function=': + RE_FUNCTIONNAME = arg[11:] + +def reportError(token, severity, msg): + sys.stderr.write('[' + token.file + ':' + str(token.linenr) + '] (' + severity + ') ' + msg + '\n') + +for arg in sys.argv[1:]: + if not arg[-5:]=='.dump': + continue + print('Checking ' + arg + '...') + data = cppcheckdata.parsedump(arg) + if RE_VARNAME: + for var in data.variables: + res = re.match(RE_VARNAME, var.nameToken.str) + if not res: + reportError(var.typeStartToken, 'style', 'Variable ' + var.nameToken.str + ' violates naming convention') + if RE_FUNCTIONNAME: + for function in data.functions: + res = re.match(RE_FUNCTIONNAME, function.name) + if not res: + reportError(var.typeStartToken, 'style', 'Function ' + function.name + ' violates naming convention')