feat(CI/Codestyle): check for braces after if/else statements

This commit is contained in:
Kitzunu
2024-12-19 20:31:30 +01:00
parent 288d70e58e
commit f340fc12cf

View File

@@ -214,6 +214,9 @@ def misc_codestyle_check(file: io, file_path: str) -> None:
global error_handler, results
file.seek(0) # Reset file pointer to the beginning
check_failed = False
# used to check for "if/else (...) {" "} else" ignores "if/else (...) {...}"
ifelsecurlyregex = r"^[^#define].*\s+(if|else)(\s*\(.*\))?\s*{[^}]*$|}\s*else(\s*{[^}]*$)"
# Parse all the file
for line_number, line in enumerate(file, start = 1):
if 'const auto&' in line:
@@ -228,6 +231,10 @@ def misc_codestyle_check(file: io, file_path: str) -> None:
print(
f"AC have as standard: if (XXXX). Please check spaces in your condition': {file_path} at line {line_number}")
check_failed = True
if re.match(ifelsecurlyregex, line):
print(
f"You are not allowed to have a curly bracket before or after an if/else statement, place them on a new line: {file_path} at line {line_number}")
check_failed = True
# Handle the script error and update the result output
if check_failed:
error_handler = True