diff options
author | Kitzunu <24550914+Kitzunu@users.noreply.github.com> | 2025-02-08 11:34:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-08 11:34:38 +0100 |
commit | 31529db2828f99666481497b593307373f4c9ad9 (patch) | |
tree | c172aac2231a1af99602fc9df745dc488d50e476 /apps/codestyle | |
parent | b07e545baea581adb5f05bbc5717e8da63c35595 (diff) |
fix(CI/Codestyle): Final fixes to backtick check (#21361)
Diffstat (limited to 'apps/codestyle')
-rw-r--r-- | apps/codestyle/codestyle-sql.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/apps/codestyle/codestyle-sql.py b/apps/codestyle/codestyle-sql.py index 5f0b7b490d..79f13241f3 100644 --- a/apps/codestyle/codestyle-sql.py +++ b/apps/codestyle/codestyle-sql.py @@ -209,8 +209,10 @@ def backtick_check(file: io, file_path: str) -> None: # Find SQL clauses pattern = re.compile( - r'\b(SELECT|FROM|JOIN|WHERE|GROUP BY|ORDER BY|DELETE FROM|UPDATE|INSERT INTO|SET|REPLACE|REPLACE INTO)\s+([^;]+)', - re.IGNORECASE) + r'\b(SELECT|FROM|JOIN|WHERE|GROUP BY|ORDER BY|DELETE FROM|UPDATE|INSERT INTO|SET|REPLACE|REPLACE INTO)\s+(.*?)(?=;$|(?=\b(?:WHERE|SET|VALUES)\b)|$)', + re.IGNORECASE | re.DOTALL + ) + # Make sure to ignore values enclosed in single- and doublequotes quote_pattern = re.compile(r"'(?:\\'|[^'])*'|\"(?:\\\"|[^\"])*\"") @@ -219,17 +221,15 @@ def backtick_check(file: io, file_path: str) -> None: # Ignore comments if line.startswith('--'): continue - - # Ignore SET variables with multiple lines - if line.startswith('@'): - continue # Sanitize single- and doublequotes to prevent false positives 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) + # Find all words and exclude @variables + words = re.findall(r'\b(?<!@)([a-zA-Z_][a-zA-Z0-9_]*)\b', content) + for word in words: # Skip SQL keywords if word.upper() in {"SELECT", "FROM", "JOIN", "WHERE", "GROUP", "BY", "ORDER", @@ -237,6 +237,7 @@ def backtick_check(file: io, file_path: str) -> None: "IN", "OR", "REPLACE"}: continue + # Make sure the word is enclosed in backticks if not re.search(rf'`{re.escape(word)}`', content): print(f"Missing backticks around ({word}). {file_path} at line {line_number}") check_failed = True |