mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-04 19:26:52 +00:00
Merge branch 'main' into empty-object-with-newline
This commit is contained in:
commit
a23cc57a37
44 changed files with 321 additions and 97 deletions
|
|
@ -4,9 +4,9 @@ import argparse
|
|||
import json
|
||||
import re
|
||||
import sys
|
||||
from collections.abc import Mapping
|
||||
from collections.abc import Sequence
|
||||
from difflib import unified_diff
|
||||
from typing import Mapping
|
||||
from typing import Sequence
|
||||
|
||||
def _insert_linebreaks(json_str: str) -> str:
|
||||
return re.sub(
|
||||
|
|
@ -135,17 +135,22 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|||
f'Input File {json_file} is not a valid JSON, consider using '
|
||||
f'check-json',
|
||||
)
|
||||
return 1
|
||||
|
||||
if contents != pretty_contents:
|
||||
status = 1
|
||||
if args.autofix:
|
||||
_autofix(json_file, pretty_contents)
|
||||
if args.empty_object_with_newline:
|
||||
status = 0
|
||||
else:
|
||||
diff_output = get_diff(contents, pretty_contents, json_file)
|
||||
sys.stdout.buffer.write(diff_output.encode())
|
||||
else:
|
||||
if contents != pretty_contents:
|
||||
if args.autofix:
|
||||
_autofix(json_file, pretty_contents)
|
||||
if args.empty_object_with_newline:
|
||||
status = 0
|
||||
else:
|
||||
diff_output = get_diff(
|
||||
contents,
|
||||
pretty_contents,
|
||||
json_file
|
||||
)
|
||||
sys.stdout.buffer.write(diff_output.encode())
|
||||
|
||||
status = 1
|
||||
|
||||
return status
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue