mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-13 01:20:34 +02:00
Format CI/linux-qt6/validate_json.py with 'black -l999 .'
This commit is contained in:
@ -12,19 +12,19 @@ import 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 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"
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
for path in sorted(Path('.').glob('**/*.json')):
|
for path in sorted(Path(".").glob("**/*.json")):
|
||||||
# because path is an object and not a string
|
# because path is an object and not a string
|
||||||
path_str = str(path)
|
path_str = str(path)
|
||||||
try:
|
try:
|
||||||
with open(path_str, 'r') as file:
|
with open(path_str, "r") as file:
|
||||||
if VALIDATION_TYPE == 'json':
|
if VALIDATION_TYPE == "json":
|
||||||
jstyleson.load(file)
|
jstyleson.load(file)
|
||||||
elif VALIDATION_TYPE == 'json5':
|
elif 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)
|
||||||
@ -36,16 +36,16 @@ for path in sorted(Path('.').glob('**/*.json')):
|
|||||||
error_pos = path_str
|
error_pos = path_str
|
||||||
|
|
||||||
# create error position strings for each type of parser
|
# create error position strings for each type of parser
|
||||||
if hasattr(exc, 'pos'):
|
if hasattr(exc, "pos"):
|
||||||
# 'json'
|
# '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)
|
||||||
elif VALIDATION_TYPE == 'json5':
|
elif VALIDATION_TYPE == "json5":
|
||||||
# 'json5'
|
# 'json5'
|
||||||
pos = re.findall(r'\d+', str(exc))
|
pos = re.findall(r"\d+", str(exc))
|
||||||
error_pos = f"{path_str}:{pos[0]}:{pos[-1]}"
|
error_pos = f"{path_str}:{pos[0]}:{pos[-1]}"
|
||||||
elif hasattr(exc, 'problem_mark'):
|
elif hasattr(exc, "problem_mark"):
|
||||||
# 'yaml'
|
# 'yaml'
|
||||||
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}"
|
||||||
|
Reference in New Issue
Block a user