Skip to content

Commit

Permalink
fix: keep_arrays_single_line issue where it splits on , in the middle
Browse files Browse the repository at this point in the history
of a string
  • Loading branch information
TerminalFi committed May 25, 2021
1 parent 51859d6 commit a960fb8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions PrettyJson.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ def json_dumps(obj, minified: bool = False) -> str:
matches.sort(key=len, reverse=True)
join_separator = line_separator.ljust(2)
for m in matches:
content = m[1:-1]
items = [a.strip() for a in content.split(line_separator.strip())]

content = m[1:-1].strip()
items = [a.strip() for a in content.split(os.linesep)]
items = [item[:-1] if item[-1] == ',' else item for item in items]
replacement = f'[{join_separator.join(items)}]'
if len(replacement) <= s.get('max_arrays_line_length', 120):
output_json = output_json.replace(m, replacement, 1)

elif s.get('bracket_newline', True):
output_json = PrettyJsonBaseCommand.bracket_newline.sub(r'\1\n\2\3', output_json)

Expand Down

0 comments on commit a960fb8

Please sign in to comment.