addons/namingng.py: allow function/variable name test without prefixes (#5801)

This patch allows a config file to have RE_VARNAME and RE_FUNCTIONNAME
without the corresponding var_prefixes and function_prefixes keys. The
namingng.py processing function would otherwise raise an exception
trying to get these keys, while they are not strictly necessary, if no
prefixes are required.
This commit is contained in:
thingsconnected 2023-12-23 22:33:36 +01:00 committed by GitHub
parent 9118d330d3
commit d506e7e937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -132,7 +132,7 @@ def process(dumpfiles, configfile, debugprint=False):
if conf["skip_one_char_variables"] and len(var.nameToken.str) == 1: if conf["skip_one_char_variables"] and len(var.nameToken.str) == 1:
continue continue
if varType in conf["var_prefixes"]: if varType in conf.get("var_prefixes",{}):
if not var.nameToken.str.startswith(conf["var_prefixes"][varType]): if not var.nameToken.str.startswith(conf["var_prefixes"][varType]):
errors.append(reportError( errors.append(reportError(
var.typeStartToken.file, var.typeStartToken.file,
@ -192,7 +192,7 @@ def process(dumpfiles, configfile, debugprint=False):
if debugprint: if debugprint:
print("\t:: {} {}".format(retval, token.function.name)) print("\t:: {} {}".format(retval, token.function.name))
if retval and retval in conf["function_prefixes"]: if retval and retval in conf.get("function_prefixes",{}):
if not token.function.name.startswith(conf["function_prefixes"][retval]): if not token.function.name.startswith(conf["function_prefixes"][retval]):
errors.append(reportError( errors.append(reportError(
token.file, token.linenr, 'style', 'Function ' + token.function.name + ' violates naming convention')) token.file, token.linenr, 'style', 'Function ' + token.function.name + ' violates naming convention'))