Skip to content

Commit dc50b7f

Browse files
committed
Attempt to fix the json hook under test
1 parent a859266 commit dc50b7f

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

pre_commit_hooks/check_json.py

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

33
import argparse
4+
import io
5+
import json
46
import sys
57

6-
import simplejson
7-
88

99
def check_json(argv=None):
1010
parser = argparse.ArgumentParser()
@@ -14,8 +14,8 @@ def check_json(argv=None):
1414
retval = 0
1515
for filename in args.filenames:
1616
try:
17-
simplejson.load(open(filename))
18-
except (simplejson.JSONDecodeError, UnicodeDecodeError) as exc:
17+
json.load(io.open(filename, encoding='UTF-8'))
18+
except (ValueError, UnicodeDecodeError) as exc:
1919
print('{}: Failed to json decode ({})'.format(filename, exc))
2020
retval = 1
2121
return retval

pre_commit_hooks/pretty_format_json.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ def pairs_first(pairs):
2727
)) + "\n" # dumps does not end with a newline
2828

2929

30-
def _autofix(filename, new_contents, encoding=None):
30+
def _autofix(filename, new_contents):
3131
print("Fixing file {}".format(filename))
32-
with io.open(filename, 'w', encoding=encoding) as f:
32+
with io.open(filename, 'w', encoding='UTF-8') as f:
3333
f.write(new_contents)
3434

3535

@@ -100,7 +100,7 @@ def pretty_format_json(argv=None):
100100
status = 0
101101

102102
for json_file in args.filenames:
103-
with io.open(json_file, encoding='utf-8') as f:
103+
with io.open(json_file, encoding='UTF-8') as f:
104104
contents = f.read()
105105

106106
try:
@@ -113,10 +113,7 @@ def pretty_format_json(argv=None):
113113
print("File {} is not pretty-formatted".format(json_file))
114114

115115
if args.autofix:
116-
_autofix(
117-
json_file, pretty_contents,
118-
encoding='utf-8' if args.no_ensure_ascii else None,
119-
)
116+
_autofix(json_file, pretty_contents)
120117

121118
status = 1
122119

0 commit comments

Comments
 (0)