summaryrefslogtreecommitdiff
path: root/apps/codestyle/codestyle-sql.py
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codestyle/codestyle-sql.py')
-rw-r--r--apps/codestyle/codestyle-sql.py44
1 files changed, 36 insertions, 8 deletions
diff --git a/apps/codestyle/codestyle-sql.py b/apps/codestyle/codestyle-sql.py
index 840be49045..d93646d091 100644
--- a/apps/codestyle/codestyle-sql.py
+++ b/apps/codestyle/codestyle-sql.py
@@ -15,6 +15,7 @@ results = {
"Multiple blank lines check": "Passed",
"Trailing whitespace check": "Passed",
"SQL codestyle check": "Passed",
+ "Missing semicolon check": "Passed"
}
# Collect all files in all directories
@@ -42,6 +43,7 @@ def parsing_file(files: list) -> None:
multiple_blank_lines_check(file, file_path)
trailing_whitespace_check(file, file_path)
sql_check(file, file_path)
+ semicolon_check(file, file_path)
except UnicodeDecodeError:
print(f"\nCould not decode file {file_path}")
sys.exit(1)
@@ -114,14 +116,6 @@ def sql_check(file: io, file_path: str) -> None:
print(
f"Tab found! Replace it to 4 spaces: {file_path} at line {line_number}")
check_failed = True
-
- # Ignore comments (remove content after --)
- line_without_comment = re.sub(r'--.*', '', line).strip()
- # Check if the last non-empty line ends with a semicolon
- if not line_without_comment.endswith(';'):
- print(
- f"The last non-empty line does not end with a semicolon: {file_path}")
- check_failed = True
last_line = line[-1].strip()
if last_line:
@@ -134,6 +128,40 @@ def sql_check(file: io, file_path: str) -> None:
error_handler = True
results["SQL codestyle check"] = "Failed"
+def semicolon_check(file: io, file_path: str) -> None:
+ global error_handler, results
+ file.seek(0) # Reset file pointer to the beginning
+ check_failed = False
+ sql_keywords = ["SELECT", "INSERT", "UPDATE", "DELETE"]
+ query_open = False
+
+ lines = file.readlines()
+ total_lines = len(lines)
+
+ for line_number, line in enumerate(lines, start=1):
+ stripped_line = line.rstrip() # Remove trailing whitespace including newline
+
+ # Check if one keyword is in the line
+ if not query_open and any(keyword in stripped_line for keyword in sql_keywords):
+ query_open = True
+
+ if query_open:
+ if stripped_line == '':
+ print(f"Missing semicolon in {file_path} at line {line_number - 1}")
+ check_failed = True
+ query_open = False
+ elif line_number == total_lines:
+ if not stripped_line.endswith(';'):
+ print(f"Missing semicolon in {file_path} at the last line {line_number}")
+ check_failed = True
+ query_open = False
+ elif stripped_line.endswith(';'):
+ query_open = False
+
+ if check_failed:
+ error_handler = True
+ results["Missing semicolon check"] = "Failed"
+
# Collect all files from matching directories
all_files = collect_files_from_directories(src_directory)