addons/naming.py: Allow regular expression for private member variable names

This commit is contained in:
Daniel Marjamäki 2018-06-17 14:46:59 +02:00
parent fa8911a7d2
commit 2f23757c74
2 changed files with 14 additions and 0 deletions

View File

@ -359,6 +359,7 @@ class Variable:
nameToken name token in variable declaration
typeStartToken start token of variable declaration
typeEndToken end token of variable declaration
access Global/Local/Namespace/Public/Protected/Public/Throw/Argument
isArgument Is this variable a function argument?
isArray Is this variable an array?
isClass Is this variable a class or struct?
@ -378,6 +379,7 @@ class Variable:
typeStartToken = None
typeEndTokenId = None
typeEndToken = None
access = None
isArgument = False
isArray = False
isClass = False
@ -397,6 +399,7 @@ class Variable:
self.typeStartToken = None
self.typeEndTokenId = element.get('typeEndToken')
self.typeEndToken = None
self.access = element.get('access')
self.isArgument = element.get('isArgument') == 'true'
self.isArray = element.get('isArray') == 'true'
self.isClass = element.get('isClass') == 'true'

View File

@ -12,10 +12,13 @@ import sys
import re
RE_VARNAME = None
RE_PRIVATE_MEMBER_VARIABLE = None
RE_FUNCTIONNAME = None
for arg in sys.argv[1:]:
if arg[:6] == '--var=':
RE_VARNAME = arg[6:]
elif arg.startswith('--private-member-variable='):
RE_PRIVATE_MEMBER_VARIABLE = arg[arg.find('=')+1:]
elif arg[:11] == '--function=':
RE_FUNCTIONNAME = arg[11:]
@ -38,6 +41,14 @@ for arg in sys.argv[1:]:
if not res:
reportError(var.typeStartToken, 'style', 'Variable ' +
var.nameToken.str + ' violates naming convention')
if RE_PRIVATE_MEMBER_VARIABLE:
for var in cfg.variables:
if (var.access is None) or var.access != 'Private':
continue
res = re.match(RE_PRIVATE_MEMBER_VARIABLE, var.nameToken.str)
if not res:
reportError(var.typeStartToken, 'style', 'Private member variable ' +
var.nameToken.str + ' violates naming convention')
if RE_FUNCTIONNAME:
for scope in cfg.scopes:
if scope.type == 'Function':