diff options
author | Kitzunu <24550914+Kitzunu@users.noreply.github.com> | 2025-02-05 17:25:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-05 17:25:34 +0100 |
commit | f46fea0ac98eb098102641c3f9e6654a840d2a25 (patch) | |
tree | 60171c65f966c995af41fb3c9013dac663512328 | |
parent | 34bed0651abd8ad1ba18f2721edff2fd2253d76e (diff) |
fix(CI/Codestyle): Backtick check SET, quote and REPLACE case (#21333)
-rw-r--r-- | apps/codestyle/codestyle-sql.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/apps/codestyle/codestyle-sql.py b/apps/codestyle/codestyle-sql.py index 662f0962c8..1bb98e037b 100644 --- a/apps/codestyle/codestyle-sql.py +++ b/apps/codestyle/codestyle-sql.py @@ -206,18 +206,27 @@ def backtick_check(file: io, file_path: str) -> None: global error_handler, results file.seek(0) check_failed = False + + # Find SQL clauses pattern = re.compile( - r'\b(SELECT|FROM|JOIN|WHERE|GROUP BY|ORDER BY|DELETE FROM|UPDATE|INSERT INTO|SET)\s+([^;]+)', + r'\b(SELECT|FROM|JOIN|WHERE|GROUP BY|ORDER BY|DELETE FROM|UPDATE|INSERT INTO|SET|REPLACE|REPLACE INTO)\s+([^;]+)', re.IGNORECASE) + # Make sure to ignore values enclosed in single- and doublequotes + quote_pattern = re.compile(r"'(?:\\'|[^'])*'|\"(?:\\\"|[^\"])*\"") + for line_number, line in enumerate(file, start=1): - matches = pattern.findall(line) + sanitized_line = quote_pattern.sub('', line) + matches = pattern.findall(sanitized_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"}: + "DELETE", "UPDATE", "INSERT", "INTO", "SET", "VALUES", "AND", + "IN", "OR", "REPLACE"}: 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 |