Skip to content

Commit 31e740e

Browse files
committed
Use unified_diff
1 parent 27cd688 commit 31e740e

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

pre_commit_hooks/pretty_format_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def parse_topkeys(s): # type: (str) -> List[str]
5959
def get_diff(source, target): # type: (str, str) -> str
6060
source_lines = source.splitlines(True)
6161
target_lines = target.splitlines(True)
62-
diff = ''.join(difflib.ndiff(source_lines, target_lines))
62+
diff = ''.join(difflib.unified_diff(source_lines, target_lines))
6363
return diff
6464

6565

tests/pretty_format_json_test.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,24 @@ def test_diffing_output(capsys):
111111
resource_path = get_resource_path('not_pretty_formatted_json.json')
112112
expected_retval = 1
113113
expected_out = '''\
114-
{
115-
- "foo":
116-
- "bar",
117-
- "alist": [2, 34, 234],
118-
+ "alist": [
119-
+ 2,
120-
+ 34,
121-
+ 234
122-
+ ],
123-
- "blah": null
124-
+ "blah": null,
125-
? +
126-
+ "foo": "bar"
127-
}
128-
129-
'''
114+
---
115+
+++
116+
@@ -1,6 +1,9 @@
117+
{
118+
- "foo":
119+
- "bar",
120+
- "alist": [2, 34, 234],
121+
- "blah": null
122+
+ "alist": [
123+
+ 2,
124+
+ 34,
125+
+ 234
126+
+ ],
127+
+ "blah": null,
128+
+ "foo": "bar"
129+
}
130+
131+
''' # noqa: W291
130132
expected_err = 'File {} is not pretty-formatted\n'.format(resource_path)
131133

132134
actual_retval = main([resource_path])

0 commit comments

Comments
 (0)