Skip to content

Commit

Permalink
Add format_check.py
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegratedQuantum committed Jun 16, 2024
1 parent 9673ce9 commit 5cac5b3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This is a basic workflow that is manually triggered

name: Format Check

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
format_check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Check Format
run: python3 "format_check.py"
44 changes: 44 additions & 0 deletions format_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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("./compiler"): continue
if filepath.startswith("./saves"): continue
if filepath.startswith("./serverAssets"): continue
if filepath.startswith("./zig-cache"): 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", newline = '') 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)

0 comments on commit 5cac5b3

Please sign in to comment.