ndk check 工具上门禁

Signed-off-by: jwx1102601 <jiangqianjin@huawei.com>
This commit is contained in:
jwx1102601 2023-12-15 15:04:08 +08:00
parent 3f55556eb8
commit 6efe9550ef
3 changed files with 80 additions and 57 deletions

View File

@ -80,9 +80,7 @@ def result_to_json(check_result):
return json.dumps(txt_resul, default=lambda obj: obj.__dict__, indent=4)
def curr_entry(pr_id):
file_path = os.path.abspath(os.path.join(os.getcwd(), f'..{os.sep}..{os.sep}all_files.txt'))
file_list = get_md_files(file_path)
def curr_entry(file_list):
check_result_list = get_check_result_list(file_list)
write_in_txt(check_result_list, r'./Error.txt')
@ -97,13 +95,3 @@ def get_check_result_list(file_list):
check_result_list.extend(check_syntax(file))
return check_result_list
def get_md_files(url):
file = open(url, "r")
file_list = []
line = file.readline()
while line:
file_list.append(line.splitlines()[0])
line = file.readline()
file.close()
return file_list

View File

@ -32,7 +32,7 @@ def check_function_name(api_info):
return api_result_info_list
else:
api_result_info = ApiResultInfo(ErrorType.NAMING_ERRORS.value,
ErrorMessage[api_info['kind']].value, name)
ErrorMessage[api_info['kind']].value.replace('$$', name), name)
api_result_info.set_location_line(api_info['location']['location_line'])
api_result_info.set_location_column(api_info['location']['location_column'])
api_result_info.set_location(api_info['location']['location_path'])
@ -43,6 +43,14 @@ def check_function_name(api_info):
return api_result_info_list
def check_variable_name(api_info):
is_const = api_info['is_const']
if is_const:
return processing_check_data('ALL_UPPERCASE_HUMP', api_info)
else:
return processing_check_data('SMALL_HUMP', api_info)
def check_small_hump(api_info):
return processing_check_data('SMALL_HUMP', api_info)
@ -60,7 +68,7 @@ def check_file_name(file_path):
file_name = os.path.basename(file_path)
result = re.match(CheckName['FILE_NAME'].value, file_name)
if result is None:
error_info = ErrorMessage.TRANSLATION_UNIT.value
error_info = ErrorMessage.TRANSLATION_UNIT.value.replace('$$', file_name)
api_result_info = ApiResultInfo(ErrorType.NAMING_ERRORS.value, error_info, '')
api_result_info.set_type(LogType.LOG_FILE.value)
api_result_info.set_file_name(file_path)
@ -76,7 +84,7 @@ def processing_check_data(function_type, api_info):
result = re.match(CheckName[function_type].value, name)
if result is None:
api_result_info = ApiResultInfo(ErrorType.NAMING_ERRORS.value,
ErrorMessage[api_info['kind']].value, name)
ErrorMessage[api_info['kind']].value.replace('$$', name), name)
api_result_info.set_location_line(api_info['location']['location_line'])
api_result_info.set_location_column(api_info['location']['location_column'])
api_result_info.set_location(api_info['location']['location_path'])
@ -90,7 +98,7 @@ def processing_check_data(function_type, api_info):
class CheckName(enum.Enum):
LARGE_HUMP = r'^([A-Z][a-z0-9]*)*([\_]([A-Z][a-z0-9]*)*)*$'
SMALL_HUMP = r'^([a-z][A-Z0-9]*)*([\_]([a-z][A-Z0-9]*)*)*$'
ALL_UPPERCASE_HUMP = r'^[A-Z]+[0-9]*([\_][A-Z0-9]+)*$'
ALL_UPPERCASE_HUMP = r'^[A-Z]+[0-9]*([\_][A-Z0-9]*)*$'
GLOBAL_VARIABLE = r'^g_([a-z][A-Z0-9]*)*$'
FILE_NAME = r'^[a-z]+[a-z0-9]+([\_][a-z0-9]+)*\.h$'
@ -100,7 +108,7 @@ process_tag_function = {
'STRUCT_DECL': check_large_hump,
'ENUM_DECL': check_large_hump,
'UNION_DECL': check_large_hump,
'VAR_DECL': check_small_hump,
'VAR_DECL': check_variable_name,
'PARM_DECL': check_small_hump,
'FIELD_DECL': check_small_hump,
'MACRO_DEFINITION': check_all_uppercase_hump,

View File

@ -32,42 +32,70 @@ class TAGS(enum.Enum):
class ErrorType(enum.Enum):
DEFAULT = {
'id': -1,
'description': '',
UNKNOW_DECORATOR: {
id: 0,
'description': 'unknow decorator',
}
EMPTY_TAG = {
'id': 0,
'description': "miss tag value",
}
ERROR_TAG = {
'id': 1,
'description': 'error tag name',
}
MISSPELL_WORDS = {
'id': 1,
MISSPELL_WORDS: {
id: 1,
'description': 'misspell words',
}
NAMING_ERRORS = {
'id': 2,
NAMING_ERRORS: {
id: 2,
'description': 'naming errors',
}
SYNTAX_ERRORS = {
'id': 3,
'description': 'syntax errors',
UNKNOW_PERMISSION: {
id: 3,
'description': 'unknow permission',
}
UNKNOW_DEPRECATED = {
'id': 5,
UNKNOW_SYSCAP: {
id: 4,
'description': 'unknow syscap',
}
UNKNOW_DEPRECATED: {
id: 5,
'description': 'unknow deprecated',
}
WRONG_VALUE = {
'id': 7,
WRONG_ORDER: {
id: 6,
'description': 'wrong order',
}
WRONG_VALUE: {
id: 7,
'description': 'wrong value',
}
WRONG_SCENE = {
'id': 8,
WRONG_SCENE: {
id: 8,
'description': 'wrong scene',
}
PARAMETER_ERRORS: {
id: 9,
'description': 'wrong parameter',
}
API_PAIR_ERRORS: {
id: 10,
'description': 'limited api pair errors',
}
ILLEGAL_ANY: {
id: 11,
'description': 'illegal any',
}
API_CHANGE_ERRORS: {
id: 12,
'description': 'api change errors',
}
EMPTY_TAG: {
id: 13,
'description': 'miss tag value',
}
ERROR_TAG: {
id: 14,
'description': 'error tag name',
}
SYNTAX_ERRORS: {
id: 15,
'description': 'syntax errors',
}
class LogType(enum.Enum):
@ -105,23 +133,22 @@ class ErrorMessage(enum.Enum):
be reused please delete the extra tags.'
ERROR_FILE_HAS_ONE_LOSE_OTHER = 'the file has the $$, but do not has the $$.'
ERROR_FILE_LOSE_ONE = 'the file missing $$'
FUNCTION_DECL = 'Function naming should use the big hump naming style or beginning with OH/OS,and \
FUNCTION_DECL = 'This name [$$] should use the big hump naming style or beginning with OH/OS,and \
using "_" segmentation.'
STRUCT_DECL = 'Structure type naming should use the big hump naming style.'
ENUM_DECL = 'Enum type naming should use the big hump naming style.'
UNION_DECL = 'Consortium type naming should use the big hump naming style.'
VAR_DECL = 'Variable naming should use the small hump naming style.'
PARM_DECL = 'Function parameters naming should use the small hump naming style.'
MACRO_PARAMETERS_TYPE_NAMING_ERROR = 'Macro parameters naming should use the small hump naming style.'
FIELD_DECL = 'Fields in the structure naming should use the small hump naming style.'
MEMBERS_OF_THE_CONSORTIUM_TYPE_NAMING_ERROR = 'Members of the consortium naming should use the \
small hump naming style.'
MACRO_DEFINITION = 'Macro naming should use all uppercase, separated by underscores naming style.'
ENUM_CONSTANT_DECL = 'Enum value naming should use all uppercase, separated by underscores naming style.'
GOTO_LABEL_TYPE_NAMING_ERROR = 'Goto label value naming should use all uppercase, separated by \
STRUCT_DECL = 'This name [$$] should use the big hump naming style.'
ENUM_DECL = 'This name [$$] should use the big hump naming style.'
UNION_DECL = 'This name [$$] should use the big hump naming style.'
VAR_DECL = 'This name [$$] should use the small hump naming style.'
PARM_DECL = 'This name [$$] should use the small hump naming style.'
MACRO_PARAMETERS_TYPE_NAMING_ERROR = 'This name [$$] should use the small hump naming style.'
FIELD_DECL = 'This name [$$] should use the small hump naming style.'
MEMBERS_OF_THE_CONSORTIUM_TYPE_NAMING_ERROR = 'This name [$$] should use the small hump naming style.'
MACRO_DEFINITION = 'This name [$$] should use all uppercase, separated by underscores naming style.'
ENUM_CONSTANT_DECL = 'This name [$$] should use all uppercase, separated by underscores naming style.'
GOTO_LABEL_TYPE_NAMING_ERROR = 'This name [$$] should use all uppercase, separated by \
underscores naming style.'
GLOBAL_VARIABLE_TYPE_NAMING_ERROR = 'Global variable should increase "g_" prefix.'
TRANSLATION_UNIT = 'File naming should be all lowercase, separated by underscores.'
GLOBAL_VARIABLE_TYPE_NAMING_ERROR = 'This name [$$] should increase "g_" prefix.'
TRANSLATION_UNIT = 'This name [$$] should be all lowercase, separated by underscores.'
class OutputTxt: