fix(CI/Codestyle): Final fixes to backtick check (#21361)
This commit is contained in:
parent
b07e545bae
commit
31529db282
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user