fix(CI/Codestyle): Final fixes to backtick check (#21361)

This commit is contained in:
Kitzunu 2025-02-08 11:34:38 +01:00 committed by GitHub
parent b07e545bae
commit 31529db282
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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