Skip to content

Commit

Permalink
Merge branch 'master' into Playerbot
Browse files Browse the repository at this point in the history
  • Loading branch information
liyunfan1223 committed Feb 11, 2025
2 parents de3c2b5 + c070e4b commit 41415bb
Show file tree
Hide file tree
Showing 62 changed files with 1,440 additions and 1,877 deletions.
4 changes: 2 additions & 2 deletions apps/codestyle/codestyle-cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def misc_codestyle_check(file: io, file_path: str) -> None:
# used to check for "if/else (...) {" "} else" ignores "if/else (...) {...}" "#define ... if/else (...) {"
ifelse_curlyregex = r"^[^#define].*\s+(if|else)(\s*\(.*\))?\s*{[^}]*$|}\s*else(\s*{[^}]*$)"
# used to catch double semicolons ";;" ignores "(;;)"
double_semiregex = r"[^(];;[^)]"
double_semiregex = r"(?<!\()\s*;;(?!\))"
# used to catch tabs
tab_regex = r"\t"

Expand All @@ -245,7 +245,7 @@ def misc_codestyle_check(file: io, file_path: str) -> None:
print(
f"Curly brackets are not allowed to be leading or trailing if/else statements. Place it on a new line: {file_path} at line {line_number}")
check_failed = True
if re.match(double_semiregex, line):
if re.search(double_semiregex, line):
print(
f"Double semicolon (;;) found in {file_path} at line {line_number}")
check_failed = True
Expand Down
30 changes: 25 additions & 5 deletions apps/codestyle/codestyle-sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,38 @@ 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+([^;]+)',
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"'(?:\\'|[^'])*'|\"(?:\\\"|[^\"])*\"")

for line_number, line in enumerate(file, start=1):
matches = pattern.findall(line)
# Ignore comments
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",
"DELETE", "UPDATE", "INSERT", "INTO", "SET", "VALUES"}:
"DELETE", "UPDATE", "INSERT", "INTO", "SET", "VALUES", "AND",
"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
Expand Down
Loading

0 comments on commit 41415bb

Please sign in to comment.