Skip to content

Commit

Permalink
Add lint.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Rufflewind committed Jul 5, 2024
1 parent d2fb504 commit 96fccc0
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
import glob, pathlib, re, sys

def error(counter, path, row, message):
sys.stderr.write(f'{path}:{row}: {message}\n')
counter[0] += 1

counter = [0]
for path in glob.glob('**', recursive=True):
if not re.fullmatch(r'System/.*\.hsc?', path):
continue
contents = pathlib.Path(path).read_text()

for i, line in enumerate(contents.splitlines()):
if len(line) > 80:
error(counter, path, i+1, f'line over 80 chars')

contents = re.sub(r'--.*', '', contents)
for m in re.finditer(r'(?s)\b(os|so)\b\s*(\S*)', contents):
func, next_token = m.groups()
if not re.fullmatch(r'|'.join([
r'".*',
r'=',
r'::',
r'EXE_EXTENSION',
r'.*exeExtension',
]), next_token):
row = 1 + contents[:m.start()].count('\n')
error(counter, path, row, f'{func} only allowed on literals')
if counter[0]:
sys.exit(f'{counter[0]} error(s)')

0 comments on commit 96fccc0

Please sign in to comment.