mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-09 04:54:16 +00:00
Style fixups
This commit is contained in:
parent
ea867c2e68
commit
17478a0a50
3 changed files with 14 additions and 12 deletions
|
|
@ -5,8 +5,7 @@ env: # These should match the tox env list
|
||||||
- TOXENV=py34
|
- TOXENV=py34
|
||||||
- TOXENV=pypy
|
- TOXENV=pypy
|
||||||
- TOXENV=pypy3
|
- TOXENV=pypy3
|
||||||
install:
|
install: pip install coveralls tox
|
||||||
- pip install coveralls tox
|
|
||||||
script: tox
|
script: tox
|
||||||
# Special snowflake. Our tests depend on making real commits.
|
# Special snowflake. Our tests depend on making real commits.
|
||||||
before_install:
|
before_install:
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,10 @@ import simplejson
|
||||||
|
|
||||||
def _get_pretty_format(contents, indent, sort_keys=True):
|
def _get_pretty_format(contents, indent, sort_keys=True):
|
||||||
return simplejson.dumps(
|
return simplejson.dumps(
|
||||||
simplejson.loads(contents,
|
simplejson.loads(
|
||||||
object_pairs_hook=None if sort_keys else OrderedDict),
|
contents,
|
||||||
|
object_pairs_hook=None if sort_keys else OrderedDict,
|
||||||
|
),
|
||||||
sort_keys=sort_keys,
|
sort_keys=sort_keys,
|
||||||
indent=indent
|
indent=indent
|
||||||
) + "\n" # dumps don't end with a newline
|
) + "\n" # dumps don't end with a newline
|
||||||
|
|
@ -28,20 +30,20 @@ def pretty_format_json(argv=None):
|
||||||
'--autofix',
|
'--autofix',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='autofix',
|
dest='autofix',
|
||||||
help='Automatically fixes encountered not-pretty-formatted files'
|
help='Automatically fixes encountered not-pretty-formatted files',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--indent',
|
'--indent',
|
||||||
type=int,
|
type=int,
|
||||||
default=2,
|
default=2,
|
||||||
help='Number of indent spaces used to pretty-format files'
|
help='Number of indent spaces used to pretty-format files',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--no-sort-keys',
|
'--no-sort-keys',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='no_sort_keys',
|
dest='no_sort_keys',
|
||||||
default=False,
|
default=False,
|
||||||
help='Keep JSON nodes in the same order'
|
help='Keep JSON nodes in the same order',
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
|
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
|
||||||
|
|
@ -50,12 +52,13 @@ def pretty_format_json(argv=None):
|
||||||
status = 0
|
status = 0
|
||||||
|
|
||||||
for json_file in args.filenames:
|
for json_file in args.filenames:
|
||||||
try:
|
with open(json_file) as f:
|
||||||
f = open(json_file, 'r')
|
|
||||||
contents = f.read()
|
contents = f.read()
|
||||||
f.close()
|
|
||||||
|
|
||||||
pretty_contents = _get_pretty_format(contents, args.indent, (not args.no_sort_keys))
|
try:
|
||||||
|
pretty_contents = _get_pretty_format(
|
||||||
|
contents, args.indent, sort_keys=not args.no_sort_keys,
|
||||||
|
)
|
||||||
|
|
||||||
if contents != pretty_contents:
|
if contents != pretty_contents:
|
||||||
print("File {0} is not pretty-formatted".format(json_file))
|
print("File {0} is not pretty-formatted".format(json_file))
|
||||||
|
|
|
||||||
2
tox.ini
2
tox.ini
|
|
@ -1,7 +1,7 @@
|
||||||
[tox]
|
[tox]
|
||||||
project = pre_commit_hooks
|
project = pre_commit_hooks
|
||||||
# These should match the travis env list
|
# These should match the travis env list
|
||||||
envlist = py26,py27,py33,py34,pypy,pypy3
|
envlist = py27,py33,py34,pypy,pypy3
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
deps = -rrequirements-dev.txt
|
deps = -rrequirements-dev.txt
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue