Skip to content

Commit

Permalink
Merge pull request #571 from jack1142/patch-1
Browse files Browse the repository at this point in the history
Update `pretty-format-json` to write to stdout with utf-8 encoding
  • Loading branch information
asottile committed Mar 16, 2021
2 parents 0c033f7 + 1de4fe6 commit d34222b
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions pre_commit_hooks/pretty_format_json.py
@@ -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:
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

0 comments on commit d34222b

Please sign in to comment.