-
Notifications
You must be signed in to change notification settings - Fork 58
/
format_check.py
44 lines (39 loc) · 1.45 KB
/
format_check.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
import os
import sys
directory = os.fsencode(".")
fails = 0
for subdir, dirs, files in os.walk("."):
for file in files:
#print os.path.join(subdir, file)
filepath = subdir + os.sep + file
if filepath.startswith(f".{os.sep}compiler"): continue
if filepath.startswith(f".{os.sep}saves"): continue
if filepath.startswith(f".{os.sep}serverAssets"): continue
if filepath.startswith(f".{os.sep}zig-cache"): continue
if filepath.startswith(f".{os.sep}.zig-cache"): continue
if filepath.endswith(".json") or filepath.endswith(".zig") or filepath.endswith(".py") or filepath.endswith(".zon") or filepath.endswith(".vs") or filepath.endswith(".fs") or filepath.endswith(".glsl"):
with open(filepath, "r", newline = '', encoding="utf-8") as f:
string = f.read()
line = 1
lineStart = True
for i, c in enumerate(string):
if(c == '\r'):
print("Incorrect line ending \\r in file ", filepath, " in line ", line, ". Please configure your editor to use LF instead of CRLF.")
fails += 1
elif(c == '\n'):
line += 1
lineStart = True
elif(c == ' '):
if(lineStart):
print("Incorrect indentation in file ", filepath, " in line ", line, ". Please use tabs instead of spaces.")
fails += 1
lineStart = False # avoid repeating this error multiple times
elif(c == '\t'):
continue
elif(lineStart):
lineStart = False
else:
continue
if(fails != 0):
sys.exit(1)
sys.exit(0)