Skip to content

Commit 39f95cc

Browse files
committed
added --empty-object-with-newline formatting and checking
2 parents 6394898 + 61b72ab commit 39f95cc

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

pre_commit_hooks/pretty_format_json.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
import argparse
44
import json
5-
import sys
65
import re
7-
6+
import sys
87
from difflib import unified_diff
98
from typing import Mapping
109
from typing import Sequence
@@ -129,7 +128,7 @@ def main(argv: Sequence[str] | None = None) -> int:
129128
pretty_contents = _get_pretty_format(
130129
contents, args.indent, ensure_ascii=not args.no_ensure_ascii,
131130
sort_keys=not args.no_sort_keys, top_keys=args.top_keys,
132-
empty_object_with_newline=args.empty_object_with_newline
131+
empty_object_with_newline=args.empty_object_with_newline,
133132
)
134133
except ValueError:
135134
print(
@@ -148,7 +147,6 @@ def main(argv: Sequence[str] | None = None) -> int:
148147
diff_output = get_diff(contents, pretty_contents, json_file)
149148
sys.stdout.buffer.write(diff_output.encode())
150149

151-
152150
return status
153151

154152

tests/pretty_format_json_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from __future__ import annotations
22

3+
import filecmp
34
import os
45
import shutil
56

67
import pytest
7-
import filecmp
88

99
from pre_commit_hooks.pretty_format_json import main
1010
from pre_commit_hooks.pretty_format_json import parse_num_to_int
@@ -142,8 +142,8 @@ def test_diffing_output(capsys):
142142

143143
def test_empty_object_with_newline(tmpdir):
144144
# same line objects shoud trigger with --empty-object-with-newline switch
145-
sameline = get_resource_path("empty_object_json_sameline.json")
146-
ret = main(["--empty-object-with-newline", str(sameline)])
145+
sameline = get_resource_path('empty_object_json_sameline.json')
146+
ret = main(['--empty-object-with-newline', str(sameline)])
147147
assert ret == 1
148148

149149
# a template to be compared against.

0 commit comments

Comments
 (0)