mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-08 20:44:18 +00:00
added --empty-object-with-newline formatting and checking
This commit is contained in:
commit
39f95ccaea
2 changed files with 5 additions and 7 deletions
|
|
@ -2,9 +2,8 @@ from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import sys
|
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
from difflib import unified_diff
|
from difflib import unified_diff
|
||||||
from typing import Mapping
|
from typing import Mapping
|
||||||
from typing import Sequence
|
from typing import Sequence
|
||||||
|
|
@ -129,7 +128,7 @@ def main(argv: Sequence[str] | None = None) -> int:
|
||||||
pretty_contents = _get_pretty_format(
|
pretty_contents = _get_pretty_format(
|
||||||
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,
|
||||||
empty_object_with_newline=args.empty_object_with_newline
|
empty_object_with_newline=args.empty_object_with_newline,
|
||||||
)
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print(
|
print(
|
||||||
|
|
@ -148,7 +147,6 @@ def main(argv: Sequence[str] | None = None) -> int:
|
||||||
diff_output = get_diff(contents, pretty_contents, json_file)
|
diff_output = get_diff(contents, pretty_contents, json_file)
|
||||||
sys.stdout.buffer.write(diff_output.encode())
|
sys.stdout.buffer.write(diff_output.encode())
|
||||||
|
|
||||||
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import filecmp
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import filecmp
|
|
||||||
|
|
||||||
from pre_commit_hooks.pretty_format_json import main
|
from pre_commit_hooks.pretty_format_json import main
|
||||||
from pre_commit_hooks.pretty_format_json import parse_num_to_int
|
from pre_commit_hooks.pretty_format_json import parse_num_to_int
|
||||||
|
|
@ -142,8 +142,8 @@ def test_diffing_output(capsys):
|
||||||
|
|
||||||
def test_empty_object_with_newline(tmpdir):
|
def test_empty_object_with_newline(tmpdir):
|
||||||
# same line objects shoud trigger with --empty-object-with-newline switch
|
# same line objects shoud trigger with --empty-object-with-newline switch
|
||||||
sameline = get_resource_path("empty_object_json_sameline.json")
|
sameline = get_resource_path('empty_object_json_sameline.json')
|
||||||
ret = main(["--empty-object-with-newline", str(sameline)])
|
ret = main(['--empty-object-with-newline', str(sameline)])
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
|
|
||||||
# a template to be compared against.
|
# a template to be compared against.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue