addons/naming.py: some refactoring and write a comment that says how it is used

This commit is contained in:
Daniel Marjamäki 2015-07-28 14:50:30 +02:00
parent 0e82730ee4
commit 339fbd4be3
1 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,11 @@
#/usr/bin/python #/usr/bin/python
#
# cppcheck addon for naming conventions # cppcheck addon for naming conventions
#
# Example usage (variable name must start with lowercase, function name must start with uppercase):
# $ cppcheck --dump path-to-src/
# $ python addons/naming.py --var='[a-z].*' --function='[A-Z].*' path-to-src/*.dump
#
import cppcheckdata import cppcheckdata
import sys import sys
@ -27,7 +33,8 @@ for arg in sys.argv[1:]:
if not res: if not res:
reportError(var.typeStartToken, 'style', 'Variable ' + var.nameToken.str + ' violates naming convention') reportError(var.typeStartToken, 'style', 'Variable ' + var.nameToken.str + ' violates naming convention')
if RE_FUNCTIONNAME: if RE_FUNCTIONNAME:
for function in data.functions: for scope in data.scopes:
res = re.match(RE_FUNCTIONNAME, function.name) if scope.type == 'Function':
if not res: res = re.match(RE_FUNCTIONNAME, scope.className)
reportError(function.tokenDef, 'style', 'Function ' + function.name + ' violates naming convention') if not res:
reportError(scope.classStart, 'style', 'Function ' + scope.className + ' violates naming convention')