Add a simple python script to check for common formatting errors (tabs and line endings) and fix existing problems.

a step towards #315
This commit is contained in:
IntegratedQuantum 2024-04-16 13:50:40 +02:00
parent 5b76d2c33c
commit aba651a998
10 changed files with 53 additions and 11 deletions

View File

@ -50,7 +50,7 @@ sudo apt install libgl-dev libasound2-dev libx11-dev libxcursor-dev libxrandr-de
# Contributing
### Code
Try to follow the style of the existing code. `// TODO: Add a style guide` <br>
Try to follow the style of the existing code. The `check_format.py` file can be used to find violations of indentation and line endings. `// TODO: Add a full style guide` <br>
If you have any more questions, you can ask them over on [Discord](https://discord.gg/XtqCRRG).
### Textures
If you want to add new textures, make sure they fit the style of the game.

View File

@ -1,6 +1,5 @@
#version 430
out vec4 fragColor;
in vec2 texCoords;
uniform sampler2D color;

43
format_check.py Normal file
View File

@ -0,0 +1,43 @@
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("./compiler"): continue
if filepath.startswith("./saves"): continue
if filepath.startswith("./serverAssets"): continue
if filepath.startswith("./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") 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)