diff options
author | Kitzunu <24550914+Kitzunu@users.noreply.github.com> | 2025-02-03 21:03:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-03 21:03:21 +0100 |
commit | 5d9e45ab9b88d28fba366c8775f1770dc792e7c0 (patch) | |
tree | 621892a32fa18ad7d739c805d37f3bb725d89dfc /apps | |
parent | 2aaf28800d5c362fa9907815186b4df04361ad2f (diff) |
feat(CI/Codestyle): backtick check for sql (#21321)
Diffstat (limited to 'apps')
-rw-r--r-- | apps/codestyle/codestyle-sql.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/apps/codestyle/codestyle-sql.py b/apps/codestyle/codestyle-sql.py index bd51802e49..662f0962c8 100644 --- a/apps/codestyle/codestyle-sql.py +++ b/apps/codestyle/codestyle-sql.py @@ -15,8 +15,9 @@ results = { "Multiple blank lines check": "Passed", "Trailing whitespace check": "Passed", "SQL codestyle check": "Passed", - "INSERT safety usage check": "Passed", - "Missing semicolon check": "Passed" + "INSERT & DELETE safety usage check": "Passed", + "Missing semicolon check": "Passed", + "Backtick check": "Passed" } # Collect all files in all directories @@ -46,6 +47,7 @@ def parsing_file(files: list) -> None: sql_check(file, file_path) insert_delete_safety_check(file, file_path) semicolon_check(file, file_path) + backtick_check(file, file_path) except UnicodeDecodeError: print(f"\nCould not decode file {file_path}") sys.exit(1) @@ -200,6 +202,30 @@ def semicolon_check(file: io, file_path: str) -> None: error_handler = True results["Missing semicolon check"] = "Failed" +def backtick_check(file: io, file_path: str) -> None: + global error_handler, results + file.seek(0) + check_failed = False + pattern = re.compile( + r'\b(SELECT|FROM|JOIN|WHERE|GROUP BY|ORDER BY|DELETE FROM|UPDATE|INSERT INTO|SET)\s+([^;]+)', + re.IGNORECASE) + + for line_number, line in enumerate(file, start=1): + matches = pattern.findall(line) + for clause, content in matches: + words = re.findall(r'\b[a-zA-Z_][a-zA-Z0-9_]*\b', content) + for word in words: + if word.upper() in {"SELECT", "FROM", "JOIN", "WHERE", "GROUP", "BY", "ORDER", + "DELETE", "UPDATE", "INSERT", "INTO", "SET", "VALUES"}: + continue + if not re.search(rf'`{re.escape(word)}`', content): + print(f"Missing backticks around ({word}). {file_path} at line {line_number}") + check_failed = True + + if check_failed: + error_handler = True + results["Backtick check"] = "Failed" + # Collect all files from matching directories all_files = collect_files_from_directories(src_directory) |