1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-30 09:03:20 +00:00
CC-Tweaked/tools/check-lines.py
Jonathan Coates b14c7842fc
Add textutils.unserialiseJSON (#407)
This is relatively unoptimised right now, but should be efficient enough
for most practical applications.

 - Add textutils.json_null. This will be serialized into a literal
   `null`. When deserializing, and parse_null is true, this will be
   returned instead of a nil.

 - Add textutils.unserializeJSON (and textutils.unserializeJSON). This
   is a standard compliant JSON parser (hopefully).

 - Passing in nbt_style to textutils.unserializeJSON will handle
   stringified NBT (no quotes around object keys, numeric suffices). We
   don't currently support byte/long/int arrays - something to add in
   a future commit.
2020-04-19 15:08:46 +01:00

29 lines
1.0 KiB
Python

import pathlib, sys
problems = False
# Skip images and files without extensions
exclude = [ "*.png", "**/data/json-parsing/*.json" ]
for path in pathlib.Path("src").glob("**/*"):
if path.is_dir() or path.suffix == "" or any(path.match(x) for x 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)