Continues processing JSONs even if hook fails (fixes #1038)
This commit is contained in:
parent
8c24e2c2e6
commit
25cdd5457b
|
@ -115,16 +115,20 @@ def main(argv: Sequence[str] | None = None) -> int:
|
||||||
f'Input File {json_file} is not a valid JSON, consider using '
|
f'Input File {json_file} is not a valid JSON, consider using '
|
||||||
f'check-json',
|
f'check-json',
|
||||||
)
|
)
|
||||||
return 1
|
|
||||||
|
|
||||||
if contents != pretty_contents:
|
|
||||||
if args.autofix:
|
|
||||||
_autofix(json_file, pretty_contents)
|
|
||||||
else:
|
|
||||||
diff_output = get_diff(contents, pretty_contents, json_file)
|
|
||||||
sys.stdout.buffer.write(diff_output.encode())
|
|
||||||
|
|
||||||
status = 1
|
status = 1
|
||||||
|
else:
|
||||||
|
if contents != pretty_contents:
|
||||||
|
if args.autofix:
|
||||||
|
_autofix(json_file, pretty_contents)
|
||||||
|
else:
|
||||||
|
diff_output = get_diff(
|
||||||
|
contents,
|
||||||
|
pretty_contents,
|
||||||
|
json_file,
|
||||||
|
)
|
||||||
|
sys.stdout.buffer.write(diff_output.encode())
|
||||||
|
|
||||||
|
status = 1
|
||||||
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,24 @@ def test_autofix_main(tmpdir):
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_invalid_main(tmpdir):
|
||||||
|
srcfile1 = tmpdir.join('not_valid_json.json')
|
||||||
|
srcfile1.write(
|
||||||
|
'{\n'
|
||||||
|
' // not json\n'
|
||||||
|
' "a": "b"\n'
|
||||||
|
'}',
|
||||||
|
)
|
||||||
|
srcfile2 = tmpdir.join('to_be_json_formatted.json')
|
||||||
|
srcfile2.write('{ "a": "b" }')
|
||||||
|
|
||||||
|
# it should have skipped the first file and formatted the second one
|
||||||
|
assert main(['--autofix', str(srcfile1), str(srcfile2)]) == 1
|
||||||
|
|
||||||
|
# confirm second file was formatted (shouldn't trigger linter again)
|
||||||
|
assert main([str(srcfile2)]) == 0
|
||||||
|
|
||||||
|
|
||||||
def test_orderfile_get_pretty_format():
|
def test_orderfile_get_pretty_format():
|
||||||
ret = main((
|
ret = main((
|
||||||
'--top-keys=alist', get_resource_path('pretty_formatted_json.json'),
|
'--top-keys=alist', get_resource_path('pretty_formatted_json.json'),
|
||||||
|
|
Loading…
Reference in New Issue