From 84b1fb6827ebcd539f60ffdd6f95229650aa056c Mon Sep 17 00:00:00 2001 From: dmlb2000 Date: Thu, 3 Nov 2016 15:54:48 -0700 Subject: [PATCH] let pre-commit fix some stuff --- pre_commit_hooks/pretty_format_json.py | 3 ++- tests/pretty_format_json_test.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pre_commit_hooks/pretty_format_json.py b/pre_commit_hooks/pretty_format_json.py index a1dccc0..91dae8d 100644 --- a/pre_commit_hooks/pretty_format_json.py +++ b/pre_commit_hooks/pretty_format_json.py @@ -7,7 +7,6 @@ from collections import OrderedDict import simplejson - def _get_pretty_format(contents, indent, sort_keys=True, top_keys=[]): def pairs_first(pairs): before = [pair for pair in pairs if pair[0] in top_keys] @@ -50,10 +49,12 @@ def parse_indent(s): 'Negative integer supplied to construct JSON indentation delimiter. ', ) + def parse_topkeys(s): # type: (str) -> array return s.split(',') + def pretty_format_json(argv=None): parser = argparse.ArgumentParser() parser.add_argument( diff --git a/tests/pretty_format_json_test.py b/tests/pretty_format_json_test.py index df2152a..72c2b86 100644 --- a/tests/pretty_format_json_test.py +++ b/tests/pretty_format_json_test.py @@ -64,14 +64,17 @@ def test_autofix_pretty_format_json(tmpdir): ret = pretty_format_json([srcfile.strpath]) assert ret == 0 + def test_orderfile_get_pretty_format(): ret = pretty_format_json(['--top-keys=alist', get_resource_path('pretty_formatted_json.json')]) assert ret == 0 + def test_not_orderfile_get_pretty_format(): ret = pretty_format_json(['--top-keys=blah', get_resource_path('pretty_formatted_json.json')]) assert ret == 1 + def test_badfile_pretty_format_json(): ret = pretty_format_json([get_resource_path('ok_yaml.yaml')]) assert ret == 1