mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2025-11-29 17:38:24 +08:00
fix(CI/Codestyle): Backtick check SET, quote and REPLACE case (#21333)
This commit is contained in:
@@ -206,18 +206,27 @@ def backtick_check(file: io, file_path: str) -> None:
|
|||||||
global error_handler, results
|
global error_handler, results
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
check_failed = False
|
check_failed = False
|
||||||
|
|
||||||
|
# Find SQL clauses
|
||||||
pattern = re.compile(
|
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)
|
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):
|
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:
|
for clause, content in matches:
|
||||||
words = re.findall(r'\b[a-zA-Z_][a-zA-Z0-9_]*\b', content)
|
words = re.findall(r'\b[a-zA-Z_][a-zA-Z0-9_]*\b', content)
|
||||||
for word in words:
|
for word in words:
|
||||||
if word.upper() in {"SELECT", "FROM", "JOIN", "WHERE", "GROUP", "BY", "ORDER",
|
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
|
continue
|
||||||
|
|
||||||
if not re.search(rf'`{re.escape(word)}`', content):
|
if not re.search(rf'`{re.escape(word)}`', content):
|
||||||
print(f"Missing backticks around ({word}). {file_path} at line {line_number}")
|
print(f"Missing backticks around ({word}). {file_path} at line {line_number}")
|
||||||
check_failed = True
|
check_failed = True
|
||||||
|
|||||||
Reference in New Issue
Block a user