mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-10 05:14:18 +00:00
Update pretty-format-json to write to stdout with utf-8 encoding
This commit is contained in:
parent
0c033f760e
commit
1de4fe6b42
1 changed files with 10 additions and 11 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
from difflib import unified_diff
|
from difflib import unified_diff
|
||||||
from typing import List
|
from typing import List
|
||||||
from typing import Mapping
|
from typing import Mapping
|
||||||
|
|
@ -111,17 +112,6 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
||||||
contents, args.indent, ensure_ascii=not args.no_ensure_ascii,
|
contents, args.indent, ensure_ascii=not args.no_ensure_ascii,
|
||||||
sort_keys=not args.no_sort_keys, top_keys=args.top_keys,
|
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:
|
except ValueError:
|
||||||
print(
|
print(
|
||||||
f'Input File {json_file} is not a valid JSON, consider using '
|
f'Input File {json_file} is not a valid JSON, consider using '
|
||||||
|
|
@ -129,6 +119,15 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
||||||
)
|
)
|
||||||
return 1
|
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
|
return status
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue