mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-08 04:34:16 +00:00
Merge pull request #122 from sanmai-NL/JSON_arbitrary_indentation_separator
Fix exception raising logic to match validation issues
This commit is contained in:
commit
6dfcb89af3
1 changed files with 8 additions and 7 deletions
|
|
@ -28,19 +28,20 @@ def parse_indent(s):
|
||||||
# type: (str) -> str
|
# type: (str) -> str
|
||||||
try:
|
try:
|
||||||
int_indentation_spec = int(s)
|
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:
|
if int_indentation_spec >= 0:
|
||||||
return int_indentation_spec * ' '
|
return int_indentation_spec * ' '
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'Negative integer supplied to construct JSON indentation delimiter. ',
|
'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):
|
def pretty_format_json(argv=None):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue