Skip to content

Commit

Permalink
Fixes pretty_contents undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
amarvin committed Apr 12, 2024
1 parent 38c5176 commit 461e777
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pre_commit_hooks/pretty_format_json.py
Expand Up @@ -105,6 +105,7 @@ def main(argv: Sequence[str] | None = None) -> int:
with open(json_file, encoding='UTF-8') as f:
contents = f.read()

is_error = False
try:
pretty_contents = _get_pretty_format(
contents, args.indent, ensure_ascii=not args.no_ensure_ascii,
Expand All @@ -115,9 +116,10 @@ def main(argv: Sequence[str] | None = None) -> int:
f'Input File {json_file} is not a valid JSON, consider using '
f'check-json',
)
is_error = True
status = 1

if contents != pretty_contents:
if contents != pretty_contents and not is_error:
if args.autofix:
_autofix(json_file, pretty_contents)
else:
Expand Down

0 comments on commit 461e777

Please sign in to comment.