From abaf0d12de63dd092b931002aae00ab003f717b7 Mon Sep 17 00:00:00 2001 From: Sander Maijers Date: Mon, 13 Jun 2016 11:34:55 +0200 Subject: [PATCH] Fix exc. raising logic to match validation issues --- pre_commit_hooks/pretty_format_json.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pre_commit_hooks/pretty_format_json.py b/pre_commit_hooks/pretty_format_json.py index 605cbec..36a90eb 100644 --- a/pre_commit_hooks/pretty_format_json.py +++ b/pre_commit_hooks/pretty_format_json.py @@ -28,19 +28,20 @@ def parse_indent(s): # type: (str) -> str try: int_indentation_spec = int(s) + except ValueError: + if not s.strip(): + return s + else: + raise ValueError( + 'Non-whitespace JSON indentation delimiter supplied. ', + ) + else: if int_indentation_spec >= 0: return int_indentation_spec * ' ' else: raise ValueError( 'Negative integer supplied to construct JSON indentation delimiter. ', ) - except ValueError: - if s.strip() == '': - return s - else: - raise ValueError( - 'Non-whitespace JSON indentation delimiter supplied. ', - ) def pretty_format_json(argv=None):