Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pretty-format-json to write to stdout with utf-8 encoding #571

Merged
merged 1 commit into from
Mar 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions pre_commit_hooks/pretty_format_json.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import json
import sys
from difflib import unified_diff
from typing import List
from typing import Mapping
Expand Down Expand Up @@ -111,24 +112,22 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
contents, args.indent, ensure_ascii=not args.no_ensure_ascii,
sort_keys=not args.no_sort_keys, top_keys=args.top_keys,
)

if contents != pretty_contents:
if args.autofix:
_autofix(json_file, pretty_contents)
else:
print(
get_diff(contents, pretty_contents, json_file),
end='',
)

status = 1
except ValueError:
Jackenmen marked this conversation as resolved.
Show resolved Hide resolved
print(
f'Input File {json_file} is not a valid JSON, consider using '
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

return status


Expand Down