This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckCode.py
63 lines (56 loc) · 2.3 KB
/
CheckCode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import sys
import json
import re
# Set standard variables
BACKEND = "./backend"
FRONTEND = "./frontend"
IgnoreDir: list = [".git", "node_modules"]
IgnoreFile: list = ["README.md", "config.json", ".env"]
IgnoreExtension = (".jar", ".py", ".md", ".db", ".json", ".js")
Errors = []
# Get arguments
args = sys.argv
# Remove first since it doesn't matter
del args[0]
#print(args)
def DoBackEnd():
for subdir, dirs, files in os.walk(BACKEND):
for file in files:
# Ignore dirs we don't want to modify
if not any(ext in subdir for ext in IgnoreDir):
# Ignore files we don't want to modify
if not any(ext in file for ext in IgnoreFile) and not file.endswith(IgnoreExtension):
dir = os.path.join(subdir, file)
print(f"Checking file: " + dir)
with open(dir, "rt") as a_file:
list_of_lines = a_file.readlines()
count = 0
# Check each line for errors perhaps? Will be working on
for x in range(len(list_of_lines)):
# Want to avoid using else statements xd
findElse = re.search("else", list_of_lines[x])
if(findElse):
Errors.append(f"Found else statements in: " + dir + " in line: " + str(x+1))
count = count+1
#return
def DoFrontEnd():
for subdir, dirs, files in os.walk(FRONTEND):
for file in files:
# Ignore dirs we don't want to modify
if not any(ext in subdir for ext in IgnoreDir):
# Ignore files we don't want to modify
if not any(ext in file for ext in IgnoreFile) and not file.endswith(IgnoreExtension):
with open(os.path.join(subdir, file), "rt") as a_file:
list_of_lines = a_file.readlines()
if args[0] == "backend":
DoBackEnd()
if args[0] == "frontend":
DoFrontEnd()
if len(Errors) > 0:
print(f"================================================================")
print(f"ERRORS FOUND.. PRINTING THEM NOW")
for x in Errors:
print(x)
continue
print(f"================================================================")