Skip to content

Commit 61b72ab

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 496e23d commit 61b72ab

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

pre_commit_hooks/pretty_format_json.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
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
1110

11+
1212
def _insert_linebreaks(json_str) -> str:
1313
# (?P<spaces>\s*) seems to capture the \n. Hence, there is no need for it in the substitution string
14-
return re.sub(r'\n(?P<spaces>\s*)(?P<json_key>.*): {}(?P<delim>,??)', '\n\g<spaces>\g<json_key>: {\n\g<spaces>}\g<delim>', json_str)
14+
return re.sub(r'\n(?P<spaces>\s*)(?P<json_key>.*): {}(?P<delim>,??)', '\n\\g<spaces>\\g<json_key>: {\n\\g<spaces>}\\g<delim>', json_str)
15+
1516

1617
def _get_pretty_format(
1718
contents: str,
@@ -126,7 +127,7 @@ def main(argv: Sequence[str] | None = None) -> int:
126127
pretty_contents = _get_pretty_format(
127128
contents, args.indent, ensure_ascii=not args.no_ensure_ascii,
128129
sort_keys=not args.no_sort_keys, top_keys=args.top_keys,
129-
empty_object_with_newline=args.empty_object_with_newline
130+
empty_object_with_newline=args.empty_object_with_newline,
130131
)
131132
except ValueError:
132133
print(
@@ -145,7 +146,6 @@ def main(argv: Sequence[str] | None = None) -> int:
145146
diff_output = get_diff(contents, pretty_contents, json_file)
146147
sys.stdout.buffer.write(diff_output.encode())
147148

148-
149149
return status
150150

151151

tests/pretty_format_json_test.py

Lines changed: 7 additions & 7 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,13 +142,13 @@ 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

149-
multiline = get_resource_path("empty_object_json_multiline.json")
149+
multiline = get_resource_path('empty_object_json_multiline.json')
150150
to_be_formatted_sameline = tmpdir.join(
151-
"not_pretty_formatted_empty_object_json_sameline.json"
151+
'not_pretty_formatted_empty_object_json_sameline.json',
152152
)
153153
shutil.copyfile(str(sameline), str(to_be_formatted_sameline))
154154

@@ -158,12 +158,12 @@ def test_empty_object_with_newline(tmpdir):
158158

159159
# now launch the autofix with empty object with newline support on that file
160160
ret = main(
161-
["--autofix", "--empty-object-with-newline", str(to_be_formatted_sameline)]
161+
['--autofix', '--empty-object-with-newline', str(to_be_formatted_sameline)],
162162
)
163163
# it should have formatted it and don't raise an error code
164164
assert ret == 0
165165

166166
# file was formatted (shouldn't trigger linter with --empty-object-with-newline switch)
167-
ret = main(["--empty-object-with-newline", str(to_be_formatted_sameline)])
167+
ret = main(['--empty-object-with-newline', str(to_be_formatted_sameline)])
168168
assert ret == 0
169169
assert filecmp.cmp(to_be_formatted_sameline, multiline)

0 commit comments

Comments
 (0)