1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

Only validate JSON on Linux

This commit is contained in:
Alexander Wilms 2023-09-15 23:52:04 +00:00
parent 2394612e28
commit 512816b223
2 changed files with 7 additions and 7 deletions

View File

@ -1,13 +1,14 @@
import jstyleson
import re
from pathlib import Path
from pprint import pprint
import yaml
import json5
import re
import jstyleson
import yaml
# 'json', 'json5' or 'yaml'
# json: strict, but doesn't preserve line numbers necessarily, since it strips comments before parsing
# json5: strict and preserves line numbers even for files will with line comments
# json5: strict and preserves line numbers even for files with line comments
# yaml: less strict, allows e.g. leading zeros
VALIDATION_TYPE = 'json5'
@ -20,10 +21,8 @@ for path in sorted(Path('.').glob('**/*.json')):
if VALIDATION_TYPE == 'json':
jstyleson.load(file)
if VALIDATION_TYPE == 'json5':
json5.load(file)
elif VALIDATION_TYPE == 'yaml':
file = file.read().replace("\t", " ")
file = file.replace("//", "#")
yaml.safe_load(file)
@ -38,7 +37,6 @@ for path in sorted(Path('.').glob('**/*.json')):
# https://stackoverflow.com/a/72850269/2278742
error_pos = f"{path_str}:{exc.lineno}:{exc.colno}"
print(error_pos)
# error_msg = "position": position_msg, "exception": exc
if hasattr(exc, 'problem_mark'):
mark = exc.problem_mark
error_pos = f"{path_str}:{mark.line+1}:{mark.column+1}"

View File

@ -146,6 +146,8 @@ jobs:
submodules: recursive
- name: Validate JSON
# the Python yaml module doesn't seem to work on mac-arm
if: ${{ startsWith(matrix.preset, 'linux') }}
run: |
pip3 install json5 jstyleson
python3 .github/validate_json.py