mirror of
https://github.com/vcmi/vcmi.git
synced 2025-05-29 22:57:49 +02:00
Only validate JSON on Linux
This commit is contained in:
parent
2394612e28
commit
512816b223
12
.github/validate_json.py
vendored
12
.github/validate_json.py
vendored
@ -1,13 +1,14 @@
|
|||||||
import jstyleson
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
import yaml
|
|
||||||
import json5
|
import json5
|
||||||
import re
|
import jstyleson
|
||||||
|
import yaml
|
||||||
|
|
||||||
# 'json', 'json5' or 'yaml'
|
# 'json', 'json5' or 'yaml'
|
||||||
# json: strict, but doesn't preserve line numbers necessarily, since it strips comments before parsing
|
# 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
|
# yaml: less strict, allows e.g. leading zeros
|
||||||
VALIDATION_TYPE = 'json5'
|
VALIDATION_TYPE = 'json5'
|
||||||
|
|
||||||
@ -20,10 +21,8 @@ for path in sorted(Path('.').glob('**/*.json')):
|
|||||||
if VALIDATION_TYPE == 'json':
|
if VALIDATION_TYPE == 'json':
|
||||||
jstyleson.load(file)
|
jstyleson.load(file)
|
||||||
if VALIDATION_TYPE == 'json5':
|
if VALIDATION_TYPE == 'json5':
|
||||||
|
|
||||||
json5.load(file)
|
json5.load(file)
|
||||||
elif VALIDATION_TYPE == 'yaml':
|
elif VALIDATION_TYPE == 'yaml':
|
||||||
|
|
||||||
file = file.read().replace("\t", " ")
|
file = file.read().replace("\t", " ")
|
||||||
file = file.replace("//", "#")
|
file = file.replace("//", "#")
|
||||||
yaml.safe_load(file)
|
yaml.safe_load(file)
|
||||||
@ -38,7 +37,6 @@ for path in sorted(Path('.').glob('**/*.json')):
|
|||||||
# https://stackoverflow.com/a/72850269/2278742
|
# https://stackoverflow.com/a/72850269/2278742
|
||||||
error_pos = f"{path_str}:{exc.lineno}:{exc.colno}"
|
error_pos = f"{path_str}:{exc.lineno}:{exc.colno}"
|
||||||
print(error_pos)
|
print(error_pos)
|
||||||
# error_msg = "position": position_msg, "exception": exc
|
|
||||||
if hasattr(exc, 'problem_mark'):
|
if hasattr(exc, 'problem_mark'):
|
||||||
mark = exc.problem_mark
|
mark = exc.problem_mark
|
||||||
error_pos = f"{path_str}:{mark.line+1}:{mark.column+1}"
|
error_pos = f"{path_str}:{mark.line+1}:{mark.column+1}"
|
||||||
|
2
.github/workflows/github.yml
vendored
2
.github/workflows/github.yml
vendored
@ -146,6 +146,8 @@ jobs:
|
|||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
- name: Validate JSON
|
- name: Validate JSON
|
||||||
|
# the Python yaml module doesn't seem to work on mac-arm
|
||||||
|
if: ${{ startsWith(matrix.preset, 'linux') }}
|
||||||
run: |
|
run: |
|
||||||
pip3 install json5 jstyleson
|
pip3 install json5 jstyleson
|
||||||
python3 .github/validate_json.py
|
python3 .github/validate_json.py
|
||||||
|
Loading…
x
Reference in New Issue
Block a user