1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-07 07:50:27 +00:00

Lint whitespace during CI

This commit is contained in:
SquidDev 2020-01-23 15:11:50 +00:00
parent 3f98b2785e
commit 0de5969ec1
68 changed files with 759 additions and 728 deletions

View File

@ -37,3 +37,6 @@ jobs:
test -f bin/illuaminate || wget -q -Obin/illuaminate https://squiddev.cc/illuaminate/bin/illuaminate
chmod +x bin/illuaminate
bin/illuaminate lint
- name: Check whitespace
run: python3 tools/check-lines.py

28
tools/check-lines.py Normal file
View File

@ -0,0 +1,28 @@
import pathlib, sys
problems = False
# Skip images and files without extensions
exclude = [ ".png", "" ]
for path in pathlib.Path(".").glob("src/**/*"):
if path.is_dir() or path.suffix in exclude:
continue
with path.open(encoding="utf-8") as file:
has_dos, has_trailing, needs_final = False, False, False
for i, line in enumerate(file):
if len(line) >= 2 and line[-2] == "\r" and line[-1] == "\n" and not has_line:
print("%s has contains '\\r\\n' on line %d" % (path, i + 1))
problems = has_dos = True
if len(line) >= 2 and line[-2] in " \t" and line[-1] == "\n" and not has_trailing:
print("%s has trailing whitespace on line %d" % (path, i + 1))
problems = has_trailing = True
if line is not None and len(line) >= 1 and line[-1] != "\n":
print("%s should end with '\\n'" % path)
problems = True
if problems:
sys.exit(1)