File tree Expand file tree Collapse file tree 3 files changed +9
-12
lines changed
Expand file tree Collapse file tree 3 files changed +9
-12
lines changed Original file line number Diff line number Diff line change 11- repo : https://github.com/pre-commit/pre-commit-hooks
2- sha : 4c3cc8f3edc3c673b3a4abe2054e64f21d26772c
2+ sha : dc50b7f09c9612624c97e7f11fa346937c37f444
33 hooks :
44 - id : trailing-whitespace
55 - id : end-of-file-fixer
Original file line number Diff line number Diff line change 11from __future__ import print_function
22
33import argparse
4+ import io
5+ import json
46import sys
57
6- import simplejson
7-
88
99def 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments