From f340fc12cf3bd937a5b3e36794715ba5c4b5d794 Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Thu, 19 Dec 2024 20:31:30 +0100 Subject: [PATCH] feat(CI/Codestyle): check for braces after if/else statements --- apps/codestyle/codestyle.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/codestyle/codestyle.py b/apps/codestyle/codestyle.py index ea580f56b9..f6b3201f6c 100644 --- a/apps/codestyle/codestyle.py +++ b/apps/codestyle/codestyle.py @@ -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